/*
让图片旋转到鼠标点击的位置
*/
// 创建一个Sprite,并将他显示在屏幕的中间
var mySprite = new cc.Sprite("res/B1.png") mySprite.setPosition(cc.winSize.width >> 1, cc.winSize.height >> 1) mySprite.setAnchorPoint(0,0.5) 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 = listener .x-mySprite.x var a = listener.y-mySprite.y cc.log(o,a) var at = Math.atan(o / a) * 180 / Math.PI cc.log(at) if (a < 0) { if (o < 0) at = 180 + Math.abs(at); else at = 180 - Math.abs(at); } at-= 90 cc.log(at) var rotate = cc.rotateTo(2,at) mySprite.runAction(rotate)
});
cc.eventManager.addListener(listener, this);