been working on only the main character to work however character moves but does not stop must fix this code
function onKeyPressed(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.RIGHT)
{
isRightPressed = true;
}
if(event.keyCode == Keyboard.LEFT)
{
isLeftPressed = true;
}
if(event.keyCode == Keyboard.SPACE)
{
isSpacePressed = true;
}
}
function onKeyReleased(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.LEFT)
{
isLeftPressed = false;
}
if(event.keyCode == Keyboard.RIGHT)
{
isRightPressed = false;
}
if(event.keyCode == Keyboard.SPACE)
{
isSpacePressed = false;
}
}
function moveAgent():void
{
if(isLeftPressed == true)
{
agent_mc.x -= AGENT_SPEED;
agentRun_mc.x = agent_mc.x;
agentRun_mc.y = agent_mc.y;
agentRun_mc.scaleX = .3;
agentRun_mc.scaleY = .3;
removeChild(agent_mc);
addChild(agentRun_mc);
}
if(isRightPressed == true)
{
agent_mc.x += AGENT_SPEED;
agentRun_mc.x = agent_mc.x;
agentRun_mc.y = agent_mc.y;
agentRun_mc.scaleX = .3;
agentRun_mc.scaleY = .3;
removeChild(agent_mc);
addChild(agentRun_mc);
}
if(isSpacePressed == true)
{
agentAttack_mc.x = agent_mc.x;
agentAttack_mc.y = agent_mc.y;
agentAttack_mc.scaleX = .3;
agentAttack_mc.scaleY = .3;
removeChild(agent_mc);
addChild(agentAttack_mc);
}
}
function stopAgent():void
{
if(isLeftReleased == true)
{
removeChild(agentRun_mc);
addChild(agent_mc);
}
if(isRightReleased == true)
{
removeChild(agentRun_mc);
addChild(agent_mc);
}
if(isSpaceReleased == true)
{
removeChild(agentAttack_mc);
addChild(agent_mc);
}
}
No comments:
Post a Comment