本文整理汇总了C++中CCPhysicsSprite类的典型用法代码示例。如果您正苦于以下问题:C++ CCPhysicsSprite类的具体用法?C++ CCPhysicsSprite怎么用?C++ CCPhysicsSprite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCPhysicsSprite类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tolua_extensions_CCPhysicsSprite_setPTMRatio00
static int tolua_extensions_CCPhysicsSprite_setPTMRatio00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCPhysicsSprite",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
CCPhysicsSprite* self = (CCPhysicsSprite*) tolua_tousertype(tolua_S,1,0);
float fPTMRatio = ((float) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setPTMRatio'", NULL);
#endif
{
self->setPTMRatio(fPTMRatio);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'setPTMRatio'.",&tolua_err);
return 0;
#endif
}
示例2: CCRANDOM_0_1
KDvoid TestBox2D::addNewSpriteWithCoords ( const CCPoint& tPosition )
{
// Define the dynamic body.
//Set up a 1m squared box in the physics world
b2BodyDef tBodyDef;
tBodyDef.type = b2_dynamicBody;
tBodyDef.position.Set ( tPosition.x / PTM_RATIO, tPosition.y / PTM_RATIO );
//tBodyDef.userData = sprite;
b2Body* pBody = m_pWorld->CreateBody ( &tBodyDef );
// Define another box shape for our dynamic body.
b2PolygonShape tDynamicBox;
tDynamicBox.SetAsBox ( 0.5f, 0.5f );
// Define the dynamic body fixture.
b2FixtureDef tFixtureDef;
tFixtureDef.shape = &tDynamicBox;
tFixtureDef.density = 1.0f;
tFixtureDef.friction = 0.3f;
pBody->CreateFixture ( &tFixtureDef );
CCNode* pParent = this->getChildByTag ( kTagParentNode );
// We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
// just randomly picking one of the images
KDint nOffsetX = ( CCRANDOM_0_1 ( ) > 0.5f ? 0 : 1 );
KDint nOffsetY = ( CCRANDOM_0_1 ( ) > 0.5f ? 0 : 1 );
CCPhysicsSprite* pSprite = CCPhysicsSprite::createWithTexture ( m_pSpriteTexture, ccr ( 32 * nOffsetX, 32 * nOffsetY, 32, 32 ) );
pParent->addChild ( pSprite );
pSprite->setB2Body ( pBody );
pSprite->setPTMRatio ( PTM_RATIO );
pSprite->setPosition ( tPosition );
}
示例3: tolua_extensions_CCPhysicsSprite_setB2Body00
static int tolua_extensions_CCPhysicsSprite_setB2Body00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCPhysicsSprite",0,&tolua_err) ||
!tolua_isusertype(tolua_S,2,"b2Body",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
CCPhysicsSprite* self = (CCPhysicsSprite*) tolua_tousertype(tolua_S,1,0);
b2Body* pBody = ((b2Body*) tolua_tousertype(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setB2Body'", NULL);
#endif
{
self->setB2Body(pBody);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'setB2Body'.",&tolua_err);
return 0;
#endif
}
示例4: CCPhysicsSprite
CCPhysicsSprite* CCPhysicsSprite::createWithSpriteFrame(CCSpriteFrame *pSpriteFrame)
{
CCPhysicsSprite* pRet = new CCPhysicsSprite();
if (pRet && pRet->initWithSpriteFrame(pSpriteFrame))
{
pRet->autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
示例5: addChild
void HelloWorld::addPhysicSprite() {
#if CC_ENABLE_CHIPMUNK_INTEGRATION
// Use batch node. Faster
CCSpriteBatchNode *parent = CCSpriteBatchNode::create(s_SpinPea, 100);
m_pSpriteTexture = parent->getTexture();
addChild(parent, 100, kTagParentNode);
CCPoint pos = ccp(200,200);
int posx, posy;
CCNode *parent = getChildByTag(kTagParentNode);
posx = CCRANDOM_0_1() * 200.0f;
posy = CCRANDOM_0_1() * 200.0f;
posx = (posx % 4) * 85;
posy = (posy % 3) * 121;
int num = 4;
cpVect verts[] = {
cpv(-24,-54),
cpv(-24, 54),
cpv( 24, 54),
cpv( 24,-54),
};
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));
body->p = cpv(pos.x, pos.y);
cpSpaceAddBody(m_pSpace, body);
cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
shape->e = 0.5f; shape->u = 0.5f;
cpSpaceAddShape(m_pSpace, shape);
CCPhysicsSprite *sprite = CCPhysicsSprite::createWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121));
parent->addChild(sprite,50);
sprite->setCPBody(body);
sprite->setPosition(pos);
#endif
}
示例6: m_offsetPx
Runner::Runner(cpSpace* space)
: m_offsetPx(150.0)
{
this->space = space;
this->shape = NULL;
this->initWithSpriteFrameName("runner0.png");
CCPhysicsSprite* tmpSprite = CCPhysicsSprite::createWithSpriteFrameName("runnerCrouch0.png");
m_runningSize = this->getContentSize();
m_crouchSize = tmpSprite->getContentSize();
m_state = RunnerStateRunning;
initBody();
initShape(RUNING_MODE);
initAction();
this->setCPBody(body);
this->runAction(m_actionRunning);
}
示例7: getChildByTag
void ChipmunkTestLayer::addNewSpriteAtPosition(CCPoint pos)
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION
int posx, posy;
CCNode *parent = getChildByTag(kTagParentNode);
posx = CCRANDOM_0_1() * 200.0f;
posy = CCRANDOM_0_1() * 200.0f;
posx = (posx % 4) * 85;
posy = (posy % 3) * 121;
int num = 4;
cpVect verts[] = {
cpv(-24,-54),
cpv(-24, 54),
cpv( 24, 54),
cpv( 24,-54),
};
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));
body->p = cpv(pos.x, pos.y);
cpSpaceAddBody(m_pSpace, body);
cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
shape->e = 0.5f; shape->u = 0.5f;
cpSpaceAddShape(m_pSpace, shape);
CCPhysicsSprite *sprite = CCPhysicsSprite::createWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121));
parent->addChild(sprite);
sprite->setCPBody(body);
sprite->setPosition(pos);
#endif
}