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); } });
相关推荐
5. 在解决方案中选择HelloWorld项目作为起点,这是Cocos2d-x提供的一个基础示例,可以快速看到游戏框架运行的效果。 6. 编译并运行HelloWorld项目,观察到基本的游戏框架运行在屏幕上,此时Cocos2d-x的入门学习已...
### Cocos2d-x初探学习笔记:HelloWorld详解 #### Cocos2d-x简介 Cocos2d-x是一款基于C++的开源游戏开发框架,它最初是从Cocos2d移植而来,支持跨平台的游戏开发,包括iOS、Android、Windows等多平台。Cocos2d-x因...
本文是关于如何使用Cocos2d-x开发一个基础的Hello World程序,并使用Visual Studio 2010和C++语言进行开发。由于Cocos2d-x通常不自带Visual Studio的插件,本文也介绍了如何安装并配置Cocos2d-x的VS插件。 首先,...
本篇学习笔记将深入解析Cocos2d-x的Hello World示例的源码,帮助初学者理解其基本结构和工作原理。 游戏开发的核心在于动态地呈现静态图像,就像电影通过连续播放静止画面来创造动态效果。Cocos2d-x中的游戏画面是...
### Cocos2d-x开发环境搭建 #### Cocos2d-x简介 Cocos2d-x是一款免费的游戏开发引擎,具有开源和跨平台的特性。它支持多种操作系统和编程语言,为开发者提供了一整套游戏开发的解决方案。随着智能手机的普及,移动...
在Cocos2d-x游戏引擎中,`CCLayerColor` 是一个非常基础且实用的类,它用于创建具有单一颜色背景的图层。本篇学习笔记将深入探讨 `CCLayerColor` 的使用实例,通过一个简单的 "Hello World" 示例来展示其基本功能。 ...
图层在cocos2d-x中很重要,我们可以在其中添加精灵,也可以将图层添加到场景中。这几个图层类功能各不相同,具体的看代码的注释。大家只需要替换掉helloworld中的init函数就可以运行了。 bool HelloWorld::init() ...
cocos2d-x的坐标系很重要,想要学好该引擎,深入理解它的坐标体系很重要。注释写的很清楚了,对照上运行结果一块来看代码吧! bool HelloWorld::init() { bool bRet = false; do { CC_BREAK_IF(! CCLayer::...
在示例代码中,`HelloWorld`继承自`CCLayer`,并调用了`addChild`方法将精灵(CCSprite)添加到层上。CCLayer的默认坐标和锚点与CCScene相同,也是(0.5, 0.5)。这意味着当你调整CCLayer的位置时,实际上是在移动层的...
Cocos2D研究院之构建游戏开发环境(一) Direct3D研究院之创建第一个DirectX3D项目(一) NGUI研究院之开始学习制作第一个例子(一) Objective-C研究院之基础语法(一) Ruby On Rails研究院之初识Rails(一) ...