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 ...
随机推荐
- shell-code-4-运算符
#1. shell 基本运算符有:算数.关系.布尔.字符串.文件测试运算符#2. 原生bash不支持简单的数学运算,可使用awk和expr(最常用)echo `expr 1 + 2`# 反引号:表达式 ...
- 基础训练 Sine之舞
Sine之舞 #include<iostream> #include<vector> #include<string.h> using namespace std; ...
- java 获取音频文件时长
需要导入jar包:jave 1.0.2 jar 如果是maven项目,在pom.xml文件中添加: <dependency> <groupId>it.sauronsoftwar ...
- xtu数据结构 H. City Horizon
H. City Horizon Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java cl ...
- TOJ 2017: N-Credible Mazes
2017: N-Credible Mazes Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByteTotal Subm ...
- hihoCoder1381 - Little Y's Tree
Portal Description 给出一个\(n(n\leq10^5)\)个点的带边权的树.进行\(Q\)次询问:每次删除树上的\(k\)条边,求剩下的\(k+1\)个连通块中最远点对距离的和.\ ...
- 625. Minimum Factorization
Problem statement Given a positive integer a, find the smallest positive integer b whose multiplicat ...
- 记一次Jenkins 打包异常 ERROR: Exception when publishing, exception message [Failure]
今天早上打包一直都没有问题,突然有一次打包突然出现异常现象,如下: ERROR: Exception when publishing, exception message [Failure] Buil ...
- javaweb学习总结(八)——HttpServletResponse对象(二)(转)
(每天都会更新至少一篇以上,有兴趣的可以关注)转载自孤傲苍狼 一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedI ...
- 洛谷 P1756 最小花费
题目背景 题目描述 在n个人中,某些人的银行账号之间可以互相转账.这些人之间转账的手续费各不相同.给定这些人之间转账时需要从转账金额里扣除百分之几的手续费,请问A最少需要多少钱使得转账后B收到100元 ...