I've implemented some seemingly basic tweens for a side-scrolling platformer in haxe using flixel.tweens.FlxTween. For example:
public static function lunge(sprite: FlxSprite) {
var deltax:Int = sprite.facing==FlxObject.LEFT?-50:50;
return FlxTween.tween(sprite, { x:sprite.x+deltax,y:sprite.y-10 }, 0.10, { type: FlxTween.ONESHOT } );
}
This works as expected -- the sprite lunges forward 50px and up 10px. However, the sprite will happily and indescriminately lunge through my tilemap and other sprites, ignoring collisions which all work normally outside tweens. I attempted tweening on the velocity:
public static function lungeV(sprite: FlxSprite) {
var newVelocity:FlxPoint = new FlxPoint(sprite.velocity.x*3, -40);
return FlxTween.tween(sprite, { velocity: newVelocity }, 0.10, { type: FlxTween.ONESHOT } );
}
This compiles and runs, but I get an "Unsupported Operation" when the function is called (the stack trace only refers to haxe/haxeflixel code, not to my own):
Unsupported operation
Called from flixel.tweens.misc.VarTween::initializeVars line 120
Called from flixel.tweens.misc.VarTween::update line 78
Called from flixel.plugin.TweenManager::update line 31
Called from flixel.FlxGame::update line 698
Called from flixel.FlxGame::step line 648
Called from flixel.FlxGame::onEnterFrame line 493
Called from openfl._legacy.events.EventDispatcher::dispatchEvent line 98
Called from a C function
Called from openfl._legacy.display.DisplayObject::__broadcast line 161
Called from a C function
Called from openfl._legacy.display.DisplayObjectContainer::__broadcast line 280
Called from openfl._legacy.display.Stage::__render line 1074
Called from openfl._legacy.display.Stage::__checkRender line 339
Called from openfl._legacy.display.Stage::__pollTimers line 1059
Called from openfl._legacy.display.Stage::__doProcessStageEvent line 414
Compilation failed.
I also tried using
{velocity.x: sprite.velocity.x * 3, ... }
but haxe doesn't like this:
Effects.hx:39: characters 36-37 : Missing ;
Effects.hx:39: characters 37-38 : Unexpected :
Effects.hx:39: characters 37-38 : Unexpected :
Compilation failed.
(Full path removed for clarity. Line 39 is the FlxTween call.)
Documentation outlining what specific properties can be tweened eludes me, as does the solution. I have implemented the same functionality without tweens, but, now I just have to know whether this is possible.
Try this:
FlxTween.tween(sprite.velocity, { x: newVelocity }, 0.10, { type: FlxTween.ONESHOT } );
I don't know if it's gonna work as you expect though: the tween will change the velocity over the course of the time - it won't move the sprite to a desired location. For moviment with collision the best route is to avoid FlxTweens since they ignore FlxCollision completely.
If you must use FlxTween for movement the ideal would be to roll your own collision detection.