使Sprite朝向旋转到鼠标点击方向

var mySprite = new cc.Sprite(res.paotai_png);
mySprite.setPosition(cc.winSize.width>>1,100);
this.addChild(mySprite);
var that = this;
var listener = cc.EventListener.create({
    event:cc.EventListener.TOUCH_ONE_BY_ONE,
    swallowTouches: true,
    onTouchBegan: function (touch, event) {
        var locationInNode = touch.getLocation();
        var o = locationInNode.x - mySprite.x;
        var a = locationInNode.y - mySprite.y;
        var at = Math.atan(o / a) * 180 / Math.PI;
        if (a < 0) {
            if (o < 0){
                at = 180 + Math.abs(at);
            }else{
                at = 180 - Math.abs(at);
            }
        }
        //at -= 90;                           //横板设置
        var rotate = cc.rotateTo(0.2, at);   //缓动
        mySprite.runAction(rotate)
    }
});
cc.eventManager.addListener(listener, this);

你可能感兴趣的:(使Sprite朝向旋转到鼠标点击方向)