Author Topic: Limiting amount of a certain sprite allowed on a map.  (Read 1807 times)

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Limiting amount of a certain sprite allowed on a map.
« 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?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Limiting amount of a certain sprite allowed on a map.
« Reply #1 on: 2007-07-21, 08:08:24 AM »
Well, to delete a dynamic sprite, just deactivate it when you want it to go away.  It would be something along the lines of
Code: [Select]
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.
Edward Dassmesser

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: Limiting amount of a certain sprite allowed on a map.
« Reply #2 on: 2007-07-21, 07:25:43 PM »
Well inside the car sprites rules, I have this

Code: [Select]
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.


durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Limiting amount of a certain sprite allowed on a map.
« Reply #3 on: 2007-07-22, 09:30:02 PM »
Well, you can limit it to only create them "every so often" by checking the current frame mod x == y.  For example:

Code: [Select]
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.
Edward Dassmesser