//随机 旋转
for(var i= 0;i<100;i++){
var Sp = new cc.Sprite("res/图片");
this.addChild(Sp);
var X=parseInt(Math.random()*cc.winSize.width);
var Y=parseInt(Math.random()*cc.winSize.height);
var moveTo = cc.moveTo(2, cc.p(X, Y));
var rotateBy=cc.rotateBy(2,360);
//var moveBy = cc.moveBy(2, cc.p(-cc.winSize.width >> 1,0));
Sp.runAction(cc.sequence(moveTo,rotateBy));
}
//移动
var mySprite = new cc.Sprite("图片");
this.addChild(mySprite);
var moveTo=cc.moveTo(2,cc.p(50.0));
mySprite.runAction(moveTo);
var moveBy=cc.moveTo(2,cc.p(50.0));
mySprite.runAction(moveBy);
//鼠标点击
var Sp = new cc.Sprite("res/图片");
this.addChild(Sp);
Sp.setPosition(cc.winSize.width>>1,cc.winSize.height>>1);
that=this;
var listener = cc.EventListener.create({
event:cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches:true,
onTouchBegan:function(touch,event){
var po = touch.getLocation();
var centerPoint = cc.p(cc.winSize.width>>1,cc.winSize.height>>1);
cc.log(po);
var o = po.x-Sp.x;
var a = po.y-Sp.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);
}
var rotateBy=cc.rotateTo(2,at);
Sp.runAction(rotateBy)
}
});
cc.eventManager.addListener(listener,this);