首页 > 解决方案 > 在javascript中落在另一个对象上后旋转的对象

问题描述

当物体落在斜坡上时,如何利用重力旋转物体。

例如。这是我想要发生的事情:

在此处输入图像描述

这是我的代码:

            this.box_speed++;

            if(this.box_speed > 0){
            //check ground
            for (i = 0; i < this.box_speed; i++) {
                if(!this.terrain_bmp.hitTest(new Rectangle(this.box.x,this.box.y + 20,10,1))){
                    this.box.y += 1;
                }else{
                    this.box_speed = 0;
                }
            }
        }else{
            for (i = 0; i < Math.abs(this.box_speed); i++) {
                if(!this.terrain_bmp.hitTest(new Rectangle(this.box.x,this.box.y,10,1))){
                    this.box.y -= 1;
                }
                else{
                    this.box_speed = 0;
                }
            }
        }

标签: javascriptcanvas

解决方案


推荐阅读