Cocos2d-x学习笔记

Cocos2d-x学习笔记(一) 创建自己的Cocos2d-x项目 这几天心血来潮想要学习Cocos2d-x,虽然有C#与Java的基础,不过毕竟好几年不碰代码,而且对于C++我完全是个新手,只好一边学习C++基础一边找些Cocos2d-x的相关资料。不过好在C++的基础语法与C#还算相似,所以起步不算太艰难。只是Cocos2d-x在还未开始进行的时候就已经让我栽了好几个跟头。总之这些经验来之不易,所以我决定记录下我学习的过程,也许能帮助到那些跟我遇... 阅读详情

Cocos2d-x学习笔记

A. Severalimportant concepts。

Director: run backward, manage the all the scenes in the game like replacescene.

Scene: run at forward, contains several layers, control the layers,now a container of the layers.

Layer: run at forward, each layer contains several sprites, andcontrol the sprites, accept input from touching or accelerometer.

Sprite: a sprite is just a changing image.

 

B. Afterreading the HW code of Felix。

1.About Scene: Scene classes are used to create scenes as container of layersimplemented by creating scenes at first then creating layers of this scene andadd them to the current scene.

2.About Layer: When we init a layer we create the menu items(menu) and spritesand add them to the layer itself.

3.About the control of menu: we set a selector(a function) to carry out the event we get fromthe menu. Maybe we use Director to call its member functions to replace thescenes.

 

C. Timer:

We use schedule(stepfun,interval)  inherited from CocosNode to run an actionrepeatly.

And we use unscheduled to release the timer.`                                                                                                                                           `

 

D.Action.

Instant Action: Place  Hide Show  ToggleVisibility

Finite Time Action: Moveto MoveBy JumptoJumpby …

Composition Ation: Sequence,Spawn,Repeat, Revers, Animation, RepeatForever, Back.

 

E. Cocos2dx Project settings in VS2008:

First we should build the libcocos2d, because we will use the outputof the libcocos2d building in our own project, so its setting should befinished first. 

Libcocos2d Project:

1.      Configuration Properties ->General -> Output Directory: the result(lib files) will be built to here soit should be a place we should know.

2.      Configuration Properties ->C/C++ -> General -> Additional Include Directories: here should be allthe head files’ directories that will be used by this project.

3.      Configuration Properties ->Linker -> General -> Output File: $(OutDir)\$(ProjectName).dll 

The OutDir is the same as the OutputDirectory in 1.

4.      Configuration Properties ->Linker -> General ->Additional Library Directories: $(OutDir)

5.      Configuration Properties ->Linker -> Input -> Additional Dependencies: put down all the libraries wewill use. Like : libEGL.lib libgles_cm.lib libxml2.lib libzlib.lib libpng.liblibjpeg.lib libiconv.lib pthreadVCE2.lib

 

My Cocos2d Project:

1.      Configuration Properties ->General -> Output Directory: this should be same with the one of Libcocos2dproject.

2. Configuration Properties-> C/C++ -> General -> Additional Include Directories:

Like:..\..\cocos2dx\include;..\..\cocos2dx;..\..\cocos2dx\platform;..\..\cocos2dx\platform\third_party\win32\OGLES.  We could add more if they will be use by ourproject just for improving developing speed.

3.      Configuration Properties ->Linker -> General -> Output File: $(OutDir)\$(ProjectName).exe 

4.      Configuration Properties ->Linker -> General ->Additional Library Directories: $(OutDir)

5.      Configuration Properties ->Linker -> Input -> Additional Dependencies: libcocos2d.lib libgles_cm.lib2

F.  After Writing My First Cocos2dx Program

1. Global initial settings isin the AppDelegate::initInstance andAppDelegate::ApplicationDidFinishLaunching, such as the windowsize and the FPSand so on.

2. Difference between JumpByand JumpTo.

JumpBy(Duration, Relative Increment to its StartPosition, Height,Jump Times).

JumpTo(Duration, Absolute Target Position to reach, Height, JumpTimes)

Code to Impliment Jump At the Original Place With CCJumpBy:

     //create a new sprite from an image

     CCSprite* sprite=CCSprite::spriteWithFile("res\\image\\man.png");

     //set the sprite's start position

     sprite->setPosition(CCPointMake(s.width-40,s.height/2));

     //also add the sprite to the object of Layer1

     addChild(sprite);

     //create a jumpby action,jump 2 times in 1 second

     CCActionInterval* jump=CCJumpBy::actionWithDuration(1,CCPointMake(0,0),40,2);

     //create a repeat action to repeat the jump action

     CCAction* repeat=CCRepeatForever::actionWithAction(jump);

     //let sprite run the action

     sprite->runAction(repeat);

The same with MoveBy&MoveTo and ScaleBy&ScaleTo and so on.

XxxTo classes usually don’t support Reverse(), but XxxxBy classesusually support Reverse().

3.      some questions for theCCSequece:

Definition: 

classCC_DLLCCSequence : publicCCActionInterval { …};

classCC_DLLCCActionInterval : publicCCFiniteTimeAction { …};

That is to say CCSequence is a child class of CCActionInterval, butwhen I create a CCSequece:

CCActionInterval* sequence= (CCSequence::actions(scaleExpand,ScaleShrink, NULL));

The compiler complains:

 cannot convert from 'cocos2d::CCFiniteTimeAction *' to'cocos2d::CCActionInterval *'

I ‘solve’ this problem by cast it to CCActionInterval forcely andthe problem could run seems OK.

4. A good example ofCCSequence:

Example:

CCAction *pingPongAction =CCSequence::actions(action, action->reverse(), NULL);

G. Animation:

       1.create animation from several images

         //create an animation action

         CCAnimation* animition=CCAnimation::animation();

         //2 frames each second

         animition->setDelay(0.5f);

         //add the files as frames

         for(inti=0;i<NumOfImages;i++)

         {

                   animition->addFrameWithFileName(img[i].c_str());

         }

         CCAnimate* animate=CCAnimate::actionWithAnimation(animition);

         //create a repeat action to repeatthe rotate action

         CCAction* repeat=CCRepeat::actionWithAction(animate,2);

         //let sprite run the action

         sprite->runAction(repeat);

2.create animation fromone image

       //load the image

         CCTexture2D *PlayerRunTexture=CCTextureCache::sharedTextureCache()->

addImage(".\\res\\image\\swordman.png");

         //store the frames in theCCMutableArray

         CCMutableArray<CCSpriteFrame*>* animFrames= newCCMutableArray<CCSpriteFrame*>(11);

         for(inti=0;i<8;i++)

         {

                   animFrames->addObject(CCSpriteFrame::frameWithTexture

(PlayerRunTexture,CCRectMake(72*i,0,72,72)));

         }

         

         //create the animation object

         CCAnimation* animation=newCCAnimation();

         animation->initWithFrames(animFrames,0.08f);

         animFrames->release();

         //create animation action

         CCActionInterval* animate=CCAnimate::actionWithAnimation(animation,false);

         //create a new sprite from an thefirst frame

         CCSprite* sprite=CCSprite::spriteWithSpriteFrame(CCSpriteFrame::

frameWithTexture(PlayerRunTexture,CCRectMake(0,0,72,72)));

         //set the sprite's start position

         sprite->setPosition(CCPointMake(s.width/2,s.height-80));

         //also add the sprite to theobject of Layer1

         addChild(sprite);

         //create a repeat action to repeatthe jump action

         CCAction* repeat=CCRepeatForever::actionWithAction(animate);

         //let sprite run the action

         sprite->runAction(repeat);

3.create animation fromone png image and it’s .plist and .anim files(produced from its .sprite file).

 

H. Intrinsic Animation of aSprite is the Animation which always exists with Sprite and keep running.

I. Don’t Know How to UseCCCallFun ?

         //create a function action

         CCCallFunc* acf=CCCallFunc::actionWithTarget(this,callfunc_selector(Layer1::callback));

Use it as an action will be ok. But I madea stupid mistake as I forgot to set a BreakPointto test if the callback() has been runned.

J. Aboutthe CCSequece:

CCSequence cannot be directly used byCCRepeatForever(CCActionInterval*),Because the return type fromCCSequence::actions(CCFiniteTimeAction*,…) is CCFiniteTimeAction.CCActionInterval is inherited from CCFiniteTimeAction. Pointer to Parent classcannot be cast to Pointer to Child class. Instead we could useCCSequence::initOneTwo() several times to create our Sequece as its return typeis CCSequence which is a child class of CCActionInterval.

K. Howto test double-click in cocos2d-x?

There is no direct function to implementthis, but we can implement it by test the tick between two clicks.ssssss

L.MapEditor

We construct a map in the cocos2d-x gameswith tiles,because e will fill many places in the map with same tiles so, thissolution will save a lot memory.

The result of the TMX Editor:

  1. a .tmx file which is an XML file indicates the organization of the map from the tiles.
  2. a .png image provides the tiles we used before.

Display Map:  CCTMXTiledMap

Parse The XMLFiles: CCTMXXMLParser(not found in cocos2d-x).

How to use the Tile tool to edit map?

Elements:

Map, Layer, Tileset.

We can add properties which we will usewhen programming to each kind of element.

Save->.tmx, it is an XML file containsour map information.

We can also export the properties of ourtileset as an element which can be imported to other map.

 

About the XML file:

It’s structure like html contains manylabels indicates the elements we can see from the Tile tool.

 

Structure of the Game data:

The XML files gives the structure of ourscenes and maps, and some properties we can use to set our sprites.

The data can be got from database .dbfiles.

 

M. CCAnimationhas no constructor like CCAnimation().

       TodayI tried to create an animation with the following code:

                CCAnimation* animation=newCCAnimation();

       Butit leads to a crush, I don’t knowwhy, and compare the code with my code to create an animation yesterday, it islike this:

                       CCAnimation* animation=CCAnimation::animation();

       Somethingmust be wrong , I looked up the definition of the CCAnimation and didn’t find aCCAnimation() constructor but a static initial function animation().

 

N.Coding tips when you compare a variable and a constant.

Putting the constant forward will reducethe chance you make mistakes because constant cannot be assigned.

Like: p is a pointer:

The error like this  If(NULL = p) will not pass the compile.

But this If(p = NULL) may lead to a crush.

 

O.usageof callFunctionND

Do something after some action.

HFSS本征模求解:谐振特性分析与工程实践 本征模求解是电磁仿真中的基础技术,用于分析无源谐振系统的固有特性。其核心原理是通过求解麦克斯韦方程组的特征值问题,获得谐振频率、品质因数(Q值)及电磁场分布等关键参数。在5G滤波器设计、雷达谐振腔优化等高频场景中,精确的本征模分析能有效避免模式干扰,提升器件性能。HFSS作为行业标准工具,提供了完整的本征模求解工作流,涵盖边界条件设置、模式识别、场分布可视化等关键环节。针对多模耦合、模式纯度评估等工程难题,结合参数化扫描和场重叠积分等高级技巧,可显著提升微波器件设计效率。 阅读详情

相关推荐

技术文档的语言表达:简洁、准确与易懂的平衡艺术

技术文档的语言表达不仅要简洁、准确,还需要能够打破技术壁垒,使不同背景的读者都能理解。这是一项需要技巧和经验的工作,它要求技术作者既要具备扎实的专业知识,又要具备清晰的表达能力。通过不断打磨语言的简洁性、准确性和易懂性,我们能够创造出一份高质量的技术文档,让知识的传递不再受限于语言的障碍。

人心有反复,好在山水有重逢。 4677

cocosjs

    cc.Class 是一个很常用的 API,用于声明 Cocos Creator 中的类,为了方便区分,我们把使用 cc.Class 声明的类叫做 CCClass。 调用 cc.Class,传入一个原型对象,在原型对象中以键值对的形式设定所需的类型参数,就能创建出所需要的类。 var Sprite = cc.Class({ name: "sprite" }); 使用 ct...

菜鸟的专栏 3086

PADS Layout中快速导入自定义元器件封装的实用技巧

本文详细介绍了在PADS Layout中高效导入自定义元器件封装的实用技巧。针对封装“找不到”、“对不上”、“导不进”三大痛点,系统梳理了从封装文件来源识别、库规划管理,到三种核心导入场景(从库文件添加、从其他设计借用、处理第三方格式)的完整操作流程,并提供了导入后的关键验证清单与常见问题排查方法,旨在帮助硬件工程师快速掌握这一提升设计效率的关键技能。

weixin_29302047的博客 375

scala初学_Scala初学者系列1基础

scala初学This series is all about the taste of Scala. It is best suitable for all the newbies in Scala. So here we go… 这个系列是关于Scala的味道的。 它最适合Scala中的所有新手。 所以我们开始... This article will cover the fundamenta...

weixin_26705651的博客 244

内存|内存的概念、内存的作用、内存的物理结构及内存使用

内存是硬件,是用于存放数据的硬件。程序执行前需要先放到内存中才能被CPU处理。内存是与CPU沟通的桥梁,计算机中所有程序的运行都要依靠内存,内存对计算机的影响非常大。本文简单介绍了内存的概念、作用、物理结构以及使用,内存远不止如此,后续文章会逐步深入讲解。

qq_59938293的博客 2万+

开关电源辅助电源设计全流程拆解

地类型定义包含电路功率地(PGND)高压侧地,与主功率电路地相连整流桥负极、原边电感地、UC3842的功率地信号地(SGND)低压侧地,与控制/采样电路地相连副边整流管地、TL431地、MCU/运放地。

lyzh971103的博客 1469

学习笔记 6_Cocos Creator_CCClass 进阶参考

CCClass 进阶参考 相比其它 JavaScript 的类型系统,CCClass 的特别之处在于功能强大,能够灵活的定义丰富的元数据。CCClass 的技术细节比较丰富,你可以在开发过程中慢慢熟悉。本文档将列举它的详细用法,阅读前需要先掌握 使用 cc.Class 声明类型。 原型对象参数说明 cc.Class({ // 类名,用于序列化 // 值类型:Str

Leovany的专栏 3923

PWM调光原理详解:为什么你的LED灯会闪烁?从硬件到软件的避坑指南

本文深入解析PWM调光原理,揭示LED灯闪烁的根本原因,并提供从硬件设计到软件算法的全面解决方案。通过分析人眼视觉暂留机制和PWM参数设置,帮助开发者避免频闪问题,提升照明质量。特别适合电子工程师和智能家居开发者参考。

weixin_29189363的博客 293

几个错误的解决关键

导读:   1、   org.springframework.orm.ObjectRetrievalFailureException: Object of class [com.xindeco.myregister.pojo.MyRegisterInfo] with identifier [14]: not found   MyRegisterInfo在数据库没有identifier [1

我的世界我的梦 3万+

基于ESP32的智能健康监测系统开发

本文介绍了如何基于ESP32开发智能健康监测系统,从硬件选型、系统架构到软件实现的每一个环节。通过ESP32的Wi-Fi功能、传感器模块和云平台的结合,我们实现了实时健康数据监测、远程查看、报警等功能。系统的低功耗特性使得其适用于长期健康监测,能够为用户提供更便捷的健康管理方案。随着技术的不断发展,未来智能健康监测系统将进一步发展。例如,增加更多的传感器,提升数据分析能力,甚至通过人工智能算法来预测用户的健康趋势,为用户提供个性化的健康建议。

2201_76125393的博客 1104

【YOLO部署Android安卓手机APP】YOLOv8部署到安卓实时目标检测识别——官方/自训练模型YOLOv8人脸/车辆等目标检测(可自定义更换其他目标)

本文首先讲解如何直接使用官方训练好的模型部署到手机APP进行人脸检测,然后讲解如何修改其他目标进行检测,以车辆检测为例进行讲解如何训练自己的模型部署到手机APP。本文为详细设计/配置文档,包含完整所需的环境配置搭建,项目工程配置步骤等,手把手记录使用pycharm和Android studio的工程开发过程,实现YOLO部署到安卓。实战开发,亲测无误。本项目实现了人脸检测和车辆检测,当然,以此你可以按照本项目开发步骤扩展更换为其他目标进行检测,例如更换为车牌、手势、人脸面部活动、人脸表情、火焰烟雾、行人等

嵌入式阿齐Archie 1万+

cc.isChildClassOf 判断两个类的继承关系

使用cc.isChildClassOf来判断两个类的继承关系:var Texture = cc.Class(); var Texture2D = cc.Class({ extends: Texture }); cc.log(cc.isChildClassOf(Texture2D, Texture)); // true两个传入参数都必须是类的构造函数,而不是类的对象实例。如果...

weixin_34310127的博客 323

数据库系统工程师软考备战:第三篇 - SQL语言深入解析与应用

​​创建表​​​修改表​​​删除表​。

Programming Talk 122

cocos2d-x学习笔记!

最近忙了一段时间,在用Cocos2d-x开发休闲游戏,顺便写下学习笔记吧!

yaohe321321的专栏 557

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

cocos2d-x 学习笔记——瓦片地图TiledMap

` 转 cocos2d-x 学习笔记——瓦片地图TiledMap ...

二休哥的博客 1247

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

[Cocos2d-x]Cocos2d-x 3.2 学习笔记

2014-06-27     我来说两句    来源:[Cocos2d-x]Cocos2d-x 3.2 学习笔记   收藏    我要投稿 获取屏幕大小(Visible) ? 1 2 3 <code class="perl">Size visibleSize = Director::getInstance()-

yejian2011的专栏 568

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

老G的cocos2d-x学习笔记系列

本文转自Cocos2d-x中文论坛,版主老G分享了自己的cocos2d-x学习笔记。 感谢老G的慷慨分享! cocos2d-x学习笔记18:内存管理01:概述 http://4137613.blog.51cto.com/4127613/784134 cocos2d-x学...

199

cocos2d-x初探学习笔记(装载)

cocos2d-x初探学习笔记(1)--HelloWorld http://blog.csdn.net/bill_man/article/details/7202458

灵思致远Leansmall的博客 547

移动2D游戏框架 Cocos2d-x 学习笔记

转自:http://blog.51cto.com/zt/152

MyDriverC 586

Cocos2d-x学习笔记《02》— 架构初识

Cocos2d-x学习笔记《02》— 架构初识 who1753Cocos2d围观556次暂无评论 1. 架构 2. 目录结构 目录名称 说明 CocosDenshion 音频支持。注意:Android平台中背景音乐和短音效所使用的系统API不同。 cocos2dx Cocos2d-x框架的主目录。

anlun的专栏 695

cocos2d-x学习笔记(持续更新)

接受触屏事件的优先级是值越小,响应触屏事件的优先级越高 Z值越大,越外面 粒子系统设计工具:Particle Designer软件  目前只支持MAC平台 导出 plist文件 地图设计工具:Tiles 目前有两个版本,一个是Java版本,另一个是QT版本  导出TMX格式文件 图片编缉工具,将多个精灵整合成一个大图:  导出plist文件 Zwoptex 两个版本,

we000636的专栏 2万+

Cocos2d-x学习笔记(七)—— 动作处理

动作类型 瞬时动作: 瞬间执行的动画,我们无法看到它变化的过程。 CCSize s = Director::getInstance()->getWinSize(); CCLabelTTF *label = CCLabelTTF::create("windowslake", "A Damn Mess", 23); label->setPosition(Vec2(0, s.height /

u013707014的博客 491

Cocos2d-x:学习笔记(2017.05.12更新)

1.参考链接汇总官方接口文档 关于Cocos2d-x中addchild和removeChild方法的参数的解析 Cocos2d-x3.2 Menu菜单的创建 cocos 中熟练运用场景的切换 cocos2dx一个场景添加多个层 Cocos2d-x Layer锚点设置 cocos2d-x convertToWorldSpace 和 convertToNodeSpace cocos2d-

linwh8的博客 1775

Cocos2d-x学习笔记(3) - 动作

对于一个游戏来说,动作是非常重要的,好的动作可以使游戏的可玩性大大提高,在cocos2d-x引擎中有一个动作类,CCAction是动作类的基类,动作是定义在节点(CCNode)上的,以节点为目标,主要分为两类瞬时动作和延时动作,具体的动作可以再官方的api上有详细的列表,这里给一个链接吧!(不要总是偷懒。。。http://cn.cocos2d-x.org/document) 一个动作的实现主要

John_cdy的专栏 1384

Cocos2d-x学习笔记(六)—— 事件处理

事件处理: 事件监听和事件监听绑定通知中心Input输入框的使用 事件监听和事件监听绑定 事件监听处理,有个重要的类EventDispatcher: 这个类管理事件监听器的订阅和事件的分发 事件监听器列表以这样的方式来进行管理:当事件正在分发的过程中,事件监听器可以被添加或者移除,包括事件监听器内部的监听器。 其常用的成员函数: void addEve

u013707014的博客 513

【cocos2d-x】cocos2d-x学习笔记之一

本篇博文主要记录了自己在Ubuntu12.04系统下配置cocos2d-x的开发环境。在配置过程了参考了以下地址的博文: Ubuntu下cocos2d-x开发环境及配置http://blog.csdn.net/jamesjiangchn/article/details/8734586 子龙山人的cocos2d-x跨android&ios平台开发入门教程http://www.cnblogs.co

haoaina521的专栏 3710
上一篇: 使用cocos2d-x编程debug记录
下一篇: VS2008下cocos2d-x工程配置
SingingCoder
博客等级 码龄15年 9粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值