|
Hi
i have a coin class in which i am creating a body of coin and giving it a linear velocity (because my plane's x-axis is constant and background is panning) to move code is:- -(void) createCoin:(ActionManager*)_objActionManager:(float)_x:(float)_y:(int)_no { b2BodyDef coinBodyDef; coinBodyDef.type = b2_kinematicBody; coinBodyDef.position.Set(_x/PTM_RATIO, _y/PTM_RATIO);//_x/PTM_RATIO, _y/PTM_RATIO coinBodyDef.userData = s_coin; //coinBodyDef.linearDamping = 1.5f;//2.7 //coinBodyDef.angularDamping = 1.5f;//3.0 m_coinBody = _objActionManager->world->CreateBody(&coinBodyDef); b2CircleShape circle; circle.m_radius = 10.0/PTM_RATIO; b2FixtureDef ballShapeDef; ballShapeDef.shape = &circle; ballShapeDef.density = 1.0f;//1 ballShapeDef.friction = 0.7f;//0.7 ballShapeDef.restitution = 0.0f;//0.5 ballShapeDef.isSensor = TRUE; m_coinFixt = m_coinBody->CreateFixture(&ballShapeDef);
float speed = _objActionManager->m_obstaclesSpeed; m_coinBody->SetLinearVelocity(b2Vec2(-(speed),0)); }
and m calling this function in my main game play layer (Action Manager)
-(id) init { if( (self=[super init])) { if(!m_objCoin) m_objCoin = [[Coins alloc]init]; } }
now i am calling my createCoin function with the help of m_objCoin when i need to show coins:
[m_objCoin createCoin:self :550 :_y :1];
|