More helpful Cocos2d and Gaming macros
More helpful Cocos2d and Gaming macros
Here are w few macros that i wrote to make the code more readable and to compress it in order to make more sense. The most important part of development is to keep the code simple and readable. This has multiple benefits which range from ease of working in a team to manageable code. When you code is clean and organized, you will be able to concentrate more on game logic rather getting lost in the syntactical complexities of the language.
Purpose: gets the x position of the ccnode#define PX(__NODE) __NODE.position.x
Purpose: gets the y position of the ccnode#define PY(__NODE) __NODE.position.y
Purpose:gets the CGSize of the ccnode#define CS(__NODE) __NODE.contentSize
Purpose:gets the width of the ccnode#define WDT(__NODE) __NODE.contentSize.width
Purpose:gets the height of the ccnode#define HGT(__NODE) __NODE.contentSize.height
Purpose: gets half the width of the ccnode#define WDT2(__NODE) __NODE.contentSize.width/2
Purpose:gets half the height of the ccnode#define HGT2(__NODE) __NODE.contentSize.height/2
Purpose:gets the center point of the ccnode#define CENTER_POINT(__NODE) ccp(WDT2(__NODE),HGT2(__NODE))
Purpose:gets the screen size (CGSize)#define viewportSize [[CCDirector sharedDirector] winSize]
Purpose:gets the center point of the screen#define centerScreenPoint ccp([[CCDirector sharedDirector] winSize].width/2,[[CCDirector sharedDirector] winSize].height/2)
Purpose: calls release on an object and nullifies it#define RELEASE_OBJECT(__NODE){ \
if (__NODE) { \
[__NODE release]; \
__NODE = nil; \
} \
}
Purpose:calls release of each object held at the index of the array, releases the array itself and nullfies the pointer.#define RELEASE_ARRAY(__NODE){ \
if (__NODE) { \
[__NODE removeAllObjects]; \
[__NODE release]; \
__NODE = nil; \
} \
}
Purpose:removes the sprite from the display list and nullifies its pointer. It does NOT release the sprite. This macro is for objects owned by cocos2d classes/code#define RELEASE_SPRITE(__NODE) { \
if (__NODE) { \
[__NODE removeFromParentAndCleanup:YES]; \
__NODE = nil; \
} \
}
Purpose:gets a random integer with a specified range#define GET_RANDOM(min, max) \
((rand()%(int)(((max) + 1)-(min)))+ (min))
Purpose:adds child in the mentioned parent and positions it#define ADDCHILD_POSITION(_object, _parent, _position){\
[_parent addChild:_object];\
[_object setPosition:_position];\
}
Purpose:adds child and positions it while giving it a tag and zindex#define ADDCHILD_POSITION_TAG_ZINDEX(_object, _parent, _position, _tag, _zIndex){\
[_parent addChild:_object z:_zIndex tag:_tag];\
[_object setPosition:_position];\
}
Purpose:gets the coordinates on the screen where the tap was made. used in ccTouchesBegan, ccTouchesMoved, ccTouchesEnded and ccTouchesCancelled functions#define GET_TOUCH_POINT(__TOUCHES) \
[[CCDirector sharedDirector] convertToGL:[[__TOUCHES anyObject] locationInView:[[__TOUCHES anyObject] view]]]
Purpose:Its a good practice to use such variables. A change in the font family later on will be quite problematic to make. Using this variable, single change will cause the change in the entire application.#define APPLICATION_FONT_FAMILY @"Arial"
More helpful Cocos2d and Gaming macros的更多相关文章
- 欢迎来到 Flask 的世界
欢迎来到 Flask 的世界 欢迎阅读 Flask 的文档.本文档分成几个部分,我推荐您先读 < 安装 >,然后读< 快速上手 >.< 教程 > 比快速上手文档更详 ...
- 【转】Enable ARC in a Cocos2D Project: The Step-by-Step-How-To-Guide Woof-Woof!
On April 5, 2012, in idevblogaday, by Steffen Itterheim http://www.learn-cocos2d.com/2012/04/enablin ...
- Scenes in Cocos2D
https://www.makeschool.com/docs/?source=mgwu#!/cocos2d/1.0/scenes Scenes in Cocos2D In Cocos2D you h ...
- [转]How to enable macros in Excel 2016, 2013, and 2010
本文转自:https://www.ablebits.com/office-addins-blog/2014/07/22/enable-macros-excel/#always-run-macros T ...
- Scala Macros - scalamela 1.x,inline-meta annotations
在上期讨论中我们介绍了Scala Macros,它可以说是工具库编程人员不可或缺的编程手段,可以实现编译器在编译源代码时对源代码进行的修改.扩展和替换,如此可以对用户屏蔽工具库复杂的内部细节,使他们可 ...
- Scala Macros - 元编程 Metaprogramming with Def Macros
Scala Macros对scala函数库编程人员来说是一项不可或缺的编程工具,可以通过它来解决一些用普通编程或者类层次编程(type level programming)都无法解决的问题,这是因为S ...
- 小尝试一下 cocos2d
好奇 cocos2d 到底是怎样一个框架,正好有个项目需要一个游戏框架,所以稍微了解了一下.小结一下了解到的情况. 基本概念 首先呢,因为 cocos2d 是基于 pyglet 做的,你完全可以直接用 ...
- 采用cocos2d-x lua 制作数字滚动效果样例
require "Cocos2d"require "Cocos2dConstants"local testscene = class("testsce ...
- Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板
很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...
随机推荐
- json : json数据解析(一)
在项目中经常用到json格式的数据转换与解析,先前写过一些小例子,现在整理下,以备后用和帮助后来者. 言归正传: 使用到的jar包 :json-lib-2.4-jdk15.jar,当然你也可以用自己版 ...
- 读取spring boot项目中resource目录下的文件
在开发中, 我们常常要将我们的配置文件或者模板文件放在我们的resource目录中. 如下 而在spring boot的项目中, 我们运行的是一个jar包, 并没有解压 所以当我们使用以下方式获取文件 ...
- Numbers Exchange
题意: Eugeny有n张卡片,他希望和Nikolay交换一些卡片使得他拥有的奇数数字和偶数数字的卡片数目一样,且所有数字都不同. Nikolay有m张卡片,分别写着1到m.问最少交换几次,能够满足要 ...
- [CVE-2014-3704]Drupal 7.31 SQL注入漏洞分析与复现
记录下自己的复现思路 漏洞影响: Drupal 7.31 Drupal是一个开源内容管理平台,为数百万个网站和应用程序提供支持. 0x01漏洞复现 复现环境: 1) Apache2.4 2) Php ...
- Jmeter之HTTP request
1.下载Jmeter http://jmeter.apache.org/download_jmeter.cgi 2.解压,在bin目录下找到jmeter.bat,并双击打开. 3.添加线程组 4.添加 ...
- 201621123016 《Java程序设计》第十二周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...
- 算法学习--Day8
今天重拾算法复习. 今天学习了两个类型的算法——并查集与最小生成树(MST) 简单记录一下并查集的大致内容. 一.并查集的内容大致作用为查找当前图中的点有几个集合. 该算法起到查询分组的情况.通过给定 ...
- UGUI实现unity摇杆
http://www.winig.cc/archives/348 好久没有写文章了,最近在做项目是用的unity最新的ui系统UGUI,项目需要做一个摇杆,网上大部分都是用的插件和NGUI做的摇杆,u ...
- windows 自定义批处理BAT/CMD启动Redis等软件
需求:每次开机都需要启动Redis.QQ.IDEA等等好几个软件,手动点击比较无趣.浪费劳动力,所以通过自定义bat文件,进行批量启动. 唯独启动到Redis时出现问题,下面是在bat里运行的路径: ...
- CentOS7-MySQL8安装-使用yum库安装
# Enable to use MySQL 5.5 [mysql55-community] name=MySQL 5.5 Community Server baseurl/$basearch/ ena ...