1. 创建
this._streak = cc.MotionStreak.create(2, 3, 32, cc.color.GREEN, s_streak);
this.addChild(this._streak);
var winSize = cc.director.getWinSize();
// create the streak object and add it to the scene
this._streak = cc.MotionStreak.create(3, 3, 64, cc.color.WHITE, s_streak);
this.addChild(this._streak);
this._streak.x = winSize.width / 2;
this._streak.y = winSize.height / 2;
2. 加入action
var colorAction = cc.RepeatForever.create(cc.Sequence.create(
cc.TintTo.create(0.2, 255, 0, 0),
cc.TintTo.create(0.2, 0, 255, 0),
cc.TintTo.create(0.2, 0, 0, 255),
cc.TintTo.create(0.2, 0, 255, 255),
cc.TintTo.create(0.2, 255, 255, 0),
cc.TintTo.create(0.2, 255, 0, 255),
cc.TintTo.create(0.2, 255, 255, 255)));
this._streak.runAction(colorAction);
3.更新
onUpdate:function (delta) {
var pos = this._target.convertToWorldSpace(cc.p(this._target.width/2, 0));
this._streak.x = pos.x;
this._streak.y = pos.y;
},
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ALL_AT_ONCE,
onTouchesMoved:function (touches, event) {
if (touches.length == 0)
return;
var touch = touches[0];
var touchLocation = touch.getLocation();
var streak = event.getCurrentTarget()._streak;
streak.x = touchLocation.x;
streak.y = touchLocation.y;
}
}, this);
update:function (dt) {
this._angle += 1.0;
this._streak.x = this._center.x + Math.cos(this._angle / 180 * Math.PI) * this._radius;
this._streak.y = this._center.y + Math.sin(this._angle / 180 * Math.PI) * this._radius;
}