Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 90918

小白求教如何让重力感应只能上下左右四个方向走?

$
0
0

@758482981 写道:

想写一个依靠重力感应过关的RPG游戏,但是游戏人物有移动方向,不同移动的方向的动画也不同。求教如何实现。
GSensor:function(){
cc.inputManager.setAccelerometerEnabled(true);
var self = this
var listener1 = cc.EventListener.create({
event: cc.EventListener.ACCELERATION,
callback: function (accelEvent, event) {
this.speed.x = accelEvent.x
this.speed.y = accelEvent.y

          return true
        }.bind(self),
    });
    cc.eventManager.addListener(listener1, this.node);
},,这么写只会四面八方移动。应该也可以根据移动的方向算出旋转的方向。那请问下如何算呢?

帖子: 3

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 90918

Trending Articles