Scrolling Game Development Kit Forum
SGDK Version 2 => Help, Errors, FAQ => Topic started by: Jam0864 on 2007-07-21, 06:39:29 AM
-
I'm using the AddSpriteHere rule to make produce a smoke sprite when turning to simulate skidding in a car...how do I limit the amount of sprites created? It just seems to keep creating them until the game crashes... lol Also how do I delete them after 1 cycle of their animation?
-
Well, to delete a dynamic sprite, just deactivate it when you want it to go away. It would be something along the lines of
If
>
Left operand: frame
Right operand: 10
Do
Deactivate
Except instead of 10, use the number of frames of animation (that is, the number of frames, times the repeat count of each frame).
To answer your other question, I'd need to know more about how you're creating it, and how many you want to show up.
-
Well inside the car sprites rules, I have this
If--->IsInputPressed
Input--->SpriteBase.InputBits.Left
InitialOnly--->False
Do--->SwitchToState
State--->(state + 1) % 360
Alignment--->RelativePosition.CenterMiddle
Do--->AddSpriteHere
SpriteDefinition--->typeof(Sprites.Smoke)
Location--->RelativePosition.CenterMiddle
Hotspot--->RelativePosition.CenterMiddle
(Also one exactly the same except turning right.)
So pretty much, if holding left key down, rotate car left, create smoke sprite.
It'd be good if it only created about 2 sprites a second, at the moment I think it does 1 a frame...making about 100 sprites in 2-3 seconds and the game crashes...that's not even enough time for the smoke sprite to finish it's animation. I'm not really sure if that's possible though...so a limit of about 20 sprites would be good.
-
Well, you can limit it to only create them "every so often" by checking the current frame mod x == y. For example:
If--->IsInputPressed
Input--->SpriteBase.InputBits.Left
InitialOnly--->False
If--->==
Left Operand--->frame % 10
Right Operand--->0
Do...
This will check the frame of animation the car is on, and if the value % 10 == 0, then it will do whatever, like create a puff of smoke. In practice, this means that it will create a puff of smoke once every 10 frames instead of once every frame.