コード例 #1
0
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
0
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
0
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
0
ファイル: CCPhysicsSprite.cpp プロジェクト: 0309/cocos2d-x
CCPhysicsSprite* CCPhysicsSprite::createWithSpriteFrame(CCSpriteFrame *pSpriteFrame)
{
    CCPhysicsSprite* pRet = new CCPhysicsSprite();
    if (pRet && pRet->initWithSpriteFrame(pSpriteFrame))
    {
        pRet->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(pRet);
    }

    return pRet;
}
コード例 #5
0
ファイル: CCPhysicsSprite.cpp プロジェクト: 0309/cocos2d-x
CCPhysicsSprite* CCPhysicsSprite::createWithTexture(CCTexture2D *pTexture, const CCRect& rect)
{
    CCPhysicsSprite* pRet = new CCPhysicsSprite();
    if (pRet && pRet->initWithTexture(pTexture, rect))
    {
        pRet->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(pRet);
    }

    return pRet;
}
コード例 #6
0
ファイル: CCPhysicsSprite.cpp プロジェクト: 0309/cocos2d-x
CCPhysicsSprite* CCPhysicsSprite::create()
{
    CCPhysicsSprite* pRet = new CCPhysicsSprite();
    if (pRet && pRet->init())
    {
        pRet->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(pRet);
    }
    
    return pRet;
}
コード例 #7
0
ファイル: CCPhysicsSprite.cpp プロジェクト: 0309/cocos2d-x
CCPhysicsSprite* CCPhysicsSprite::create(const char *pszFileName, const CCRect& rect)
{
    CCPhysicsSprite* pRet = new CCPhysicsSprite();
    if (pRet && pRet->initWithFile(pszFileName, rect))
    {
        pRet->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(pRet);
    }

    return pRet;
}
コード例 #8
0
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
}
コード例 #9
0
ファイル: Runner.cpp プロジェクト: LiYuandong/Parkour
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);
}
コード例 #10
0
ファイル: ChipmunkTest.cpp プロジェクト: 645286681/cocos2d-x
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
}