LoginSignup
0
0

More than 5 years have passed since last update.

cocosStudio2.0.2で作成したアニメーションがcocos2d-js ver3.1で動かない問題

Last updated at Posted at 2014-12-19

大いにはまった。
普通に動かない。

今回は、sceneの中に、node(csdファイルをインポート)を組み込んだ場合、
再生できない問題ではまりました。

cocosStudioのプロジェクト構成はこんな感じ。

scene.csd
chara.csd

で、scene.csdにchara.csdをnodeとして組み込んで、タイムラインでぐるぐる動かしている感じです。

基本、cocosStudio2.0.2で作成したcsbは以下のように再生します。


var node = ccs.csLoader.createNode("scene.csb");
var action = ccs.actionTimelineCache.createAction("scene.csb");

node.runAction(action);
action.gotoFrameAndPlay(0, false);

var node = ccs.csLoader.createNode(file);で落ちる。

調べてみたら、createNodeが、"scene.csb"の解析時に、
"chara.csb"も自動で解析してインスタンス化してくれている部分に問題があった。
しかも2つw

具体的には、ccs.csLoader.nodeFromProtocolBuffers関数の中の
以下の部分。


 else if (classname == "ProjectNode")
    {
      var nodeOptions = nodetree["widgetOptions"];
      var options = nodetree["projectNodeOptions"];

      // 1個目。
      //var filePath = options.filename();
      var filePath = options.fileName;
      //cc.log("filePath = %s", filePath);
      if(filePath != "")
      {
        node = this.createNodeFromProtocolBuffers(this._protocolBuffersPath + filePath);
        this.setPropsForProjectNodeFromProtocolBuffers(node, options, nodeOptions);

     // 2個目。
        var action = ccs.ActionTimelineCache.createActionFromProtocolBuffers(this._protocolBuffersPath + filePath);
        if(action)
        {
          node.runAction(action);
          action.gotoFrameAndPlay(0);
        }
      }

1個目

まず1個目から。

var filePath = options.filename();

optionsに、filename()なんてないじゃん!!!
ということで、


 var filePath = options.fileName;

書き換えました。

2個目

ccs.ActionTimelineCacheなんてないじゃん!!
ccs.actionTimelineCacheはあるけど。

なので、cocos2d-jsのフレームワークを読み込んだ時点で、

ccs.ActionTimelineCache = ccs.actionTimelineCache;

やって、注入してやることにしました。

まとめ

ふう。アニメーション1つ再生するのも大変だ。

以上。

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