actionscript 3 - Best way to reuse an element from an Array? -


I have an array of character objects (Sprite is extracted).

  Public Static Verlists: Array;  

When a character dies, I put a flag to give this sign.

  char.die = true;  

When I create a new player, to check the slot again, I check against this flag. This is where the problem arises. What is the best way to do that? Actually I have this approach:

  char = new four (); (* Var =: number = 0; i & lt; char.charlist.length; i ++) {if (char.charlist [i] .death) {char.charlist [i] = Four; Return; }}  

But the problem is that I have come from C ++ and I think calculation of index is completely useless.
I'll do this, but it does not work in AS3, because I can not access this item from context:

  char = new letter (); / * ... * / for (var i: number = 0; i & lt; char.charlist.length; i ++) {var char_it: char = char.charlist [i]; If (char_it.death) {char_it = char; Return;  

Just a note: Charite is a stable member of class four.

Do you have any ideas or a better attitude?

Thank you!

The "customized" version is not very favorable, I guess.

Your code does not reach 2 in every iteration, it only happens when you find a dead variable; And after that you come back, then there is no big deal, I guess.

Personally, I do not think the use of an array slot is going to make a big difference. And, maybe it may be low (but the worst part is that if you put it off you can simplify your code). Suppose you have 100 characters, 60 of which are dead, and you have a loop that runs each frame and does some check / action on each live cam. You will loop over 100 characters, when you can loop more than 40, if you reject a list of living items and a separate list of dead items, then prepare to reuse them. In addition, "dead list" can be handled as a stack, so there is no need for repetition to get all four.

However, I see 2 things that you can easily adapt to in your code:

1) Retrieve the list length outside the loop:

Do this:

  var len: int = char.charlist.length; (Var i: Number = 0; i  

In return:

 for  (var i: number = 0; I & lt; char.charlist.length; i ++) { 

Compiler does not remove the call length (after the ecmascript device).

2) Avoid Static Access (for the Charlittist) It is much slower than the example used.

Edit:

To read your question again, I know that I have misunderstood something about it. You are not trying to reuse the variable items, but rather the array slots, I do not think it is worth using the array slots (the actions are not fixed in the actionscript); But something that can help in the display is reusing four things. Resetting Sprite is usually cheaper than creating a new one, you can manage it with a pool of "dead" objects, from which You can take one and instead of making a new one when you need it, "take it back"

About this post, object pool (blog for action stuff, especially performance and data structure is a good resource for the subject):


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -