#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. Python从文件中读取数据(2)

    一.读取文件中各行的内容并存储到一个列表中 继续用resource.txt 举例 resource.txt my name is joker, I am 18 years old, How about ...

  2. idea导入jdk源码查看(xjl456852原创)

    idea添加了jdk环境后,却无法查看jdk源码,只能通过idea自带的反编译查看,看起来有些不爽. 下面来说一下如何设置,导入jdk源码,查看时通过源码查看jdk. 1.点击菜单 File -> ...

  3. python中获取python版本号的方法【转】

    原文 python3 #!/usr/bin/python # 第1种方法 import platform print(platform.python_version()) >>> i ...

  4. log4j动态日志级别调整

    1. 针对root logger的设置 log4j.rootLogger=INFO, CONSOLELogger.getRootLogger().setLevel(org.apache.log4j.L ...

  5. 大数据学习——hive的sql练习题

    ABC三个hive表 每个表中都只有一列int类型且列名相同,求三个表中互不重复的数 create table a(age int) row format delimited fields termi ...

  6. 基于深度学习的目标检测技术演进:R-CNN、Fast R-CNN,Faster R-CNN

    基于深度学习的目标检测技术演进:R-CNN.Fast R-CNN,Faster R-CNN object detection我的理解,就是在给定的图片中精确找到物体所在位置,并标注出物体的类别.obj ...

  7. windows和ubuntu14.04双系统设置默认启动项

    首先开机或者重启,在启动项选择菜单处记住win7对应的序号,从上至下的序号从0开始计数,我的win7系统选项处于第5个,那么序号就应该是4,记住后,打开ubuntu系统. 2 按下Ctrl+alt+T ...

  8. POJ-1200 Crazy Search,人生第一道hash题!

                                                        Crazy Search 真是不容易啊,人生第一道hash题竟然是搜博客看题解来的. 题意:给你 ...

  9. iOS视频录制,裁剪(输出指定大小)

    弄了几天,终于搞懂一点了,博客后面再写,先附上demo,等研究清楚再写 demo地址:http://pan.baidu.com/s/1o6w2CMu

  10. 【Luogu】P1199三国游戏(博弈论)

    题目链接 来看一波有理有据的分析 三牧小明的那篇 代码 #include<cstdio> #include<cctype> #include<algorithm> ...