getting rid of timers
We all know that timers can cause some major performance issues.
Does anyone have any neat tricks to getting rid of timers completely and using something more memory-friendly instead?
Does anyone have any neat tricks to getting rid of timers completely and using something more memory-friendly instead?
Comments
When you want to use a timer:
change attribute game.TimerStart to game.Time
(Let's say your timer is "For" 3 Seconds)
When game.Timer Start = game.Time - 3,
Behavior Here
Matt
Create an index/integer attribute called zero. Give it a value of 0.
When zero=floor( self.Time *20)%2
...do stuff
That will 'do stuff' every 0.1 seconds.
Adjust the '20' to change that. Without the '20' it will do stuff every 2 seconds.
---
www.HoneyTribeStudios.com
Get Honey Tribe on iTunes
"...a touch above the rest in the endless running genre": 148apps.com
Say hi on Twitter
Like us on Facebook
For example
An enemy is hit and alpha interpolated to 0
When alfa is zero alfa is 1
Sometimes alfa goes back to 1 sometimes it stays 0.1 (or at leat not 0. I don't know exactly where it stops)
Lump Apps and My Assets
Method 1 (with timers)
Timer: after 1.2 seconds
--destroy
Method 2 (without timers)
-Interpolate: self.TimerCount to 1
duration 1.2
Rule: when self.TimerCount = 1
--destroy
I did this to about 30 actors with images just to make sure that I would get accurate data.
The scene using method 1(with timers) had a total memory usage of 51.1 MB
The scene using method 2 (without timers) had a total memory usage of 46.8MB
Removing the timers saved me about 5MB of memory!
All of the extra memory went to the "other" section
To replace a timer with 'after':
Make a real attribute called timeStamp.
When your event happens change timeStamp to gameTime
When gameTime = timeStamp + 1second or whatever duration you want
...do stuff
---
Get Honey Tribe on iTunes
"...a touch above the rest in the endless running genre" 148apps.com
"If you’re a nature lover, or simply a lover of well-executed games, Honey Tribe... is worth checking out. Download it today." AppAdvice.com
Say hi on Twitter
Like us on Facebook
www.HoneyTribeStudios.com
Create an integer attribute called 0 and leave it at 0 (this will never change)
Then whenever you want to have an "every" timer used at whole second intervals you will input this rule:
Rule:
...When attribute game.0 = self.time%3
......Change attribute a to a+1
In this example the "3" after the modulo "%" is the seconds you want in between each change of attribute, and the "a to a+1" was just some gibberish to give an example of an attribute being changed.
What's going on here is that as self.time changes, whenever it becomes an exact multiple of 3, the rule's conditions are valid.