cocos2d-html helloworld 노트
6559 단어 helloworld
cocos2d-html helloword 학습 노트
// :
/**cc.ScaleTo.create(duration, sx, sy)
duration
sx
sy
*/
var scaleToA = cc.ScaleTo.create(2, 1, 1);
/**
cc.sprite.runAction
cc.Sequence.create
*/
this.sprite.runAction(cc.Sequence.create(rotateToA, scaleToA));
/**
* cc.MoveBy.create(duration, deltaPosition)
* cc.TintTo.create(duration, red, green, blue)
*/
this.helloLabel.runAction(cc.Spawn.create(cc.MoveBy.create(2.5, cc.p(0, size.height - 40)),cc.TintTo.create(2.5,255,125,0)));
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
var Helloworld = cc.Layer.extend({
isMouseDown:false,
helloImg:null,
helloLabel:null,
circle:null,
sprite: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(
"res/CloseNormal.png",
"res/CloseSelected.png",
function () {
history.go(-1);
},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("Hello World", "Arial", 38);
// position the label on the center of the screen
this.helloLabel.setPosition(size.width / 2, 0);
// add the label as a child to this layer
this.addChild(this.helloLabel, 5);
var lazyLayer = cc.Layer.create();
this.addChild(lazyLayer);
// add "HelloWorld" splash screen"
this.sprite = cc.Sprite.create("res/HelloWorld.png");
this.sprite.setPosition(size.width / 2, size.height / 2);
//
this.sprite.setScale(0.5);
//
this.sprite.setRotation(180);
lazyLayer.addChild(this.sprite, 0);
//duration cc.RotateTo.create(duration, deltaAngleX, deltaAngleY)
//creates the action with separate rotation angles
var rotateToA = cc.RotateTo.create(2, 0);
/**cc.ScaleTo.create(duration, sx, sy)
duration
sx
sy
*/
var scaleToA = cc.ScaleTo.create(2, 1, 1);
/**
cc.sprite.runAction
cc.Sequence.create
*/
this.sprite.runAction(cc.Sequence.create(rotateToA, scaleToA));
/**
* cc.MoveBy.create(duration, deltaPosition)
* cc.TintTo.create(duration, red, green, blue)
*/
this.helloLabel.runAction(cc.Spawn.create(cc.MoveBy.create(2.5, cc.p(0, size.height - 40)),cc.TintTo.create(2.5,255,125,0)));
this.setTouchEnabled(true);
return true;
},
// a selector callback
menuCloseCallback:function (sender) {
cc.Director.getInstance().end();
},
onTouchesBegan:function (touches, event) {
this.isMouseDown = true;
},
onTouchesMoved:function (touches, event) {
if (this.isMouseDown) {
if (touches) {
//this.circle.setPosition(touches[0].getLocation().x, touches[0].getLocation().y);
}
}
},
onTouchesEnded:function (touches, event) {
this.isMouseDown = false;
},
onTouchesCancelled:function (touches, event) {
console.log("onTouchesCancelled");
}
});
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new Helloworld();
layer.init();
this.addChild(layer);
}
});
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
안녕, 세계! C 프로그램이번 포스팅에서는 Hello, World! 이해하기 쉬운 방식으로 C로 프로그래밍하십시오. Hello, World를 이해하기 위해! C로 프로그래밍하려면 다음 게시물에 대한 지식이 있어야 합니다. (해시) 포함 (해...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.