#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. uboot-imx RGB24分析

    在mx6q_sabrsd.c文件中 函数else if(strcmp(s, "YUV444") == 0) val = IPU_PIX_FMT_YUV444; else val = ...

  2. POJ-1061 青蛙的约会 (扩展欧几里得)

    [题目描述] 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有 ...

  3. 循环链表的C风格实现(单向)

    头文件: #ifndef _CIRCLELIST_H_ #define _CIRCLELIST_H_ typedef void CircleList; // typedef struct _tag_C ...

  4. Luogu3195 [HNOI2008]玩具装箱TOY (方程变形 + 斜率优化 )

    题意: 给出一个序列 {a[i]} 把其分成若干个区间,每个区间的价值为 W = (j − i + ∑ak(i<=k<=j) - L)​2 ,求所有分割方案中价值之和的最小值. 细节: 仔 ...

  5. Python中的序列化以及pickle和json模块介绍

    Python中的序列化指的是在程序运行期间,变量都是在内存中保存着的,如果我们想保留一些运行中的变量值,就可以使用序列化操作把变量内容从内存保存到磁盘中,在Python中这个操作叫pickling,等 ...

  6. PHP-redis命令之 散列(hashes)

    二.散列(hashes) 1.hset:设置散列的值 $redis->hset('myhas','field1','hello'); $redis->hset('myhas','field ...

  7. java的synchronized可重入锁

    在java内部,同一线程在调用自己类中其他synchronized方法/块或调用父类的synchronized方法/块都不会阻碍该线程的执行,就是说同一线程对同一个对象锁是可重入的,而且同一个线程可以 ...

  8. java 协程框架kilim

    http://phl.iteye.com/blog/2247112 http://chen-tao.github.io/2015/10/02/kilim-work-way/ 待丰富

  9. Java-获取一个类的父类

    如何使用代码获取一个类的父类 package com.tj; public class MyClass implements Cloneable { public static void main(S ...

  10. 【Luogu】P1594护卫队(前缀和+DP)

    TM搞了半天的二维DP方程还是错的. 这是题目链接: 设f[i]表示前i辆车顺利通过的最小时间. 则对于每一个i枚举该组车的起点j,然后从所有的f[j]+Min[j][i]中选一个最小的. Min[j ...