对于每个角色皮肤,它有4个与每个可能方向(向上,向下,向左和向右)对应的MovieClip。
示例:
对于我的Player 1皮肤,就像这样。
玩家1动画(P1UAnim_mc)
玩家1向下动画(P1DAnim_mc)
玩家1左动画(P1LAnim_mc)
玩家1右动画(P1RAnim_mc)
现在,我的动作方式是我们有一个与动画大小相匹配的Movieclip(它们不会改变大小),而且这个Movieclip是不可见的,当我们告诉它时,这就是动作(我称之为球员位置守门员)。这是通过单击DPAD上的方向来完成的,然后我们在适当的方向上移动玩家,同时指向该方向的同步,然后我们检查是否在我的障碍物阵列中击中了某些东西。如果我们这样做了,我们会把玩家移回去。
所以现在我们已经完成了这项工作,我需要拥有与玩家正在使用/进入的方向和角色皮肤相对应的动画。
我有一个想法,每次进入一个框架时都有一个事件监听器,我们检查玩家正在使用的charSkin,然后检查方向,然后添加适当的动画。我们不需要更新动画x,y坐标,因为在它们的类文件中它总是将自身更新为玩家位置管理器坐标的x和y,并且知道何时移除它自己。所以我需要做的就是找到合适的时间来添加它并将剩下的部分留给动画类。
我尝试这种技术的问题是代码真的很难理解,这是一个if else语句检查上面提到的因素。
这是我的MovementReworked类,它不包含动画,所以你们实际上可以阅读它。如果你想让我编辑帖子并添加带有草率动画代码的Movement类,我会的,但它很不可读。
package
{
import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.TouchEvent;
import flash.net.dns.AAAARecord;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class MovementReworked extends MovieClip
{
public function MovementReworked(main:Game)
{
// I will be changing these addChilds in the future
// Just ignore it for now
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
addChild(Game.playerPosKeeper_mc);
Game.playerPosKeeper_mc.x = 384;
Game.playerPosKeeper_mc.y = 46;
addChild(main.up_dpad);
main.up_dpad.x = 55;
main.up_dpad.y = 336;
addChild(main.down_dpad);
main.down_dpad.x = 57;
main.down_dpad.y = 432;
addChild(main.left_dpad);
main.left_dpad.x = 19;
main.left_dpad.y = 372;
addChild(main.right_dpad);
main.right_dpad.x = 118;
main.right_dpad.y = 372;
addChild(main.menu_dpad);
main.menu_dpad.x = 61;
main.menu_dpad.y = 377;
addChild(main.run_dpad);
main.run_dpad.x = 684;
main.run_dpad.y = 369;
addChild(main.barrierRoof1_game);
main.barrierRoof1_game.x = 0;
main.barrierRoof1_game.y = 0;
addChild(main.barrierRoof2_game);
main.barrierRoof2_game.x = 0;
main.barrierRoof2_game.y = 470;
addChild(main.barrierRoof3_game);
main.barrierRoof3_game.x = 0;
main.barrierRoof3_game.y = 320;
addChild(main.barrierSide1_game);
main.barrierSide1_game.x = 0;
main.barrierSide1_game.y = 0;
addChild(main.barrierSide2_game);
main.barrierSide2_game.x = 790;
main.barrierSide2_game.y = 0;
// I will be changing these addChilds in the future
for each (var aButton:MovieClip in main.Buttons)
{
aButton.addEventListener(TouchEvent.TOUCH_BEGIN, onDown);
aButton.addEventListener(TouchEvent.TOUCH_OUT, onUp);
aButton.addEventListener(TouchEvent.TOUCH_END, onUp);
}
function onDown(e:TouchEvent):void
{
switch (e.currentTarget)
{
case main.up_dpad :
Game.dir = 1;
Game._Direction.x = 0;
Game._Direction.y = Game.upWalkspeed;
break;
case main.down_dpad :
Game.dir = 2;
Game._Direction.x = 0;
Game._Direction.y = Game.downWalkspeed;
break;
case main.left_dpad :
Game.dir = 3;
Game._Direction.x = Game.leftWalkspeed;
Game._Direction.y = 0;
break;
case main.right_dpad :
Game.dir = 4;
Game._Direction.x = Game.rightWalkspeed;
Game._Direction.y = 0;
break;
}
if (Game.idle)
{
Game.idle = false;
addEventListener(Event.ENTER_FRAME, onFrame);
}
}
function onFrame(e:Event):void
{
movePlayer(Game._Direction.x, Game._Direction.y);
}
function onUp(e:TouchEvent):void
{
Game.idle = true;
removeEventListener(Event.ENTER_FRAME, onFrame);
}
function movePlayer(movementX:Number, movementY:Number):void
{
var originalX:Number = Game.playerPosKeeper_mc.x;
var originalY:Number = Game.playerPosKeeper_mc.y;
Game.playerPosKeeper_mc.x += movementX;
if (checkCollision())
{
Game.playerPosKeeper_mc.x = originalX;
}
Game.playerPosKeeper_mc.y += movementY;
if (checkCollision())
{
Game.playerPosKeeper_mc.y = originalY;
}
}
function checkCollision():Boolean
{
for each (var StageCollisions:MovieClip in main.StageCollisions)
{
if (Game.playerPosKeeper_mc.hitTestObject(StageCollisions))
{
return true;
Game.idle = true;
}
}
return false;
}
}
}
}