如何让我的角色在 Actionscript 3.0 中沿对角线移动
我无法使用箭头键使我的人物沿对角线移动。我可以让它向上、向下、向左、向右移动,但我不确定如何让它读取两个按钮同时按下,因此它应该以某种方式移动。这是迄今为止我所拥有的按键代码。任何提示表示赞赏!
function keyPressHandler(event:KeyboardEvent):void
{
switch( event.keyCode )
{
case Keyboard.UP:
up = true;
beetle_mc.rotation = 0;
beetle_mc.y -=speed;
up_mc.gotoAndStop(2);
break;
case Keyboard.DOWN:
down = true;
beetle_mc.rotation = 180;
beetle_mc.y +=speed;
down_mc.gotoAndStop(2);
break;
case Keyboard.LEFT:
left = true;
beetle_mc.rotation = 270;
beetle_mc.x -=speed;
left_mc.gotoAndStop(2);
break;
case Keyboard.RIGHT:
right = true;
beetle_mc.rotation = 90;
beetle_mc.x +=speed;
right_mc.gotoAndStop(2);
break;
I'm having trouble making my figure move diagonally with the arrowkeys. I can make it so that it moves up, down, left and right but I'm unsure how to make it read that two buttons are pressed down at once and therefore it should move in a certain way. This it the code I have for the keypresses so far. Any tips are appreciated!
function keyPressHandler(event:KeyboardEvent):void
{
switch( event.keyCode )
{
case Keyboard.UP:
up = true;
beetle_mc.rotation = 0;
beetle_mc.y -=speed;
up_mc.gotoAndStop(2);
break;
case Keyboard.DOWN:
down = true;
beetle_mc.rotation = 180;
beetle_mc.y +=speed;
down_mc.gotoAndStop(2);
break;
case Keyboard.LEFT:
left = true;
beetle_mc.rotation = 270;
beetle_mc.x -=speed;
left_mc.gotoAndStop(2);
break;
case Keyboard.RIGHT:
right = true;
beetle_mc.rotation = 90;
beetle_mc.x +=speed;
right_mc.gotoAndStop(2);
break;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论