LoginSignup
0
0

More than 5 years have passed since last update.

cocos2d-js のアニメーションを動かす / 反転させる

Posted at

まぁ出来るだろうと思って試した。
cc.RepeatForever でアニメーションさせておきつつ MoveBy で動かせる。
cc.Spawn で同時に動かしたりしなくていいのかな、と思ったんだけどこれでいけた。

var animation = cc.AnimationCache.getInstance().getAnimation('animation_name');
animation.setRestoreOriginalFrame(true);
var animation_sprite = cc.Sprite.create( image_path, cc.rect(0, 0, width, height) );
animation_sprite.setPosition(220, 240);
layer.addChild(anime_sprite, 300);

animation_sprite.runAction( cc.RepeatForever.create( cc.Animate.create(animation)) );
animation_sprite.runAction( cc.MoveBy.create(10, cc.p(200,100) ) );

反転は setScale に負の値を指定したらできた。これはアニメーションじゃなくてもそういう挙動になるってことだね。

var animation_sprite2 = cc.Sprite.create( image_path, cc.rect(0, 0, width, height) );
animation_sprite2.setPosition(420, 240);
animation_sprite2.setScale(-1);
this.addChild(animation_sprite2, 300);

animation_sprite2.runAction( cc.RepeatForever.create( cc.Animate.create(animation)) );
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0