【发布时间】:2011-04-26 15:24:13
【问题描述】:
我正在 Actionscript 中创建一个简单的可控船,并让它前进,左转和右转,但无法让它转身。我希望船朝着它所指的方向前进。
function moveBoat(event:Event):void
{
if(rightKeyIsDown)
{
player_mc.x += speed;
player_mc.rotationZ += speed;
}
if(leftKeyIsDown)
{
player_mc.x -= speed;
player_mc.rotationZ -= speed;
}
if(upKeyIsDown)
{
player_mc.y -= speed;
}
}
提前感谢任何可以告诉我我做错了什么的人。
编辑:
function moveBoat(event:Event):void
{
if(rightKeyIsDown)
{
player_mc.rotationZ += turnFactor;
}
if(leftKeyIsDown)
{
player_mc.rotationZ -= turnFactor;
}
if(upKeyIsDown)
{
player_mc.x += speed * Math.cos(player_mc.rotationZ * Math.PI / 180);
player_mc.y -= speed * Math.sin(player_mc.rotationZ * Math.PI / 180);
}
}
编辑
function moveBoat(event:Event):void
{
if(rightKeyIsDown)
{
player_mc.rotation += turnFactor;
}
if(leftKeyIsDown)
{
player_mc.rotation -= turnFactor;
}
if( upKeyIsDown )
{
// convert our rotation to radians first
var rads:Number = player_mc.rotation * ( Math.PI / 180.0 );
player_mc.x += speed * Math.cos( rads );
player_mc.y += speed * Math.sin( rads );
}
}
【问题讨论】:
-
而不是
player_mc.y -= ...,设置player_mc.y += ...就可以了。就像我在回答中提到的那样......
标签: flash actionscript