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的更多相关文章

  1. 欢迎来到 Flask 的世界

    欢迎来到 Flask 的世界 欢迎阅读 Flask 的文档.本文档分成几个部分,我推荐您先读 < 安装 >,然后读< 快速上手 >.< 教程 > 比快速上手文档更详 ...

  2. 【转】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 ...

  3. Scenes in Cocos2D

    https://www.makeschool.com/docs/?source=mgwu#!/cocos2d/1.0/scenes Scenes in Cocos2D In Cocos2D you h ...

  4. [转]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 ...

  5. Scala Macros - scalamela 1.x,inline-meta annotations

    在上期讨论中我们介绍了Scala Macros,它可以说是工具库编程人员不可或缺的编程手段,可以实现编译器在编译源代码时对源代码进行的修改.扩展和替换,如此可以对用户屏蔽工具库复杂的内部细节,使他们可 ...

  6. Scala Macros - 元编程 Metaprogramming with Def Macros

    Scala Macros对scala函数库编程人员来说是一项不可或缺的编程工具,可以通过它来解决一些用普通编程或者类层次编程(type level programming)都无法解决的问题,这是因为S ...

  7. 小尝试一下 cocos2d

    好奇 cocos2d 到底是怎样一个框架,正好有个项目需要一个游戏框架,所以稍微了解了一下.小结一下了解到的情况. 基本概念 首先呢,因为 cocos2d 是基于 pyglet 做的,你完全可以直接用 ...

  8. 采用cocos2d-x lua 制作数字滚动效果样例

    require "Cocos2d"require "Cocos2dConstants"local testscene = class("testsce ...

  9. Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板

    很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...

随机推荐

  1. Google浏览器如何加载本地文件

    Chrome浏览器加载本地文件 一般来说,为了安全起见,浏览器是不能通过load方法来加载本地文件的,load方法只能加载远程服务器上的文件. 在浏览器默认的情况下,试图加载一个本地文件,会出现交叉域 ...

  2. 【Data Structure & Algorithm】求1+2+…+n

    求1+2+-+n 题目:求1+2+-+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字以及条件判断语句(A ? B : C). 分析:此题没多少实际意义,因为 ...

  3. ASP.NET Core会议管理平台实战_汇总贴

    ASP.NET Core会议管理平台实战 课程地址:https://ke.qq.com/course/389673?from=800004097#term_id=100464670 ASP.NET C ...

  4. Qt-MVC图形视图框架初识

    使用QPushButton.QLabel.QCheckBox等构成GUI的控件或自定义图形时,开发应用程序会变得很简单.但是如果想在GUI中使用数十个或者数百个图形对象,向用户完美展示控制场景,则会受 ...

  5. 初识btrace

    此文已由作者易国强授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 1 btrace简介 BTrace是一个非常不错的java诊断工具.BTrace 中的B表示bytecode ...

  6. MyBatis中的RowBounds

    myBatis中实现分页的方式是采用RowBounds这个类,用法如下,xml语句不变 传入两个参数,strat起始行, limit是当前页显示多少条数据,原理是RowBounds在处理分页时,只是简 ...

  7. 3DMAX 7 角色建模1 人头建模

    说明: mesh与poly 可编辑多边形是一个多边形网格:即与可编辑网格不同,其使用超过三面的多边形.可编辑多边形非常有用,因为它们可以避免看不到边缘.例如,如果您对可编辑多边形执行切割和切片操作,程 ...

  8. PJzhang:百度网盘是如何泄露公司机密的?

    猫宁!!! 参考链接:https://mp.weixin.qq.com/s/PLELMu8cVleOLlwRAAYPVg 百度网盘在中国一家独大,百度超级会员具有很多特权,尤其是在下载速度上,是普通会 ...

  9. 初次接触Service笔记

    Service是后台的运行的小程序,分两种一种是StarService()另外一种是bindService(),这种可调用Service中的方法和返回结果等操作而StarService不能 他的生命周 ...

  10. STP-5-STP配置及分析

    拓扑: root id列出了根的网桥id为两部分,前边是优先级,后边跟着mac地址,cost 0 暗示sw1就是根: 下边的命令确认sw1就是vlan1的根: 下边,sw2配置了一个比sw1更低的优先 ...