1 decade ago by paulh
ay quick suggestions on how to override an entities draw method to easily make trails?
This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact
Google comes up with a fair amount of examples on what can be done.
trail: [], //trail
trailers: 5, //number of trailing images
init: function( x, y, settings ){
this.parent( x, y, settings );
//build trail array
for( var i = 0; i < this.trailers; i++ ){
this.trail.push( this.pos );
}
},
draw: function(){
//draw trailers
var alpha = this.currentAnim.alpha;
for( var i = 0; i < this.trailers; i++ ){
this.currentAnim.alpha = i.map( 0, this.trailers, 0.1, 1 );
this.currentAnim.draw(
this.trail[i].x - this.offset.x - ig.game._rscreen.x,
this.trail[i].y - this.offset.y - ig.game._rscreen.y
);
}
this.currentAnim.alpha = alpha;
this.parent();
},
update: function(){
this.parent();
//remove first trail element, push on new element
this.trail.shift();
this.trail.push( this.last );
}