如何让我的角色在 Actionscript 3.0 中沿对角线移动

发布于 2025-01-14 02:03:24 字数 1111 浏览 2 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文