1 decade ago by oronbz
Hey guys,
I'm about to complete Jesse's book and tutorial and trying to figure out one piece of code from its "Resident Raver" game.
This is the entity:
What i'm trying to understand is this couple of lines:
I know .map() is an array method which also returns an array.
Here it applied on "delta()" and the return value is going to the "alpha" property, both (to my knowledge) are not arrays. what's the trick here? can anyone simplify this for me please?
Thanks,
Oron
I'm about to complete Jesse's book and tutorial and trying to figure out one piece of code from its "Resident Raver" game.
This is the entity:
EntityDeathExplosionParticle = ig.Entity.extend({ size: {x: 2, y: 2}, maxVel: {x: 160, y: 200}, lifetime: 2, fadetime: 1, bounciness: 0, vel: {x: 100, y: 30}, friction: {x: 100, y: 30}, collides: ig.Entity.COLLIDES.LITE, colorOffset: 0, totalColors: 7, animSheet: new ig.AnimationSheet('media/blood.png', 2, 2), init: function(x, y, settings) { this.parent(x, y, settings); var frameID = Math.round(Math.random()*this.totalColors) + (this.colorOffset * (this.totalColors+1)); this.addAnim('idle',0.2, [frameID]); this.vel.x = (Math.random() * 2 - 1) * this.vel.x; this.vel.y = (Math.random() * 2 - 1) * this.vel.y; this.idleTimer = new ig.Timer(); }, update: function() { if (this.idleTimer.delta() > this.lifetime) { this.kill(); return; } this.currentAnim.alpha = this.idleTimer.delta().map( this.lifetime - this.fadetime, this.lifetime, 1, 0 ); this.parent(); }, });
What i'm trying to understand is this couple of lines:
this.currentAnim.alpha = this.idleTimer.delta().map( this.lifetime - this.fadetime, this.lifetime, 1, 0 );
I know .map() is an array method which also returns an array.
Here it applied on "delta()" and the return value is going to the "alpha" property, both (to my knowledge) are not arrays. what's the trick here? can anyone simplify this for me please?
Thanks,
Oron