Recycling bullets: am I doing this right?

NesesitaGamesNesesitaGames Member Posts: 160
edited November -1 in Working with GS (Mac)
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?

Comments

  • NesesitaGamesNesesitaGames Member Posts: 160
    Bump... anyone?
  • THRSTNTHRSTN Member Posts: 178
    ill see your bump and raise you a bump
  • NesesitaGamesNesesitaGames Member Posts: 160
    LOL, THRSTN. I call your bump :)
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    yep thats right. You just might have to play with the timer to get it how you want and change velocity and such. But thats how you set it up.
  • AjBlueAjBlue Member Posts: 215
    the whole point of recycling is to not spawn anything in,i would suggest placing 10 or so missiles outside of your scene. then when shoot behavior is activated make integer attribute +1 and make it so the attribute counts up only to the number of bullets you have and then starts from the beginning again, you can find this in the cookbook tutorial, of music on off button. then make a rule in each different bullet, if integerattribute = bullets specific number, change attribute x to gunx (same with y), and change velocity to desired velocity.

    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
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    AjBlue said:
    the whole point of recycling is to not spawn anything in,i would suggest placing 10 or so missiles outside of your scene. then when shoot behavior is activated make integer attribute +1 and make it so the attribute counts up only to the number of bullets you have and then starts from the beginning again, you can find this in the cookbook tutorial, of music on off button. then make a rule in each different bullet, if integerattribute = bullets specific number, change attribute x to gunx (same with y), and change velocity to desired velocity.

    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

    Thanks for pointing that out, didnt notice he had a spawn in there.

    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.
  • NesesitaGamesNesesitaGames Member Posts: 160
    Wow, thanks so much, John and Aj- will try that out! Do you think it would work fine with just one bullet, though, that I keep reusing over and over? That would eliminate the need to have a count up to the number of bullets I have?

    Oh, and it's "she"- I'm a girl :)
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    NesesitaGames said:
    Wow, thanks so much, John and Aj- will try that out! Do you think it would work fine with just one bullet, though, that I keep reusing over and over? That would eliminate the need to have a count up to the number of bullets I have?

    Oh, and it's "she"- I'm a girl :)

    It would work with one bullet, you just have to remeber since your only using that one, you wont be able to shoot again until you hit the target. Because if you do it will change back to the gun position before hitting anything.
Sign In or Register to comment.