batman Posted February 21, 2018 Share Posted February 21, 2018 Hi, everyone. Could you advise how correctly pass id of image form atlas when you create class? Thank you in advance, My class code: var id= PIXI.loader.resources ["assets/images/sprites.json"].textures; function Tower() { //var towerTexture = TextureCache["Tower_1.png"]//PIXI.Texture.fromImage() // this one works fine PIXI.Sprite.call(this, id["Tower_1.png"]); // when i use like this i got error that Cannot read property 'Tower_1.png' of undefined this.x = 20; this.y = 20; } Tower.prototype = Object.create(PIXI.Sprite.prototype); And of course loader from main: loader .add("assets/images/tower/sprites.json") .load(setup); Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 21, 2018 Share Posted February 21, 2018 your "id" is undefined. That means you defined "id" when loader did not complete its job yet. batman 1 Quote Link to comment Share on other sites More sharing options...
batman Posted February 21, 2018 Author Share Posted February 21, 2018 Thanks for promt reply, it helped. Declared it as global and put id= PIXI.loader.resources ["assets/images/sprites.json"].textures; inside setup function ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.