coco2d基本概念场景(Scenes)主控器(Director)层(Layers)精灵(Sprites)

开发cocos2d程序前有必要对一些基本概念进行介绍:

场景

负责游戏内容

场景(通过 CCScene 对象实现)是程序的工作流程中相对独立的部分。有些人可能喜欢称呼其为“屏幕”或“舞台”。你的应用程序可能具有许多场景,但在某刻只能有一个活动的场景。

例如,你的游戏中可能有下列场景:介绍,菜单,第一关,过场一,第二关,过场二,胜利过场,失败过场,高分记录等等。

你可以将每个场景定义成一个独立的程序; 你可以通过某种逻辑将这些场景联系起来(比如当介绍中断或者完成后,就进入菜单场景,第一关成功将进入过场一,而失败则进入失败过场,等等)。


prog_guide-scenes.png


CCScene 是由一个或者多个层(通过 CCLayer 对象实现)组成。场景的外观和行为是通过层来实现的。

CCScene 类家族中还包括一组称为“过渡” (通过 CCTransitionScene 对象实现),它允许你在两个场景之间进行生成一些特殊的过渡效果(比如淡入淡出,滑入效果等等)。

由于场景是 CCNode 的子类,因此可以使用“动作”对场景进行变换。


主控器

-----总控制 单列模式 只有一个

CCDirector 是一个负责控制场景变化的元件。

CCDirector 是一个单例对象。它知道当前哪个场景是活动的,它负责处理场景的控制,并允许进行“场景调用”之类的操作(比如在进入另一个场景时,暂停当前场景,并在适当时候返回原始场景)。在CCLayer 要求替换当前场景后,实际上是 CCDirector 进行的场景切换。

另外, CCDirector 还负责OpenGL ES的初始化。


UI界面

CCLayer 拥有整个可进行绘制的区域,并且知道怎样对自身进行绘制。它还可以是半透明的(还可以在某些地方部分或者完全透明),这样可以看到层后的部分。层是对外观和行为进行定义的元件,所以大部分时间我们都说针对 CCLayer 及子类进行编程的。

prog_guide-layers.png

CCLayer 还是进行事件处理的地方。事件是通过层进行传递直到某些层捕捉并进行处理。

尽管许多程序要求你定义自定义 CCLayer 类,但 cocos2d 提供了一些有用的预定义的层(比如简单的菜单层: CCMenu,颜色层: CCColorLayer, 其他层之间 的多路器:CCMultiplexLayer,等等)。

层还可以包括 CCSprite 对象, CCLabel 对象以及甚至是 CCLayer 对象。

由于层是 CCNode的子类,因此可以使用“动作”对场景进行变换。


精灵不实现鼠标事件

Cocos2d 的精灵与其他程序库描述的精灵一样,是一个可以进行移动,旋转,大小变化,动画等操作的2D图像。

精灵(通过 CCSprite 类实现)可以拥有其它精灵作为其子成员。当一个父成员进行变换时,其所有子成员也将同时进行变换。

由于精灵是 CCNode的子类,因此可以使用“动作”对场景进行变换。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
About CocoStudio is a game development tool kit based on Cocos2d-x. It breaks down tasks in game development into different roles, it includes: UI editor for UI graphic artists, Animation editor for graphic artists, Number cruncher for game data designers, Scene editor for game designers CocoStudio forms a complete game development solution. The UI editor The UI was designed to serve its only purpose: create UI for games. Its simple and intuitive interface allows graphic artists to focus on their expertise, without worrying about other aspects such as programming. Currently the UI editor has 12 different UI elements ready to be used in games, new UI elements will be added with each and every release of CocoStudio, Other key features that the UI editor supports are: Texture packaging - Automatically packs individual texture files into a single large sprite, which further saves memory and improves game performance. Multi-resolution adaption - Automatically adapts to multiple resolution sizes with relative UI positioning. Templating - Reuse the same UI layout across different games, swap out texture resources to give it a new look. The Animation editor The Animation editor was designed to feel like Adobe Flash, which makes graphic artists feel right at home. The Animation editor brings skeletal animation to Cocos2d-x. What advantage does skeletal animation holds against the traditional frame animation? Lower memory consumption - An animation with the traditional frame based solution could use dozens of individual textures, but with skeletal animation, only 1 set of body parts is required to make infinite number of different animations. Smaller file size - due to less number of assets. Animation blending - you can combine animations together to easily make new animation, for example, you could blend attacking animation with walk animation to create "attacking while walking animation". Animation reuse - you can share skeletal animations with another character with the same skeleton setup. Smooth interpolation - traditional frame based animation is very choppy especially in slow motion. Skeletal animation interpolates between 2 sets of key frames, so animation is always played at the same frame rate as the game. However Skeletal animation cannot replace the traditional frame based animation, for example, it cannot make isometric character, it cannot make explosion, that is why we did not forget frame based animation, we even made it better and simpler. You only have to drag and drop frame sequences to the work space, and the animation editor will automatically creates the frame animation for you. Other highlight of Animation editor includes: WYSIWYG collision box editing - editing collision box in wysiwyg way has never being easier and accurate. Reference point - enables characters to wield swords, mount horses, and attaching other objects easily. Texture packing - Automatically packs individual texture files into a single large sprite, which further saves memory and improves game performance. The Data Cruncher The data Cruncher imports excel tables and converts the data into a format readable by cocos2d-x, which can also be used as a component for the Scene editor. The Scene editor The scene editor pieces all the assets made by the UI editor, Animation editor, and the Data Cruncher into a game scene, it can then simulate the game inside the editor. The scene editor also supports many assets made from third party editors such as particle designer, tiled etc. The scene editor relies on the CocosStudio Framework. CocoStudio Framework CocoStudio Framework is an open source higher level framework on top of Cocos2d-x, it employes entity and component system, it is used to read the data saved from the scene editor. The Scene editor saves data in a MVC like fashion, it includes all entities and events used in the current scene, and exports to corresponding code template for the programmers. A programmer can then write the code in Javascript to bring the game alive. CocoStudio的安装 1.CocoStudio的运行平台是Windows操作系统,推荐使用Windows7操作系统。 2.安装CocoStudio之前,确保电脑中安装了.Net 4.0 Framework 3.安装目录尽量不要在C盘的Program Files文件夹下,可能会导致启动无法启动编辑。当然,通过“以管理员身份运行”的方式也可以打开软件 4.在Xp和Windows8的操作系统下,可能会出现的闪屏或无法运行的问题。这个问题会尽快修复

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值