1 decade ago by Nozferatu
In fundamental OO we know that we use properties/attributes to describe an object.
So what would be the best practice for handling values used strictly for processing that don't really describe our object - but need to be kept beyond a single iteration of our update loop?
To give an example, what would be a good way of handling a timer that causes our player to do something approximately every 5 seconds?
I feel really dirty using attributes for this sort of thing. This timer is only used for this single object instance, no other objects need to know about it so why is it an attribute? What's a better way?
So what would be the best practice for handling values used strictly for processing that don't really describe our object - but need to be kept beyond a single iteration of our update loop?
To give an example, what would be a good way of handling a timer that causes our player to do something approximately every 5 seconds?
EntityPlayer = ig.Entity.extend({ timer: new ig.Timer(5), … update: function() { this.parent(); if( Math.floor(this.timer.delta()) % 5 == 0 ) { // do something every 5 seconds } }, … });
I feel really dirty using attributes for this sort of thing. This timer is only used for this single object instance, no other objects need to know about it so why is it an attribute? What's a better way?