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方法制作可显示三维数据(宠物三维等)的三角形显示面板
很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...
随机推荐
- 【217】◀▶ IDL 控制语句说明
参考:Statements Routines —— 控制语句关键字 01 FOR 循环语句. 02 FOREACH 循环语句. 03 WHILE...DO 循环语句. 04 IF... ...
- sublime配置java环境
今天突然不想用eclipse编写java了,觉得sublime挺好用,就想用sublime配置java环境,以下是过程以及出现的问题. 一.配置Java环境 1.打开我的电脑–属性–高级–环境变量 2 ...
- Qt .pro文件配置大全!
避免以后的无意义重复劳动,将用过的所有的头文件库文件的配置都放在这里,以后要用的话直接copy就好. eigen3: INCLUDEPATH += \ /usr/local/include/eigen ...
- linux中的条件变量
1 大家可能知道互斥量是线程程序中必须的工具了,但是也不能是万能的,就比如某个线程正在等待共享数据某个条件的发生,这个时候会发生什么呢.它就可能重复的尝试对互斥对象锁定和解锁来检查共享数据结构. 2 ...
- 3-C++程序的结构1.4
共享数据的保护 对于既需要共享.又需要防止改变的数据应该声明为常量. 1.常引用 如果在声明引用时用const修饰,被声明的引用就是常引用.常引用所引用的对象不能被更新.声明形式如下: const 类 ...
- C# 程序软件启动默认管理员权限。
在vs的Properties目录中找到 app.manifest,将其中level="asInvoker" 改成 level="requireAdministrator& ...
- ORM取数据很简单!是吗?
简介 几乎任何系统都以某种方式与外部数据存储一起运行.大多数情况下,外部数据存储是一个关系数据库,并且在实现时通常将数据提取任务委托给某些 ORM. 尽管 ORM 包含很多 routine 代码,但是 ...
- Beatcoder#39+#41+#42
HDU5211 思路: 倒着更新每个数的约数,更新完要把自己加上,以及1的情况? //#include <bits/stdc++.h> #include<iostream> # ...
- Unity3D 图形优化
Unity3D 图形优化 例如DrawCall,我得到的是一些并不完全正确的信息,例如将N个纹理打包成一个图集,这个图集就只会产生一个DrawCall,如果不打成图集,那么就会有N个DrawCall. ...
- 我不知道的C#—字符串池机制
字符串具有值类型的特点对字符串,对同一个字符串大量修改或者对多个引用赋值同一个字符串对象时会产生大量的临时字符串对象,影响性能,但是CLR为我们做了一些工作来消除这些弊端. 对同一个字符串大 ...