1 decade ago by blueicelt
I am adding a small messaging notification to my game and I have run into an issue. It appears that all entity timers and alpha settings are global to that type of entity and not to each individually spawned entity. When I decrease the timers and alphas on an entity to fade it out, all of them fade out at the same time.
Any ideas why this is?
EntityMessage = ig.Entity.extend({ collides: ig.Entity.COLLIDES.NEVER, font: new ig.Font('media/font.png'), size: {x:300, y:50}, zIndex: 40, timer: 300, gravityFactor: 0, message: '', previousMessage: null, alpha: 1, init: function( x, y, settings ) { this.parent( x, y, settings ); }, update: function() { this.parent(); --this.timer; if ( this.timer < 30 ) { this.font.alpha = 1 * (this.timer/30); } if ( this.timer <= 0 ) { this.kill(); } }, draw: function() { this.parent(); this.font.draw( this.message, this.pos.x, this.pos.y ); } }); });
showMessage: function(message) { var offsetx = (384-(message.length*6))/2; if ( offsetx < 42 ) offsetx = 42; var rows = Math.floor(message.length/384); if ( rows < 1 ) rows = 1; var offsety = (384/2)-(rows*24); var newMessage = ig.game.spawnEntity(EntityMessage, offsetx+64, offsety, { message: message, alpha: 1, timer: 300 }); newMessage.previousMessage = this.currentMessage; for ( var last = newMessage.previousMessage; last != null; last = last.previousMessage ) { offsety -= 24; if ( offsety < 0 ) break; last.pos.y = offsety; } this.currentMessage = newMessage; }
Any ideas why this is?