Jump to content

Is a variable name the only way to load/translate a sprite?


silverplanetside
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

@xerver

Sorry 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 ?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...