I am looking for some easy way to create a popup with text and buttons.
I am able to find links for c++ but not for javascript.
I guess that I need to create a layer with high z index to show it to front of the screen…
I am looking for some easy way to create a popup with text and buttons.
I am able to find links for c++ but not for javascript.
I guess that I need to create a layer with high z index to show it to front of the screen…
I finally created it as I had been guessing, though there should be better ways of making this.
The popup shows some text and an OK button.
var Popup = cc.Layer.extend({
ctor:function() {
this._super();
cc.associateWithNative( this, cc.Layer );
},
init:function (cb, cb_parent) {
//////////////////////////////
// 1. super init first
this._super();
//navi enabling touch
if( 'touches' in sys.capabilities ) {
this.setTouchEnabled(true);
}
if( 'mouse' in sys.capabilities ) {
this.setMouseEnabled(true);
}
/////////////////////////////
var size = cc.Director.getInstance().getWinSize();
var centerPos = cc.p( size.width/2, size.height/2 );
var spriteBackground = cc.Sprite.create("res/bg/popup.png");
spriteBackground.setPosition(size.width/2, size.height/2);
this.addChild(spriteBackground, 0);
var label1 = cc.LabelTTF.create("Some text", "Arial", 32);
label1.setColor(cc.c3b(255, 255, 255));
label1.setPosition(size.width/2, size.height/2);
this.addChild(label1);
this.addMainMenu(cb, cb_parent);
return true;
},
addMainMenu: function(cb, cb_parent) {
var size = cc.Director.getInstance().getWinSize();
// add start button
var okItem = cc.MenuItemImage.create(
"res/buttons/ok.png",
"res/buttons/ok.png",
cb,
cb_parent);
okItem.setAnchorPoint(cc.p(0.5, 0.5));
okItem.setPosition(size.width/2, size.height * 1/4);
var menu = cc.Menu.create(okItem);
menu.setPosition(cc.p(0, 0));
this.addChild(menu, 1);
},
});
Screenshot attached
there no TouchPriority , < MenuTouchPriority