Recycling bullets: am I doing this right?
NesesitaGames
Member Posts: 160
In an effort to reduce memory usage, I've got this setup on my vertical shoot 'em up scene. The gun is below, the enemy is above.
Gun:
- Spawn missile
- Constrain game.CurrentGunX to self.PositionX
- Constrain game.CurrentGunY to self.PositionY
Missile:
- Change Velocity upwards (90) at 1000 speed
- On Collide with Enemy, Change Attribute self.PositionX to game.CurrentGunX
and Change Attribute self.PositionY to game.CurrentGunY
- After .1 seconds, Change Velocity upwards (90) at 1000 speed
Am I doing this right?
Gun:
- Spawn missile
- Constrain game.CurrentGunX to self.PositionX
- Constrain game.CurrentGunY to self.PositionY
Missile:
- Change Velocity upwards (90) at 1000 speed
- On Collide with Enemy, Change Attribute self.PositionX to game.CurrentGunX
and Change Attribute self.PositionY to game.CurrentGunY
- After .1 seconds, Change Velocity upwards (90) at 1000 speed
Am I doing this right?
Comments
then to make it go back to spawn, in missile, rule if missile overlaps or collides > change attribute x and y position, back to original start position. and another attribute that changes the velocity back to 0 so it doesn't move offscreen and possible onto the scene. you might need to make walls to spawn you missile to start position when offscreen too depending if you are wrapping.
then of course you could use this method for the targets by having them start offscreen. thus making your performance a lot better. also if you want to optimise even more, if your bullets are going to go completely straight on the x or y axis, you could then make your bullets interpolate, and take off your bullets moveable attribute.
hope i helped
Like aj said you shouldnt be spawning, you should have all the missiles offscreen then when your shoot button is pressed change there position to the gun x and y and do what you have.
Oh, and it's "she"- I'm a girl