Jump to content

(V3) Displaying multiple sprites that use the same name


systemx17
 Share

Recommended Posts

I am currently working on a space game (my first game ever with Pixi) and I am sure there is a good chance this has been clarified before. However I am unable to understand some of the replies to other posts without wording this to my specific situation.

 

I have an array that is storing the locations of space "lasers" (Dr Evil reference intended). I want to draw these laser beams as they move across the screen. With rapid fire enabled there might be around 20 lots of beams shooting around the screen at once.

 

What is the best way to go about this.. I have 3 unfinished guess:

 

1) Create a sprite for each and when they fade off, destroy the sprite somehow

 

2) Create 40 or so instances of these lasers and only reposition the 20 that are actually currently on the screen

 

3) Create another array that stores a new sprite for each laser. As the lasers fade off, delete that array entry specifically

 

Any advice/help would be much appreciated.

Link to comment
Share on other sites

I can tell you how phaser (the 2d game engine that uses pixi for rendering handles this):

 

It's pretty much your guess number two.

 

Phaser gives the pixi sprites some more properties and the option to put them into groups (containers that aren't drawn themselves but hold all sprites - I think they exist in Pixi too).

You either guess your maximum amount of lasers that you will be needing and initialize them beforehand - or and this is what I do:

Every time you need a new laser, you check all the laser-group members if they are currently in use (visible flag) - if you find one that is invisible, you use that one. If you don't find one, you add a new laser to the group.

Of course you have to set lasers that leave the screen to become invisible and skip updating them, until you need them again.

 

(Phaser does not do this via the visible flag, but uses an alive property)

 

If you are not too invested in the direct usage of pixi and like the idea of some more game related functions (like easy collision management) on top of the group stuff, you should check out the phaser examples.

This example should have the group management in it, even with lasers ;) http://phaser.io/examples/v2/games/invaders

Link to comment
Share on other sites

Thanks for your reply. The reason I have chosen PIXI and will probably stick with it is because I usually steer clear of frame works. I had looked at Phaser before and I believe the time it would take to learn how to do specific tasks would take me longer to learn than researching and writing them myself. But your point is solid and very valid for anyone not as stubborn as me :)

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...