keep the center of a sprite fixed while rotating

209 Views Asked by At

I'm using Cocos2d-js v3 to create a jackpot-spinner. When I'm rotating the spinner wheel sprite, it wobbles, as in it moves in x,y axis slightly too while rotataing. How can I keep the sprite fixed while rotating? I'm new to Cocos2d-js.

Here is my creating the sprite code -

sprite = new cc.Sprite.create(res.wheel_png);
sprite.setPosition(cc.p(size.width/2, size.height/2));
this.addChild(sprite, 0);

And rotation code -

var rand = Math.random();
var sprite_action = cc.RotateBy.create(2, 1370);
var repeat_action = cc.Repeat.create(sprite_action, rand);
sprite.runAction(repeat_action);
1

There are 1 best solutions below

0
dhrushit raval On

Create method is deprecated, as are some others. Check out this page for list of all things deprecated.

As per the cocos docs for v3, (look up "rotateby")

Field Detail <static> {cc.RotateBy} cc.RotateBy.create

Please use cc.rotateBy instead. Rotates a cc.Node object clockwise a number of degrees by modifying it's rotation attribute. Relative to its properties to modify. Deprecated:since v3.0

Please use cc.rotateBy instead.

You need to use it like this:

var rand = Math.random();
var sprite_action = cc.rotateBy(2, 1370);
var repeat_action = cc.repeat(sprite_action, rand);
sprite.runAction(repeat_action);