Need help with RotateBy action

Hi everyone -

I’ve been working on a small Asteroids game in CocosCreator 2.3 and ran into this unexpected behavior with the RotateBy action. I wanted to create a number of moving and rotating asteroids when the game is started in an “attract mode” … just keeping it simple at this point. The code looks like the following:

const {ccclass, property} = cc._decorator;
import {randomInt} from "./Util";
@ccclass
export default class CreateAsteroids extends cc.Component {

// LIFE-CYCLE CALLBACKS:

// onLoad () {}

start () {
    var asteroids = [];
    // load a cc.SpriteFrame with image path (Recommend)
    var self = this;
    // load the sprite frame starting from project/assets/resources folder
    cc.loader.loadRes('images/asteroids/large/a10000', cc.SpriteFrame, function (err, spriteFrame) {
        if (err) {
            cc.error(err.message || err);
            return;
        }
        let name = "Asteroid"; //+ i.toString();
        var asteroid = new cc.Node(name);
        var sprite = asteroid.addComponent(cc.Sprite); 
        sprite.spriteFrame = spriteFrame;
        asteroid.setPosition(randomInt(0, cc.winSize.width), randomInt(0, cc.winSize.height));
        cc.director.getScene().addChild(asteroid);
        asteroids.push(asteroid);
        var dx = randomInt(1, 100);
        var dy = randomInt(1, 100);
        var angle = randomInt(-360, 360);
        asteroid.runAction(cc.sequence(cc.spawn(cc.moveBy(3, dx, dy), cc.rotateBy(3, angle)),
                cc.delayTime(0.0)).repeatForever()); 
        });
    }
    // update (dt) {}
}

I attached this CreateAsteroids.ts script as a component on my Canvas, and it loads the asteroid begins to move and rotate it properly. However, at the end of the initial 3 seconds, it continues moving the asteroid with the original dx,dy vector but then the angle rotation reverses (i.e., if the sprite was moving clockwise intially, it then starts moving counterclockwise for 3 seconds, or vice versa). Then a cycle of clockwise and counterclockwise rotations begins, although the moveTo vector continues in the same direction.


This doesn’t seem like the expected behavior … in the documentation, it says that rotateBy should always move in the same direction, clockwise if the angle is positive and counterclockwise if it’s negative. I’m not changing the angle value anywhere. Am I thinking about this correctly? Is this a bug in the rotateBy action?

1 Like

seems that 2.3 rotateBy behavior is different, because your code is working fine in 2.0.10 and 2.2.2 versions though :slight_smile:

give gsap a try too - gsap - npm - until a fix is available.

Ok, cool. I hate to redo the project in 2.2 but at least I have a way forward since this seems to be a bug.