1 decade ago by alexandre
I want a creator class instance (a game, a factory, or another entity) to specify the image path of the entity that it creates.
In the Impact examples that I've seen, entities are either loaded from a wm level, or are hard coded with a texture path.
This seemed like a no brainer but my approach doesn't seem to work. Spawned entities are unable to access their texture file's attributes at init time.
I spawned an EntityButton from MyGame's init() method like this:
with EntityButton implementation starting like this:
In the browser, the console shows this:
My question: why, despite img reporting it has been loaded, does a subsequent img.loaded access indicate false and said image's dimensions 0?
In the Impact examples that I've seen, entities are either loaded from a wm level, or are hard coded with a texture path.
This seemed like a no brainer but my approach doesn't seem to work. Spawned entities are unable to access their texture file's attributes at init time.
I spawned an EntityButton from MyGame's init() method like this:
init: function ()
{
this.playBtn = this.spawnEntity (EntityButton, ig.system.width/2, ig.system.height/2 + 96, {path:'media/button-play.png', owner:this, callback:'play'});
},
with EntityButton implementation starting like this:
ig.module(
'plugins.button'
)
.requires(
'impact.game',
'impact.entity',
)
.defines(function()
{
EntityButton = ig.Entity.extend (
{
init: function (x, y, settings)
{
var img = new ig.Image (settings.path);
ig.log('1.');
ig.log(img);
ig.log('2.');
ig.log('loaded: '+img.loaded);
ig.log('dimensions: w:'+img.width+ ' w:'+img.height);
...
In the browser, the console shows this:
1. Class: data: HTMLImageElement height: 60 loadCallback: null loaded: true path: "media/button-play.png" width: 116 __proto__: window.ig.Class 2. loaded: false dimensions: w:0 h:0
My question: why, despite img reporting it has been loaded, does a subsequent img.loaded access indicate false and said image's dimensions 0?
