FlxTween.tween() Not Working (I literally tried everything....EVERYTHING) #3198
Unanswered
ChocolateBunz
asked this question in
Q&A
Replies: 1 comment
-
I tried this in a new project and it works fine, regardless of whether I use PERSIST or ONESHOT: package states;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.tweens.FlxTween;
class AlphaTweenTestState3198 extends flixel.FlxState
{
var sprite:FlxSprite;
override function create()
{
super.create();
sprite = new FlxSprite();
sprite.makeGraphic(100, 100);
sprite.screenCenter();
add(sprite);
}
override function update(elapsed)
{
super.update(elapsed);
final shift = FlxG.keys.justPressed.SHIFT;
if (FlxG.keys.justPressed.RIGHT)
onEvent(true, sprite, 1.0, shift);
else if (FlxG.keys.justPressed.LEFT)
onEvent(false, sprite, 1.0, shift);
}
function onEvent(show:Bool, sprite:FlxSprite, duration:Float, persist:Bool)
{
final options = { type: persist ? PERSIST : ONESHOT };
if (show)
{
sprite.alpha = 0;
FlxTween.tween(sprite, { alpha: 1 }, duration, options);
}
else
{
sprite.alpha = 1;
FlxTween.tween(sprite, { alpha : 0 }, duration, options);
}
}
} I always recommend creating a blank project to try the most basic example to see if it's a flixel bug or a bug with some other code in your project. if this works in your version of flixel then keep moving other relevant code over until it breaks to see what the problem is |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a sprite, to which i've set the alpha opacity to 0. I used the tween function to tween it to alpha equal to 1. Which worked! but i have another code that is set to run which tweens the alpha back to 0. And for some reason...IT DOES NOT WORK....I have tried everything...setting the alpha to 0.000001 instead of 0. Writing some other code to see if the case is not being called in the first place (which worked so the case is running). Setting the tweening type to ONESHOT and PERSISTENT. Using the coordinates and some other sprite variables to see if the problem is from alpha (it's not i tried). It just seems like if you tween a sprite to some value you can't tween it to another after it's done. It's genuinely confusing for me and also gamebreaking since that's one of the core ideas I need for my game. Here's the code if you wanna help. Thanks a lot:
switch(eventName) { case 'SplashShow': Splashimg.alpha = 0; FlxTween.tween(Splashimg, { alpha: 1 }, flValue1, { type: FlxTween.PERSIST }); case 'SplashHide': Splashimg.alpha = 1; FlxTween.tween(Splashimg, { alpha : 0.01 }, flValue1, { type: FlxTween.PERSIST }); }
Beta Was this translation helpful? Give feedback.
All reactions