Hello,
I’m currently trying to make a little game but I experience now some loss of framerate while adding “bullets” in the game
I’ll not enter in the full code source as it will take some time but basically
I got a mainGame class, a Player class, and a bulletClass
the mainGame class contain the game loop working like this,
A main timer checks:
-loop function of the Player class, checking if space is pressed,
if it’s pressed a bullet is displayed with this line in the player class:
//main_class is the MainGame class and the container is the main display
main_class.container.addChild(new Bullet(x, y, rotation,main_class));
//then the bullet add itself in a _bulletArray of the Main Game class
-loop function of the bullet Class, for each bullet cointained in the _bulletArray,
it moves the bullet from some X, and if it’s out of view of the screen it destroying itself from the array and with a removeChild of the display list like this:
y += vy;
x += vx;
if (x > main_class.visX || y > main_class.visY || x < main_class.visXMin || y < main_class.visYMin)
destroy(); //function that erase it from the array and from the display list
Problem is, if I shot more than 3 bullets i experience a drop of the FrameRate from 30 to 19, and once bullets are exiting the screen, the FPS get back to 30…
Is there a better solution to don’t have this kind of framerate loss?