[Cocos2dx-js learning sharing 4], cocos2dx-js sharing
Create a menu word
Var startScene = cc. scene. extend ({// determine whether the game has started is_Start: false, // create the constructor: function () {// initialize the constructor in the parent class this. _ super (); // write a laebl menu // var label = new cc. labelTTF ("Start", "Arial", 36); var _ labelMenu = new cc. menuItemFont ("Start", function () {//}, this); var _ winSize = cc. winSize; // set the coordinates of the menu elements (including the actual coordinates and the anchor) _ labelMenu. attr ({// object dictionary x: _ winSize. width/2, y: _ winSize. height/2, anchorX: 0.5, anchorY: 0.5}); // var _ menu = new cc. menu (_ labelMenu); _ menu. x = 0; _ menu. y = 0; this. addChild (_ menu, 2 );},});
Create a menu word element:
Var _ labelMenu = new cc. MenuItemFont ("Start", function () {}, this );
// Set his position in the menu (an attr () method must be called to include an object dictionary in the method)
_ LabelMenu. attr ({
X: _ winSize. width/2,
Y: _ winSize. height/2
// You can also default the anchor.
});
Finally, set the menu position;
Var _ menu = new cc. Menu (_ labelMenu );