An optimized way to reduce timers
homelesswombat
Member Posts: 73
So I came up with this last night while I was building an actor with a LOT of behaviors that needed to go in a specific sequence and thought I would share it.
game.timer = 0
Master Actor
Timer
.every 1 seconds
..change game.timer to game.timer+1
Rule
.When game.timer = 5
..Behavior
Rule when game.timer >= 10
.change game.timer to 0
Follower Actor
Rule
.When game.timer >= 7
.When game.timer <= 10
..Behavior
I now use this method for making platforms fade in and out in a cycle. I use a single master actor to run one timer that all other actors check on to determine when to do different behaviors. This is pretty efficient because there is only one timer. It also allows you to fake running a timer within a timer, although if you run a timer as one of the actor behaviors, the game will still be running two timers at once.
Anyone who wants to input how to make this better I'm all ears!
game.timer = 0
Master Actor
Timer
.every 1 seconds
..change game.timer to game.timer+1
Rule
.When game.timer = 5
..Behavior
Rule when game.timer >= 10
.change game.timer to 0
Follower Actor
Rule
.When game.timer >= 7
.When game.timer <= 10
..Behavior
I now use this method for making platforms fade in and out in a cycle. I use a single master actor to run one timer that all other actors check on to determine when to do different behaviors. This is pretty efficient because there is only one timer. It also allows you to fake running a timer within a timer, although if you run a timer as one of the actor behaviors, the game will still be running two timers at once.
Anyone who wants to input how to make this better I'm all ears!
Comments
Master Actor:
Constrain game.timer to floor(self.time)
Everything else would work the same...
Let me know if you get a chance to test either method. Thanks!
There's already a game clock. I think it's much more accurate to use that. With the Photics: Toolbox, I experimented with this matter heavily. It was important that the app be optimized, but also accurate. I was building a stopwatch!
change game.levelStartTime to game.time
constrain game.levelTime to game.time - game.levelStartTime