___________ Posted July 23, 2016 Share Posted July 23, 2016 Hello! I know this is probably a dumb question but I am quite new to PIXI. I was wondering if you could do something like this with PIXI: function Object(name, x, y, scale_x, scale_y, image_path) { this = PIXI.loader.add(this.name, image_path).load(function(loader, resources) { /* The initialization code. */ }); } I know that wouldn't work but is there anything like that? Quote Link to comment Share on other sites More sharing options...
d13 Posted July 23, 2016 Share Posted July 23, 2016 Hi, what are you trying to accomplish? Quote Link to comment Share on other sites More sharing options...
___________ Posted July 23, 2016 Author Share Posted July 23, 2016 I was trying to make it so that you could create an object like this: foo = new TestObject("bar", 0, 0, 1, 1, "assets/sprites/test.png"); Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 23, 2016 Share Posted July 23, 2016 You are doing something very strange, and my question is the next: why do you need that kind of stuff? Why not just use Sprite.fromFrame or Texture.fromImage? I think you missed something while learning javascript. function MySprite(name, x, y, scale_x, scale_y, url) { PIXI.Sprite.call(this, new PIXI.Texture(PIXI.Texture.Empty.BaseTexture)); this.position.set(x, y); this.scale.set(scale_x, scale_y); PIXI.loader.add(name, url, function(lo, res) => { this.texture = res; }) } MySprite.prototype = Object.create(PIXI.Sprite); MySprite.prototype.constructor = MySprite; 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.