当前位置: 首页>>代码示例>>C++>>正文


C++ CCPhysicsSprite类代码示例

本文整理汇总了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
}
开发者ID:b4lr0g,项目名称:nativeclient-sdk,代码行数:29,代码来源:LuaCocos2dExtensions.cpp

示例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 );
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:35,代码来源:TestBox2D.cpp

示例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
}
开发者ID:b4lr0g,项目名称:nativeclient-sdk,代码行数:29,代码来源:LuaCocos2dExtensions.cpp

示例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;
}
开发者ID:0309,项目名称:cocos2d-x,代码行数:14,代码来源:CCPhysicsSprite.cpp

示例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
}
开发者ID:S74390E2,项目名称:dd_Sudoku,代码行数:44,代码来源:HelloWorldScene.cpp

示例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);
}
开发者ID:LiYuandong,项目名称:Parkour,代码行数:20,代码来源:Runner.cpp

示例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
}
开发者ID:645286681,项目名称:cocos2d-x,代码行数:38,代码来源:ChipmunkTest.cpp


注:本文中的CCPhysicsSprite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。