我的代码段如下:
var MyLayer = cc.Layer.extend({
isMouseDown:false,
helloImg:null,
helloLabel:null,
circle:null,
sprite: null,
sprite1:null,
init:function () {
//////////////////////////////
// 1. super init first
this._super();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// ask director the window size
var size = cc.Director.getInstance().getWinSize();
// add a "close" icon to exit the progress. it's an autorelease object
var closeItem = cc.MenuItemImage.create(
s_CloseNormal,
s_CloseSelected,
function () {
cc.log("close");
},this);
closeItem.setAnchorPoint(0.5, 0.5);
var menu = cc.Menu.create(closeItem);
menu.setPosition(0, 0);
this.addChild(menu, 1);
closeItem.setPosition(size.width - 20, 20);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
this.helloLabel = cc.LabelTTF.create("添加labelttf", "Impact", 38);
// position the label on the center of the screen
this.helloLabel.setPosition(size.width / 2, size.height - 40);
// add the label as a child to this layer
this.helloLabel.runAction(cc.MoveBy.create(2.5, cc.p(0, -140)));
this.addChild(this.helloLabel, 5);
// add "Helloworld" splash screen"
this.sprite = cc.Sprite.create(s_HelloWorld);
this.sprite.setAnchorPoint(0.5, 0.5);
this.sprite.setPosition(size.width / 2, size.height / 2);
this.sprite.setScale(size.height/this.sprite.getContentSize().height);
this.addChild(this.sprite, 0);
this.sprite1 = cc.Sprite.create("sun.png");
// this.sprite1.setAnchorPoint(0.5, 0.5);
this.sprite1.setPosition(cc.p(100, 100));
this.addChild(this.sprite1);
}
});
var MyScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new MyLayer();
this.addChild(layer);
layer.init();
}
});