kittykatattack / smoothie

Ultra-smooth sprite animation for Pixi using true delta-time interpolation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to set sprite.x = 0 IMMEDIATELY and bypass an animation?

advancedsoftwarecanada opened this issue · comments

Howdy folks, using Smoothie on www.StarCommanderOnline.com

IMO Smoothie should be official use with PixiJS. <3

Anyway, I have some stars animating. When they hit the edge of screen, I swap the X or Y to the other side of the screen.

This actually results in the star animating quickly across the screen. Not ideal lol!

My code is simply sprite.x = 0; which is executed if( sprite.x >= 1000)

The star ........................................ right across the screen!

So how does one bypass the animation system for such a process?

I was able to resolve this by setting an initial value of sprite.alpha = 1, and as it was set to transition back 'home' would set sprite.alpha = 0.

This turns off the sprite until it's transition, which lasted one tick. It's friggin magical.

`// nebula Speed
var x_speed = 0;
var y_speed = 0;

					x_speed = player_ship.x_previous - player_ship.x;
					y_speed =  player_ship.y_previous - player_ship.y;
					
					nebula.x += (x_speed*nebula.speed)/5; 
					nebula.y += (y_speed*nebula.speed)/5; 
					
					nebula.alpha = 0.8;
					
					// RIGHT
					if(nebula.x > window.innerWidth+500){
						nebula.x = -490;
						nebula.alpha = 0.0;
						nebula.rotation = Math.floor(Math.random() * 8);
					}
					// LEFT
					if(nebula.x < -500){
						nebula.x = window.innerWidth+490;
						nebula.alpha = 0.0;
						nebula.rotation = Math.floor(Math.random() * 8);
					}
					// TOP
					if(nebula.y > window.innerHeight+500){
						nebula.y = -490;
						nebula.alpha = 0.0;
						nebula.rotation = Math.floor(Math.random() * 8);
					}
					// BOTTOM
					if(nebula.y < -500 ){
						nebula.y = window.innerHeight+490;
						nebula.alpha = 0.0;
						nebula.rotation = Math.floor(Math.random() * 8);
					}`