Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by ajainvivek

Hi All,

I am developing a game where the biker riding entity is swapped with biker exhaust entity when heat meter is full. I have created a dot entity in the biker so the collision is set to the dot. The dot entity is set along with biker riding entity. At the current point i want the dot entity velocity to be set to 0 ,until the exhaust frame is over then swap with biker riding entity .but i am unable to set the dot velocity to 0 for particular time.

I have put down the code
	
	if(ig.input.state('right'))
	{
	this.exhaustTimer.set(4);   //set the timer
	if(heat.anims.run.frame == 97 )   //condition when entity is spawned
		{	
			
			ig.game.spawnEntity( EntityPlayer_exhaust, this.pos.x ,this.pos.y-50 );
		
               if(this.exhaustTimer.delta() >= -4 &&  this.exhaustTimer.delta() <= -1  )
		    {	
			
		       	this.vel.x = 0;
		     }	

		}
         // how do i set the velocity to 0  

	
		
	}

1 decade ago by Graphikos

Good timer tutorial over at POIJS.

http://pointofimpactjs.com/tutorials/view/7/using-impact-timers

1 decade ago by Jerczu

There is one main issue with your code - when you press right every frame you set the timer therefore delta don't change. Add a bool trigger like isTimerSet and based on that trigger set your timer

//somewhere at the beginning of your code with all the declarations
...

isTimerSet:false,

...

   if(ig.input.state('right'))
    {
if(!this.isTimerSet){// if timer not set
    this.exhaustTimer.set(4);   //set the timer
this.isTimerSet = true; //this will ensure this will fire only once
}
    if(heat.anims.run.frame == 97 )   //condition when entity is spawned
        {    
            
            ig.game.spawnEntity( EntityPlayer_exhaust, this.pos.x ,this.pos.y-50 );
        
               if(this.exhaustTimer.delta() >= -4 &&  this.exhaustTimer.delta() <= -1  )
            {    
            
                   this.vel.x = 0;
             } else{
this.isTimerSet = false;//conditions met reset the trigger to allow this action be triggered again
}   

        }
         // how do i set the velocity to 0  

    
        
    }

If you want that to work every time your timer conditional is met youll need to reset the isTimerSet to false
Page 1 of 1
« first « previous next › last »