Phaser 2.6.2


#1

i created a game in phaser 2.6.2 and i need to change spritesheet color but programatically and smoothly…it means it shows color transition in background of image…

thanks and plz help m e in solving this issue…


#2

Try adapting this example. Phaser 2.6.2 doesn’t have Phaser.Tween.updateColor (CE only), maybe you can copy it.


#3

Thank you but i want to change the background color of spritesheet …


#4

I found this snippet somewhere which I used in Phaser CE to tween sprite’s color based in Phaser.Color.interpolateColor

/**
* Phaser.Tween a display object between two hex values
* @param {Phaser.Game} game the reference to the running game instance.
* @param {Object} obj the object to Phaser.Tween
* @param {number} startColor the starting color (hex)
* @param {number} endColor the ending color (hex)
* @param {number} time the duration of the Phaser.Tween
* @param {Function} callback a function to be called on Phaser.Tween completion
*/
function TweenTint(game, obj, startColor, endColor, time, delay, callback)
{
	var colorBlend = { step: 0 };
	var colorTween = game.add.tween(colorBlend).to({ step: 100 }, time, Phaser.Easing.Quadratic.InOut, false, delay);
	colorTween.onUpdateCallback(function()
	{
		obj.tint = Phaser.Color.interpolateColor(startColor, endColor, 100, colorBlend.step);
	});
	obj.tint = startColor;
	if (callback)
	{
		colorTween.onComplete.add(callback, this);
	}
	colorTween.start();
	return colorTween;
}

Alternatively:
Create another copy of the same sprite but with alpha 0 and it’s target color or tint it, then tween the alpha to fade in the targeted color sprite and fade out the original sprite.