Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17076

Child already added. It can't be added again

$
0
0

@Fran wrote:

The code at the end of this post is throwing the error "child already added. It can't be added again" all the time.

From the stack, it seems the problem arises on this line:

var menuItemPlay = new cc.MenuItemLabel("Play", this.onPlay, this);

I am creating such label there and, obviously, I haven't added it myself nowhere before that code.

Any ideas? Thanks a lot in advance.

var MenuLayer = cc.Layer.extend({
	ctor : function() {
		this._super();
	},
	init : function() {
		this._super();
		var winsize = cc.director.getWinSize();
		var centerpos = cc.p(winsize.width / 2, winsize.height / 2);
		var spritebg = new cc.Sprite(res.general_bkg);
		spritebg.setPosition(centerpos);
		this.addChild(spritebg);
		cc.MenuItemFont.setFontSize(60);
		var menuItemPlay = new cc.MenuItemLabel("Play", this.onPlay, this);
		var menu = new cc.Menu(menuItemPlay);
		menu.setPosition(centerpos);
		this.addChild(menu);
	},

	onPlay : function() {
		cc.log("==onplay clicked");
	}
});

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17076

Trending Articles