3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

enchant.jsでいうenterFrameをcocos2d-html5でやる

Last updated at Posted at 2014-02-20

enchant.jsの場合、あるオブジェクトに何らかのアクションを毎フレーム実行させたい場合はこんなふうに書く。

enchant.js
bear.onenterframe = function() {
    // 毎フレーム実行したい処理を書く
};

cocos2d-html5ではthis.scheduleUpdate()とupdate()の組み合わせで実現できる。

cocos2d-html5
cc.Node.extend({
   ctor: function() {
      this._super();
      this.scheduleUpdate(); // 毎フレームごとにupdate()を実行してねって宣言する
   },

   /** @override */
   update: function() {
      // 毎フレーム実行したい処理を書く
   }
});

なお、このクラスがsceneなりspriteなりにaddChild()されていないとupdate()を呼んでくれないので注意。(これが言いたかっただけ)

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?