I have a canvas with an example Pixi game running inside an Ember application (I use https://github.com/Ferdev/ember-cli-pixijs for this):
import PixiCanvas from 'ember-cli-pixijs/components/pixi-canvas';
import PairsGame from './pairsgame';
export default PixiCanvas.extend({
draw() {
const renderer = this.get('pixiRenderer');
var game = new PairsGame()
.init(renderer)
.preload()
.animate();
},
actions: {
log(arg) {
console.log(arg);
}
}
});
The example game I copied from: http://ipotaje.es/en/complete-html5-concentration-game-made-with-pixi-js-3/
As you can see, my Pixi component only contains the drawing/rendering logic, not the game logic. That is stored in an external class, and I want to call the log
action from that. The file with the game looks something like this:
import PIXI from 'pixi';
var PairsGame = function () {};
PairsGame.prototype.init = function (renderer)
{
this.renderer = renderer;
// create an empty container
this.gameContainer = new PIXI.Container();
const graphics = new PIXI.Graphics();
this.gameContainer.addChild(graphics);
// allow chain calling
return this;
};
PairsGame.prototype.preload = function ()
{ // importing a texture atlas created with texturepacker
var tileAtlas = ["assets/images/images.json"];
// create a new loader
PIXI.loader.add(tileAtlas)
// use callback
.once('complete', this.onLoaded.bind(this))
//begin load
.load();
//allow chain calling
return this;
};
PairsGame.prototype.animate = function ()
{
this.renderer.render(this.gameContainer);
requestAnimationFrame(this.animate.bind(this));
//allow chain calling
return this;
};
...
ET CETERA
I WOULD LIKE TO CALL THE log ACTION FROM THESE METHODS
...
Now I would like to send a 'success' or 'failure' message on each turn to my Ember component so that I can take a certain action (e.g., simply log 'success'/'failure' to console). What are ways to accomplish that?
I tried looking at the solution here and put
Ember.Instrumentation.instrument("pixi.gameEvent", 'success');
in the Pixi code, but the subscriber seems to never receive anything.
You can pass PixiCanvas component context to
PairsGame
init method and you can just call usingsendAction
.Inside init method you can store reference to PixiCanvas component,
use sendAction to call
log
method,