#ifndef __PHYSICSNODES_CCPHYSICSSPRITE_H__

#define __PHYSICSNODES_CCPHYSICSSPRITE_H__

#include "cocos2d.h"

#include "ExtensionMacros.h"

#if CC_ENABLE_CHIPMUNK_INTEGRATION

#include "chipmunk.h"

#elif CC_ENABLE_BOX2D_INTEGRATION

class b2Body;

#else // CC_ENABLE_BOX2D_INTEGRATION

#error "You must define either CC_ENABLE_CHIPMUNK_INTEGRATION or CC_ENABLE_BOX2D_INTEGRATION to use CCPhysicsSprite.h"

#endif

NS_CC_EXT_BEGIN

/** A CCSprite subclass that is bound to a physics body.

It works with:

- Chipmunk: Preprocessor macro CC_ENABLE_CHIPMUNK_INTEGRATION should be defined

- Objective-Chipmunk: Preprocessor macro CC_ENABLE_CHIPMUNK_INTEGRATION should be defined

- Box2d: Preprocessor macro CC_ENABLE_BOX2D_INTEGRATION should be defined

Features and Limitations:

- Scale and Skew properties are ignored.

- Position and rotation are going to updated from the physics body

- If you update the rotation or position manually, the physics body will be updated

- You can't enble both Chipmunk support and Box2d support at the same time. Only one can be enabled at compile time

*/

class CCPhysicsSprite : public CCSprite

{

protected:

bool    m_bIgnoreBodyRotation;

#if CC_ENABLE_CHIPMUNK_INTEGRATION

cpBody  *m_pCPBody;

#elif CC_ENABLE_BOX2D_INTEGRATION

b2Body  *m_pB2Body;

// Pixels to Meters ratio

float   m_fPTMRatio;

#endif // CC_ENABLE_CHIPMUNK_INTEGRATION

public:

CCPhysicsSprite();

static CCPhysicsSprite* create();

/** Creates an sprite with a texture.

The rect used will be the size of the texture.

The offset will be (0,0).

*/

static CCPhysicsSprite* createWithTexture(CCTexture2D *pTexture);

/** Creates an sprite with a texture and a rect.

The offset will be (0,0).

*/

static CCPhysicsSprite* createWithTexture(CCTexture2D *pTexture, const CCRect& rect);

/** Creates an sprite with an sprite frame. */

static CCPhysicsSprite* createWithSpriteFrame(CCSpriteFrame *pSpriteFrame);

/** Creates an sprite with an sprite frame name.

An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.

If the CCSpriteFrame doesn't exist it will raise an exception.

@since v0.9

*/

static CCPhysicsSprite* createWithSpriteFrameName(const char *pszSpriteFrameName);

/** Creates an sprite with an image filename.

The rect used will be the size of the image.

The offset will be (0,0).

*/

static CCPhysicsSprite* create(const char *pszFileName);

/** Creates an sprite with an image filename and a rect.

The offset will be (0,0).

*/

static CCPhysicsSprite* create(const char *pszFileName, const CCRect& rect);

virtual bool isDirty();

/** Keep the sprite's rotation separate from the body. */

bool isIgnoreBodyRotation() const;

void setIgnoreBodyRotation(bool bIgnoreBodyRotation);

virtual const CCPoint& getPosition();

virtual void getPosition(float* x, float* y);

virtual float getPositionX();

virtual float getPositionY();

virtual void setPosition(const CCPoint &position);

virtual float getRotation();

virtual void setRotation(float fRotation);

virtual CCAffineTransform nodeToParentTransform();

#if CC_ENABLE_CHIPMUNK_INTEGRATION

/** Body accessor when using regular Chipmunk */

cpBody* getCPBody() const;

void setCPBody(cpBody *pBody);

#elif CC_ENABLE_BOX2D_INTEGRATION

/** Body accessor when using box2d */

b2Body* getB2Body() const;

void setB2Body(b2Body *pBody);

float getPTMRatio() const;

void setPTMRatio(float fPTMRatio);

#endif // CC_ENABLE_BOX2D_INTEGRATION

protected:

void updatePosFromPhysics();

};

NS_CC_EXT_END

#endif // __PHYSICSNODES_CCPHYSICSSPRITE_H__


CCPhysicsSprite的更多相关文章

  1. Cocos2d学习之路五(Box2d使用CCPhysicsSprite时编译不通过解决方法)

    cocos2d使用box2d引擎,在使用CCPhysicsSprite添加精灵的时候会出现编译不通过错误. 需要注意以下几点: 1.sprite.position=ccp(p.x,p.y);这行代码一 ...

  2. 使用CocosSharp制作一个游戏 - CocosSharp中文教程

    注:本教程翻译自官方<Walkthrough - Building a game with CocosSharp>,官方教程有很多地方说的不够详细,或者代码不全,导致无法继续,本人在看了G ...

  3. cocos基础教程(3)cocos3.x版本目录结构介绍

    简介 cocos2d-x-3.x版本进行了很多优化,比如:将TTF字体用Atlas缓存,节点重排序官方声称提升了10倍速度,查找.移除节点方面也提高了10%,拆分渲染层到独立的线程运行: 另外,coc ...

  4. cocos2d-x游戏开发 跑酷(四) 关联与物理世界

    原创.转载注明出处http://blog.csdn.net/dawn_moon/article/details/21451077 前面一节尽管实现了一个跑动的人物,可是他只不过一个精灵在运行一个跑动的 ...

  5. Cocos2dx-3.1.1 冒险01----&gt; 文件夹结构、新项目project创建并执行

    windows开发环境:window7.vs2012.python2.7.6 Cocos2d-x 3.1.1的完整文件夹例如以下:比起曾经的2.x的版本号来说分类更规范了 watermark/2/te ...

  6. 让Cocos2dx中的TestCPP中的Box2dTest运行起来

    一般而言,如果你导入TestCPP到VS2012中去后,会编译十几分钟才会出现窗口界面,这是包含Cocos2dx所有功能的一个demo,功能非常齐全强大,里面有两个关于Box2d的测试案例,一个是Bo ...

  7. cocos2d-x高级学习

    弱联网开发技术: libcurl 添加lib文件:libcurl_imp.lib  pthreadVCE2.lib 添加头文件:#include"curl/curl.h" curl ...

  8. ccos2d-x 学习

    渲染驱动方式,事件驱动方式 this->addChild(pSprite, 0); 的第二个参数(int zOrder)表示要添加到this类对象中的顺序.是由里向外的方向.值越大表示越在外面. ...

  9. cocos2d-x分别在Visual Studio和eclipse中设置启用Box2D

    cocos2d-x内嵌有chipmunk和Box2D两个物理库,默认启用的是chipmunk.如果想使用Box2D,可做如下设置.PS:本人所用的版本是cocos2d-x-2.2.5. 一.在Visu ...

随机推荐

  1. 15,re正则表达式

    判断手机号是否合法. phone_number = input('请输入手机号:') if re.match('^(13|14|15|18)[0-9]{9}$',phone_number): prin ...

  2. deine const 等关键字区别

    define 属于预编译指令,在程序运行之前就已经编译好:额,定义变量,没有类型信息, const 修饰的变量是不可变的,只是给出了内存地址,且只在程序运行时初始化开辟一块内存空间 const 只修饰 ...

  3. 向php数组添加元素的方法哪种更高效

    $arr = array(); // 第一种 array_push($arr, 'test'); // 第二种 $arr[] = 'test'; 参考PHP官方文档:http://php.net/ma ...

  4. 在VS2017中编写Python程序

    最近开始了python的学习,在搭建完python环境之后,在选择IDE的时候陷入了困境,首先选择的是PyCharm但是用着还是不习惯,毕竟用VS开发了几年了,突然换软件总感觉有点不适应,就想到了强大 ...

  5. BASH重定向问题

    APUE 3.5关于重定向有个容易迷惑人的问题: ./a.out > outfile 2>&1 ./a.out 2>&1 > outfile 问两者区别? in ...

  6. 如何构建一个flink sql平台

    在本系列前面的文章中,简单介绍了一下Ignite的机器学习网格,下面会趁热打铁,结合一些示例,深入介绍Ignite支持的一些机器学习算法. 如果要找合适的数据集,会发现可用的有很多,但是对于线性回归来 ...

  7. K-D tree入门

    久仰K-D tree大名已久,终于在合适的时候遇见了合适的水题入了坑入了门 K-D tree是什么 K-D tree是什么? 按名字上翻译来就是K维的树,就是一个用来维护K维空间的点的平衡二叉树 K- ...

  8. JConsole手册

    一篇Sun官方网站上介绍JConsole使用的文章,前段时间性能测试的时候大概翻译了一下以便学习,今天整理一下发上来,有些地方也不知道怎么翻,就保留了原文,可能还好理解点,呵呵,水平有限,翻的不好,大 ...

  9. log4j详细配置解析

    出自:http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记录 ...

  10. noj 2069 赵信的往事 [yy题 无限gcd]

    njczy2010 2069 Accepted 31MS   224K 1351Byte G++ 2014-11-13 13:32:56.0 坑爹的无限gcd,,,尼玛想好久,原来要x对y算一次,y再 ...