silverplanetside Posted January 8, 2016 Share Posted January 8, 2016 Following the samples: To load a sprite I did this:var texture = PIXI.Texture.fromImage('sprite1.png');var sprite1 = new PIXI.Sprite(texture);Now the only way to display it seems: stage.addChild(sprite1);And the only way to translate it seems:sprite1.position.x = [...]sprite1.position.y = [...]Can't I assign an id to the sprite when loading it and translate it through something nice like PIXI.Spritelist('sprite1').position.x = [...] ?If it's not possible, how do you guys dynamically generate and modify them over a lapse of time? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 8, 2016 Share Posted January 8, 2016 You can iterate container's children.stage = new PIXI.Container();for (var i=0;i<10;i++) stage.addChild(Sprite.fromImage(...));for (var i=0;i<10;i++) {stage.children[i].position.x = [...]stage.children[i].position.y = [...]} If you want you can store them somewhere else. Dont forget that sprites are lightweight, you can have 1000 of them without a problem. Number of textures matters, better to have all-in-one atlas. If you have only one texture, you can put 100k sprites in PIXI.ParticleContainer and it will work just fine. Quote Link to comment Share on other sites More sharing options...
silverplanetside Posted January 8, 2016 Author Share Posted January 8, 2016 You can iterate container's children.stage = new PIXI.Container();for (var i=0;i<10;i++) stage.addChild(Sprite.fromImage(...));for (var i=0;i<10;i++) {stage.children[i].position.x = [...]stage.children[i].position.y = [...]} If you want you can store them somewhere else. Dont forget that sprites are lightweight, you can have 1000 of them without a problem. Number of textures matters, better to have all-in-one atlas. If you have only one texture, you can put 100k sprites in PIXI.ParticleContainer and it will work just fine.Sorry, not useful for me. If having to manually set up variables to be able to access to a specific sprite is bad, not having a variable and iterate over every sprite in the scene is even worse, then I can't access them individually at all. Thanks anyway. Quote Link to comment Share on other sites More sharing options...
xerver Posted January 8, 2016 Share Posted January 8, 2016 You need to have a reference to the sprite, so you have to know where it is. If you want to have a table of them keyed by some string you can do that, just be sure to insert them by the key when you create them. This is outside the scope of pixi though for sure. Quote Link to comment Share on other sites More sharing options...
dominate Posted January 9, 2016 Share Posted January 9, 2016 Sorry, not useful for me. If having to manually set up variables to be able to access to a specific sprite is bad, not having a variable and iterate over every sprite in the scene is even worse, then I can't access them individually at all. Thanks anyway. You're right. I had some related questions here: http://www.html5gamedevs.com/topic/19712-how-to-keep-attributes-on-objects/ Indeed, it would be nice if it was inside the scope of pixi, adapting this mechanism from three.js Quote Link to comment Share on other sites More sharing options...
catafest Posted January 10, 2016 Share Posted January 10, 2016 You need to have a reference to the sprite, so you have to know where it is. If you want to have a table of them keyed by some string you can do that, just be sure to insert them by the key when you create them. This is outside the scope of pixi though for sure.@xerverSorry about this note, but seam to me a general problem.I think It was a problem with point reference and also I think not everything can be passed by reference.I mean some pixi.js source code cannot be translate into new source code.I have one topic about translate with mouse one mask and I used add and load function.The problem is with animate over mouse ... This is true @xerver ? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 10, 2016 Share Posted January 10, 2016 @catafest That topic about mouse movement was answered, do you still have troubles with it? 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.