CCPhysicsSprite
#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的更多相关文章
- Cocos2d学习之路五(Box2d使用CCPhysicsSprite时编译不通过解决方法)
cocos2d使用box2d引擎,在使用CCPhysicsSprite添加精灵的时候会出现编译不通过错误. 需要注意以下几点: 1.sprite.position=ccp(p.x,p.y);这行代码一 ...
- 使用CocosSharp制作一个游戏 - CocosSharp中文教程
注:本教程翻译自官方<Walkthrough - Building a game with CocosSharp>,官方教程有很多地方说的不够详细,或者代码不全,导致无法继续,本人在看了G ...
- cocos基础教程(3)cocos3.x版本目录结构介绍
简介 cocos2d-x-3.x版本进行了很多优化,比如:将TTF字体用Atlas缓存,节点重排序官方声称提升了10倍速度,查找.移除节点方面也提高了10%,拆分渲染层到独立的线程运行: 另外,coc ...
- cocos2d-x游戏开发 跑酷(四) 关联与物理世界
原创.转载注明出处http://blog.csdn.net/dawn_moon/article/details/21451077 前面一节尽管实现了一个跑动的人物,可是他只不过一个精灵在运行一个跑动的 ...
- Cocos2dx-3.1.1 冒险01----> 文件夹结构、新项目project创建并执行
windows开发环境:window7.vs2012.python2.7.6 Cocos2d-x 3.1.1的完整文件夹例如以下:比起曾经的2.x的版本号来说分类更规范了 watermark/2/te ...
- 让Cocos2dx中的TestCPP中的Box2dTest运行起来
一般而言,如果你导入TestCPP到VS2012中去后,会编译十几分钟才会出现窗口界面,这是包含Cocos2dx所有功能的一个demo,功能非常齐全强大,里面有两个关于Box2d的测试案例,一个是Bo ...
- cocos2d-x高级学习
弱联网开发技术: libcurl 添加lib文件:libcurl_imp.lib pthreadVCE2.lib 添加头文件:#include"curl/curl.h" curl ...
- ccos2d-x 学习
渲染驱动方式,事件驱动方式 this->addChild(pSprite, 0); 的第二个参数(int zOrder)表示要添加到this类对象中的顺序.是由里向外的方向.值越大表示越在外面. ...
- cocos2d-x分别在Visual Studio和eclipse中设置启用Box2D
cocos2d-x内嵌有chipmunk和Box2D两个物理库,默认启用的是chipmunk.如果想使用Box2D,可做如下设置.PS:本人所用的版本是cocos2d-x-2.2.5. 一.在Visu ...
随机推荐
- python中魔法方法(持续更新)
1.对于一个自定义的类,如果实现了 __call__ 方法,那么该类的实例对象的行为就是一个函数,是一个可以被调用(callable)的对象.例如: class Add: def __init__(s ...
- day12-图
- PAT Basic 1029
1029 旧键盘 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及实际被输入的文字,请你列出肯定坏掉的那些键. 输入格式: 输入在2行中分别给出应该输 ...
- luogu1345 [USACO5.4]奶牛的电信Telecowmunication
对于每个点,把它拆成有权值为1的边相连的两个点,原边是inf. 边的起点统一加n,ss也加n 这就成了最小割 #include <iostream> #include <cstrin ...
- 获取class
使用原生JavaScript,获取类操作符时:即使使用getElementByClassName,在Firefox和IE9以下是不兼容的.Firefox下是可以用它获取的到元素而IE不行,一般框架都会 ...
- 在使用Cocos2d-JS 开发过程中需要用到的单体设计模式
JavaScript 单体模式的一种实现 T.getInstance = (function () { var instance = null; return function () { return ...
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- 开源中国+soucetree
参考链接:http://www.cocoachina.com/programmer/20151012/13682.html 1.创建一个工程
- 关于java读取文件IO流学习总结(二)
今天网上随意逛了逛,某处看到关于文件的操作,描述的不错,加深了对于文件操作的理解,在此分享给大家.希望能够有所收获. java读取txt文件内容: 可以作如下理解: 1. 首先获得一个文件句柄.Fil ...
- PHP中的验证码类(准备篇)
<!--code.php内容--> <?php //开启session session_start(); include "vcode.class.php"; / ...