/**
* Created by Administrator on 2017/4/21.
*/
var s_resprefix = "";
var BasicLayer = cc.Layer.exteBnd({
ctor: function () {
this._super();
var winSize = cc.winSize;
/**********************LabelAtlas1***********************/
//数字标签
var label1 = new cc.LabelAtlas("123 Test", s_resprefix + "fonts/tuffy_bold_italic-charmap.plist");
this.addChild(label1, 0);
label1.anchorX = 0.5;
label1.anchorY = 0.5;
label1.x = 10;
label1.y = 100;
label1.opacity = 200;
/**********************LabelAtlas2***********************/
var label2 = new cc.LabelAtlas("0123456789", s_resprefix + "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
this.addChild(label2, 0);
label2.x = 10;
label2.y = 200;
//label2.color = cc.color(255, 0, 0);
/**********************LabelBMFont***********************/
var label1 = new cc.LabelBMFont("Test", s_resprefix + "fonts/bitmapFontTest2.fnt");
label1.anchorX = 0;
label1.anchorY = 0;
//label1.textAlign = cc.TEXT_ALIGNMENT_LEFT;//只有水平对齐 label1.setAlignment(cc.TEXT_ALIGNMENT_LEFT);
//label1.boundingWidth = 400;//边界宽度
label1.color = cc.color.RED;
this.addChild(label1, 0);
/**********************LabelTTF***********************/
this._label = new cc.LabelTTF("123456", "Arial", 32, cc.size(200, 160), cc.TEXT_ALIGNMENT_LEFT, cc.VERTICAL_TEXT_ALIGNMENT_TOP);
this._label.anchorX = 0;
this._label.anchorY = 0;
this._label.setString("123");
var str = this._label.getString();
//this._label.setDimensions(s.width / 2, 200);
//this._label.setVerticalAlignment(cc.VERTICAL_TEXT_ALIGNMENT_TOP);
//this._label.setHorizontalAlignment(cc.TEXT_ALIGNMENT_LEFT)
this._label.x = (s.width) / 2;
this._label.y = (s.height) / 2;
this.addChild(this._label);
/**********************DrawNode***********************/
var drawNode = new cc.DrawNode();
this.addChild(drawNode);
drawNode.setDrawColor(cc.color(255,0,0,128));
drawNode.drawSegment(cc.p(0, s.height / 2), cc.p(s.width, s.height / 2), 2);
drawNode.drawSegment(cc.p(s.width / 2, 0), cc.p(s.width / 2, s.height), 2);
/**********************LayerColor***********************/
var layer = new cc.LayerColor(cc.color(255, 0, 0, 128));
layer.ignoreAnchor = false;//等价于layer.ignoreAnchorPointForPosition(true);如果设置为true,就表示锚点默认0,0 不能更改,如果设置为false,就表示锚点可以更改,设置就行了
layer.anchorX = 0.5;
layer.anchorY = 0.5;
layer.setContentSize(200, 200);
layer.x = s.width / 2;
layer.y = s.height / 2;
this.addChild(layer, 1);
/**********************MenuItemSprite、MenuItemImage、MenuItemItemLabel、MenuItemFont***********************/
var s_menuItem = "Images/menuitemsprite.png";
//MenuItemSprite
var spriteNormal = new cc.Sprite(s_menuItem, cc.rect(0,23*2,115,23));
var spriteSelected = new cc.Sprite(s_menuItem, cc.rect(0,23,115,23));
var spriteDisabled = new cc.Sprite(s_menuItem, cc.rect(0,0,115,23));
var item1 = new cc.MenuItemSprite(spriteNormal, spriteSelected, spriteDisabled, this.onMenuCallback, this);
//或者
//var item1 = new cc.MenuItemSprite(spriteNormal, spriteSelected, spriteDisabled, function(){
// this.parent.switchTo(1);
//}.bind(this));
//MenuItemImage
var sendScoreSF = new cc.SpriteFrame(s_menuItem, cc.rect(0, 0, 145, 26));
cc.spriteFrameCache.addSpriteFrame(sendScoreSF, "send_score_sf");
var item2 = new cc.MenuItemImage("#send_score_sf", s_menuItem, this.onMenuCallback2, this);
//或者
var item2 = new cc.MenuItemImage("#send_score_sf", s_menuItem, function () {
console.log("123");
}, this);
//MenuItemLabel
var labelAtlas = new cc.LabelAtlas("0123456789", s_menuItem, 12, 32, '.');
var item3 = new cc.MenuItemLabel(labelAtlas, this.onMenuCallbackDisabled, this );
item3.scaleX = 0.5;
item3.setDisabledColor( cc.color(32,32,64) );
item3.color = cc.color(200,200,255);
cc.log("test MenuItemLabel getString()" + item3.getString());
//MenuItemFont
var item4 = new cc.MenuItemFont("I toggle enable items", function(sender) {
console.log("MenuItemFont");
}, this);
var item5 = new cc.MenuItemFont("Quit", this.onQuit, this);
//Menu
var menu = new cc.Menu( item1, item2, item3, item4, item5);
menu.tag = 1;
menu.alignItemsVertically();
this.addChild(menu);
menu.x = winSize.width/2;
menu.y = winSize.height/2;
/**********************MenuItemToggle***********************/
//0N/0FF
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title1 = new cc.MenuItemFont("Sound");
title1.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item1 = new cc.MenuItemToggle(
new cc.MenuItemFont("On"),
new cc.MenuItemFont("Off"));
item1.setCallback(this.onMenuCallback,this);
//0ff/0N
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title2 = new cc.MenuItemFont("Music");
title2.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item2 = new cc.MenuItemToggle(
new cc.MenuItemFont("Off"),
new cc.MenuItemFont("On"),
this.onMenuCallback.bind(this)
);
//High/Low
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title3 = new cc.MenuItemFont("Quality");
title3.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item3 = new cc.MenuItemToggle(
new cc.MenuItemFont("High"),
new cc.MenuItemFont("Low"),
this.onMenuCallback, this
);
//Off/33%/66%/100%
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title4 = new cc.MenuItemFont("Orientation");
title4.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item4 = new cc.MenuItemToggle(
new cc.MenuItemFont("Off"),
new cc.MenuItemFont("33%"),
new cc.MenuItemFont("66%"),
new cc.MenuItemFont("100%"),
this.onMenuCallback, this
);
item4.setSelectedIndex(2);
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var label = new cc.LabelBMFont("go back", s_bitmapFontTest3_fnt);
var back = new cc.MenuItemLabel(label, this.onBackCallback, this);
var menu = new cc.Menu(
title1, title2,
item1, item2,
title3, title4,
item3, item4,
back);
menu.alignItemsInColumns(2, 2, 2, 2, 1);
this.addChild(menu);
var winSize = cc.director.getWinSize();
menu.x = winSize.width / 2;
menu.y = winSize.height / 2;
/**********************Sprite1***************************/
var sprite = new cc.Sprite("Images/grossini_dance_atlas.png", cc.rect(0, 0, 85, 121));
sprite.setColor(cc.color(255,200,10));
sprite.setTextureRect(cc.rect(0,0,200,200));
this.addChild(sprite, 999);
sprite.x = winSize.width / 2;
sprite.y = winSize.height / 2;
//或者
sprite.attr({
x: winSize.width / 2,
y: winSize.height / 2,
anchorX: 0.5,
anchorY: 0.5,
scale: 0.5,
rotation: 180
});
/**********************Sprite2***********************/
//spriteFrameCache添加精灵帧文件
cc.spriteFrameCache.addSpriteFrames(res.plist);//plist文件必须放到resource文件里
var ball = new cc.Sprite("#1.png");//或者使用cc.spriteFrameCache.getSpriteFrame("father.gif")代替也可以注意这里不用加#,相当于#代替了cc.spriteFrameCache.getSpriteFrame
this.addChild(ball, 1);
ball.x = size.width/2;
ball.y = size.height/2;
/**********************Sprite3 ***************************/
//通过纹理创建
var texture = cc.textureCache.addImage(res.HelloWorld_png);
var node = new cc.Sprite(texture);
this.addChild(node);
return true;
},
onMenuCallback:function (sender) {
this.parent.switchTo(1);
},
onMenuCallback2:function (sender) {
this.parent.switchTo(2);
},
onMenuCallbackDisabled:function (sender) {
// hijack all touch events for 5 seconds
cc.eventManager.setPriority(this._touchListener, -1);
this.schedule(this.onAllowTouches, 5.0);
cc.log("TOUCHES DISABLED FOR 5 SECONDS");
},
onExit: function() {
this._super();
cc.eventManager.removeListener(this._touchListener);
},
onQuit:function (sender) {
cc.log("Quit called");
},
onAllowTouches:function (dt) {
cc.eventManager.setPriority(this._touchListener, 1);
this.unscheduleAllCallbacks();
cc.log("TOUCHES ALLOWED AGAIN");
},
onMenuCallback:function (sender) {
cc.log("Callback called");
},
onBackCallback:function (sender) {
this.parent.switchTo(0);
}
});
* Created by Administrator on 2017/4/21.
*/
var s_resprefix = "";
var BasicLayer = cc.Layer.exteBnd({
ctor: function () {
this._super();
var winSize = cc.winSize;
/**********************LabelAtlas1***********************/
//数字标签
var label1 = new cc.LabelAtlas("123 Test", s_resprefix + "fonts/tuffy_bold_italic-charmap.plist");
this.addChild(label1, 0);
label1.anchorX = 0.5;
label1.anchorY = 0.5;
label1.x = 10;
label1.y = 100;
label1.opacity = 200;
/**********************LabelAtlas2***********************/
var label2 = new cc.LabelAtlas("0123456789", s_resprefix + "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
this.addChild(label2, 0);
label2.x = 10;
label2.y = 200;
//label2.color = cc.color(255, 0, 0);
/**********************LabelBMFont***********************/
var label1 = new cc.LabelBMFont("Test", s_resprefix + "fonts/bitmapFontTest2.fnt");
label1.anchorX = 0;
label1.anchorY = 0;
//label1.textAlign = cc.TEXT_ALIGNMENT_LEFT;//只有水平对齐 label1.setAlignment(cc.TEXT_ALIGNMENT_LEFT);
//label1.boundingWidth = 400;//边界宽度
label1.color = cc.color.RED;
this.addChild(label1, 0);
/**********************LabelTTF***********************/
this._label = new cc.LabelTTF("123456", "Arial", 32, cc.size(200, 160), cc.TEXT_ALIGNMENT_LEFT, cc.VERTICAL_TEXT_ALIGNMENT_TOP);
this._label.anchorX = 0;
this._label.anchorY = 0;
this._label.setString("123");
var str = this._label.getString();
//this._label.setDimensions(s.width / 2, 200);
//this._label.setVerticalAlignment(cc.VERTICAL_TEXT_ALIGNMENT_TOP);
//this._label.setHorizontalAlignment(cc.TEXT_ALIGNMENT_LEFT)
this._label.x = (s.width) / 2;
this._label.y = (s.height) / 2;
this.addChild(this._label);
/**********************DrawNode***********************/
var drawNode = new cc.DrawNode();
this.addChild(drawNode);
drawNode.setDrawColor(cc.color(255,0,0,128));
drawNode.drawSegment(cc.p(0, s.height / 2), cc.p(s.width, s.height / 2), 2);
drawNode.drawSegment(cc.p(s.width / 2, 0), cc.p(s.width / 2, s.height), 2);
/**********************LayerColor***********************/
var layer = new cc.LayerColor(cc.color(255, 0, 0, 128));
layer.ignoreAnchor = false;//等价于layer.ignoreAnchorPointForPosition(true);如果设置为true,就表示锚点默认0,0 不能更改,如果设置为false,就表示锚点可以更改,设置就行了
layer.anchorX = 0.5;
layer.anchorY = 0.5;
layer.setContentSize(200, 200);
layer.x = s.width / 2;
layer.y = s.height / 2;
this.addChild(layer, 1);
/**********************MenuItemSprite、MenuItemImage、MenuItemItemLabel、MenuItemFont***********************/
var s_menuItem = "Images/menuitemsprite.png";
//MenuItemSprite
var spriteNormal = new cc.Sprite(s_menuItem, cc.rect(0,23*2,115,23));
var spriteSelected = new cc.Sprite(s_menuItem, cc.rect(0,23,115,23));
var spriteDisabled = new cc.Sprite(s_menuItem, cc.rect(0,0,115,23));
var item1 = new cc.MenuItemSprite(spriteNormal, spriteSelected, spriteDisabled, this.onMenuCallback, this);
//或者
//var item1 = new cc.MenuItemSprite(spriteNormal, spriteSelected, spriteDisabled, function(){
// this.parent.switchTo(1);
//}.bind(this));
//MenuItemImage
var sendScoreSF = new cc.SpriteFrame(s_menuItem, cc.rect(0, 0, 145, 26));
cc.spriteFrameCache.addSpriteFrame(sendScoreSF, "send_score_sf");
var item2 = new cc.MenuItemImage("#send_score_sf", s_menuItem, this.onMenuCallback2, this);
//或者
var item2 = new cc.MenuItemImage("#send_score_sf", s_menuItem, function () {
console.log("123");
}, this);
//MenuItemLabel
var labelAtlas = new cc.LabelAtlas("0123456789", s_menuItem, 12, 32, '.');
var item3 = new cc.MenuItemLabel(labelAtlas, this.onMenuCallbackDisabled, this );
item3.scaleX = 0.5;
item3.setDisabledColor( cc.color(32,32,64) );
item3.color = cc.color(200,200,255);
cc.log("test MenuItemLabel getString()" + item3.getString());
//MenuItemFont
var item4 = new cc.MenuItemFont("I toggle enable items", function(sender) {
console.log("MenuItemFont");
}, this);
var item5 = new cc.MenuItemFont("Quit", this.onQuit, this);
//Menu
var menu = new cc.Menu( item1, item2, item3, item4, item5);
menu.tag = 1;
menu.alignItemsVertically();
this.addChild(menu);
menu.x = winSize.width/2;
menu.y = winSize.height/2;
/**********************MenuItemToggle***********************/
//0N/0FF
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title1 = new cc.MenuItemFont("Sound");
title1.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item1 = new cc.MenuItemToggle(
new cc.MenuItemFont("On"),
new cc.MenuItemFont("Off"));
item1.setCallback(this.onMenuCallback,this);
//0ff/0N
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title2 = new cc.MenuItemFont("Music");
title2.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item2 = new cc.MenuItemToggle(
new cc.MenuItemFont("Off"),
new cc.MenuItemFont("On"),
this.onMenuCallback.bind(this)
);
//High/Low
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title3 = new cc.MenuItemFont("Quality");
title3.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item3 = new cc.MenuItemToggle(
new cc.MenuItemFont("High"),
new cc.MenuItemFont("Low"),
this.onMenuCallback, this
);
//Off/33%/66%/100%
cc.MenuItemFont.setFontName("American Typewriter");
cc.MenuItemFont.setFontSize(18);
var title4 = new cc.MenuItemFont("Orientation");
title4.enabled = false;
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var item4 = new cc.MenuItemToggle(
new cc.MenuItemFont("Off"),
new cc.MenuItemFont("33%"),
new cc.MenuItemFont("66%"),
new cc.MenuItemFont("100%"),
this.onMenuCallback, this
);
item4.setSelectedIndex(2);
cc.MenuItemFont.setFontName("Marker Felt");
cc.MenuItemFont.setFontSize(34);
var label = new cc.LabelBMFont("go back", s_bitmapFontTest3_fnt);
var back = new cc.MenuItemLabel(label, this.onBackCallback, this);
var menu = new cc.Menu(
title1, title2,
item1, item2,
title3, title4,
item3, item4,
back);
menu.alignItemsInColumns(2, 2, 2, 2, 1);
this.addChild(menu);
var winSize = cc.director.getWinSize();
menu.x = winSize.width / 2;
menu.y = winSize.height / 2;
/**********************Sprite1***************************/
var sprite = new cc.Sprite("Images/grossini_dance_atlas.png", cc.rect(0, 0, 85, 121));
sprite.setColor(cc.color(255,200,10));
sprite.setTextureRect(cc.rect(0,0,200,200));
this.addChild(sprite, 999);
sprite.x = winSize.width / 2;
sprite.y = winSize.height / 2;
//或者
sprite.attr({
x: winSize.width / 2,
y: winSize.height / 2,
anchorX: 0.5,
anchorY: 0.5,
scale: 0.5,
rotation: 180
});
/**********************Sprite2***********************/
//spriteFrameCache添加精灵帧文件
cc.spriteFrameCache.addSpriteFrames(res.plist);//plist文件必须放到resource文件里
var ball = new cc.Sprite("#1.png");//或者使用cc.spriteFrameCache.getSpriteFrame("father.gif")代替也可以注意这里不用加#,相当于#代替了cc.spriteFrameCache.getSpriteFrame
this.addChild(ball, 1);
ball.x = size.width/2;
ball.y = size.height/2;
/**********************Sprite3 ***************************/
//通过纹理创建
var texture = cc.textureCache.addImage(res.HelloWorld_png);
var node = new cc.Sprite(texture);
this.addChild(node);
return true;
},
onMenuCallback:function (sender) {
this.parent.switchTo(1);
},
onMenuCallback2:function (sender) {
this.parent.switchTo(2);
},
onMenuCallbackDisabled:function (sender) {
// hijack all touch events for 5 seconds
cc.eventManager.setPriority(this._touchListener, -1);
this.schedule(this.onAllowTouches, 5.0);
cc.log("TOUCHES DISABLED FOR 5 SECONDS");
},
onExit: function() {
this._super();
cc.eventManager.removeListener(this._touchListener);
},
onQuit:function (sender) {
cc.log("Quit called");
},
onAllowTouches:function (dt) {
cc.eventManager.setPriority(this._touchListener, 1);
this.unscheduleAllCallbacks();
cc.log("TOUCHES ALLOWED AGAIN");
},
onMenuCallback:function (sender) {
cc.log("Callback called");
},
onBackCallback:function (sender) {
this.parent.switchTo(0);
}
});