Using addchild to add the same movie clip twice

18 posts

Flag Post

I know that using addchild twice on the same object simply replaces it so doing addchild(mc1); addchild(mc1);
would only add 1. My code currently looks like this for bullets


if (Key.isDown(Keyboard.SPACE) && shootTimer >= 20 - shootTimerVar * 1.4)
						{


							var bullets = new Bullet();
							stage.addChild(bullets);
							bullets.rotation = this.rotation;
							bullets.x = this.x;
							bullets.y = this.y;
							shootTimer = 0;
							if (numberOfBulletsVar > 1)
							{
							var bullets1 = new Bullet1();
							stage.addChild(bullets1);
							bullets1.rotation = this.rotation;
							bullets1.x = this.x-10;
							bullets1.y = this.y-10;
							shootTimer = 0;
							}

I want it to look similar to


if (Key.isDown(Keyboard.SPACE) && shootTimer >= 20 - shootTimerVar * 1.4)
						{


							var bullets = new Bullet();
							stage.addChild(bullets);
							bullets.rotation = this.rotation;
							bullets.x = this.x;
							bullets.y = this.y;
							shootTimer = 0;
							if (numberOfBulletsVar > 1)
							{
							var bullets1 = new Bullet();
							stage.addChild(bullets1);
							bullets.rotation = this.rotation;
							bullets.x = this.x-10;
							bullets.y = this.y-10;
							shootTimer = 0;
							}

this way Im using 1 class for all of my bullets which (im assuming) should make the game go smoother when there is more hittesting against enemies going on at the same time. Currently though, with that code, I have 1 going along the bottom nonstop instead of spawning at my ships x/y coordinates. What would be the cause of that and possible solution?

 
Flag Post

Loop?


for(var i:int = 0; i < numBullets; i++) {
        var bullet:Bullet = new Bullet();
        stage.addChild(bullet);
        bullet.rotation = this.rotation;
	bullet.x = this.x-(i*10);
	bullet.y = this.y-(i*10);
	shootTimer = 0;
}

 
Flag Post
int c = bulletCount, e = -(c >> 1);
for int i = 0; i < c; ++i {
  new Bullet();
  addChild bullet
  bullet rotation = rotOff * t + rotation
  bullet x = bXOff * t + yXMod * t + x
  ... getYOff(i, t) + y
}
timer = 0;
 
Flag Post

I suck at this kind of thing. Time to look up loops/arrays so I can force myself to learn them. Suppose Im not going to be able to get away from arrays. Better to just learn them instead of finding LOOP holes to them all the time (its Punny!)

 
Flag Post

So the tutorial im looking at right now shows the workings of loops pretty well, and helped me out with understanding the code posted. http://www.republicofcode.com/tutorials/flash/as3loops/#basicloop

Is there a way to control the individual values though? for example, I want the 4th i to have a seperate x starting coordinate. Is there any way to single out that specific value instead of just making it a constant increase like (i*10);

 
Flag Post

Originally posted by BluePriest:

Is there a way to control the individual values though? for example, I want the 4th i to have a seperate x starting coordinate. Is there any way to single out that specific value instead of just making it a constant increase like (i*10);

you can either hard code the values and look them up (vals[bulletCount][i]) or derive a complicated formula using mod and such to generate the values

 
Flag Post

So for some reason I wasnt able to figure out how to put all my enemies into 1 array, and I did that and it decreased the fps drop when there are tons of enemies on the screen. Heres a quick question. Will making the change im working on right now help out with performance? I suffer in performance when there are a lot of bullets and asteroids (and I mean a lot) on the screen at a time. Will this change help that, or will it just make the code look prettier

 
Flag Post
for (int i = 0; i < numBullets; i++){
  if (i ! = 3)
    addChild(new Bullet(x * i, y * i));
  else
    addChild(new Bullet(42, y * i));
}

If you want to do a lot of exceptions, try using a switch table.

Edit: In response to your post above, look up blitting. Using the displaylist is rather slow, you can get a significant performance boost with a good blitting engine implementation.

 
Flag Post

one has to learn to crawl before learning to fly. DisplayList holds all the display issues for him, and he has to make it work first, and only then to make it work fast.

 
Flag Post

the biggest issue is probably hitTesting, and possibly index creep caused by stuff not getting spliced out of the array(s)

 
Flag Post

IMO you are optimizing in the wrong places. If you are experiencing lag, I’m betting that 90% of the frame time is occupied with rendering.

 
Flag Post
Originally posted by qwerberism:

IMO you are optimizing in the wrong places. If you are experiencing lag, I’m betting that 90% of the frame time is occupied with rendering.

I only lag when shooting(1-200+ enemies on the screen at a time, and 20+bullets hittesting against them), not when then enemies are being rendered.

Originally posted by skyboy:

the biggest issue is probably hitTesting, and possibly index creep caused by stuff not getting spliced out of the array(s)

Looks like it is going back to hittesting. Ive traced the length of the arrays, and it is returning to 0 after all enemies are gone. Looks like ill have to try to figure out how to use your hittest program as it looks like its considered one of the most effecient hittests out there
edit, i believe im currently using 1 version, but I believe im using an old version.

 
Flag Post
Originally posted by BluePriest:
Originally posted by qwerberism:

IMO you are optimizing in the wrong places. If you are experiencing lag, I’m betting that 90% of the frame time is occupied with rendering.

I only lag when shooting(1-200+ enemies on the screen at a time, and 20+bullets hittesting against them), not when then enemies are being rendered.

Ha!

 
Flag Post
Originally posted by BigJM:
Originally posted by BluePriest:
Originally posted by qwerberism:

IMO you are optimizing in the wrong places. If you are experiencing lag, I’m betting that 90% of the frame time is occupied with rendering.

I only lag when shooting(1-200+ enemies on the screen at a time, and 20+bullets hittesting against them), not when then enemies are being rendered.

Ha!

Is this a hint that I should expect lag with that?
 
Flag Post

Try disabling hittesting. Have the bullets completely ignore the enemies, and see how much it lags.

 
Flag Post

Apparently, splice()ing the middle of an array in AS2 is slow.

in the loop:
instead of splice()

var l:int = array.length
for(var i:int = 0;i<=l;i++){
if(you want to remove it){
array[i].destroy()//or something similar
array[i]=array[—l];
array.length—;
i—;
}
}

Not sure if I’ve messed something up there. Taught to me by UG.

 
Flag Post

It’s comparatively slow in every language.

 
Flag Post

There was a particular thread a little while ago where someone’s AS2 game was running fine, then, with an updated flash player, was incredibly laggy.

UG was talking about optimising splicing to avoid reordering, but I don’t think I ever found out whether that was the problem, or if it was something else.

But yeah, I can’t imagine reindexing everything in an array would be particularly fast.