Jump to content

Assorted Questions (groups/ scope/ OOP)


Boxtufty
 Share

Recommended Posts

Thanks to anyone who tries to make sense of any of this!  :unsure:

 

 

1. Runtime performance: Is it significantly more efficient to recycle children in a group with reset()/revive() and kill(), or is it acceptable to just create() and kill()? 

 

2. Is it possible to have arcade physics bodies enabled in nested groups? I've tried many variations of this where the child/parent/both have the physics body enabled and it ain't happening.

 

3. Situation: A group of entities spawn at Y=0, X=random. They move down the world until Y=1000 and are then killed. The group has 50 entities in it. Only 10 exist simultaneously at any given time. getFirstDead() would just reuse the last 10 entities in the group, how can I cycle through the entire group of 50? Something like this:

for(var n=0;n<group.length;n++){   getAt(n);}

tl;dr: Is there something like getLastDead/Alive/Exists?

 

 

4. What's the best way to drawn lines? I'm using:

line = new Phaser.Line(a.x, a.y, b.x, b.y);line.fromSprite(a, b, false);game.debug.geom(line, '#ff0000');

I have it drawn to an entity that moves around the world, but there's quite a bit of latency. Is there a better/ alternative method I can try?

Link to comment
Share on other sites

1. Runtime performance: Is it significantly more efficient to recycle children in a group with reset()/revive() and kill(), or is it acceptable to just create() and kill()?

 

Yes. In most cases, it is more efficient to take the memory cost up front when possible.

 

2. Is it possible to have arcade physics bodies enabled in nested groups? I've tried many variations of this where the child/parent/both have the physics body enabled and it ain't happening.

 

Have you looked at Group.enableBody? Or Group.physicsBodyType? You should be able to use one of those when creating a new group to enable physics bodies before adding the group to a larger group.

 

Situation: A group of entities spawn at Y=0, X=random. They move down the world until Y=1000 and are then killed. The group has 50 entities in it. Only 10 exist simultaneously at any given time. getFirstDead() would just reuse the last 10 entities in the group, how can I cycle through the entire group of 50? Something like this:

 

What you might want to do to handle only some subset is forEachAlive or forEachDead and, for the third parameter, send in the exact number to work on, exiting the loop when it is reached.

 

4. What's the best way to drawn lines?

 

That's usually the suggested way, yes. The one you showed. Like in this example.

 

If you really want to work on a lower level, you can still call lineTo from the game's drawing context. You will need to call moveTo, lineTo, and stroke manually each time to do it, though.

Link to comment
Share on other sites

4. In WebGL mode using the Debug calls is really expensive (it has to create a brand new texture on the GPU, every single frame). So please don't use it in a proper game :) Instead you'd be better off using a Graphics object imho, especially as it has native moveTo/lineTo functions.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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