我使用 flixel.tweens.FlxTween 为 haxe 中的横向滚动平台游戏实现了一些看似基本的补间。例如:
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 } );
}
这按预期工作——精灵向前冲刺 50px 和向上 10px。然而,精灵会愉快地不加选择地冲过我的瓷砖地图和其他精灵,忽略所有在补间之外正常工作的碰撞。我尝试对速度进行补间:
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 } );
}
这可以编译并运行,但是在调用函数时我得到一个“不支持的操作”(堆栈跟踪仅指 haxe/haxeflixel 代码,而不是我自己的):
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.
我也尝试过使用
{velocity.x: sprite.velocity.x * 3, ... }
但haxe不喜欢这样:
Effects.hx:39: characters 36-37 : Missing ;
Effects.hx:39: characters 37-38 : Unexpected :
Effects.hx:39: characters 37-38 : Unexpected :
Compilation failed.
(为清楚起见,删除了完整路径。第 39 行是 FlxTween 调用。)
概述哪些特定属性可以补间的文档让我难以理解,解决方案也是如此。我已经实现了没有补间的相同功能,但是,现在我只需要知道这是否可能。