4
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.

【メモ・超初心者向け】CocosCreatorでPrefabを動的に生成する

Posted at

CocosCreatorを検証する機会があったのですがあまりにも記事が少ないので、自分用メモとして残します。

CocosCreatorで動的にPrefabを生成する方法を調べました。
超初心者向けの内容です。

cc.Class({
    extends: cc.Component,

    properties: {
        itemPrefab: {
            default: null,
            type: cc.Prefab
        },
    },

    // use this for initialization
    onLoad: function () { 
        // 新しいノードを生成
        var item = cc.instantiate(this.itemPrefab);
        // 新しく追加したノードを『Canvas』ノードの下に置く
        this.node.addChild(item);
    },
});

以上です。
注:Cocos Creator ver1.1.0で検証。今後やり方が変わる可能性が極めて高いです。

4
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
4
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?