Jump to content
  • Advertisement
Sign in to follow this  

Magnetic Coin Effect

This topic is 2356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am developing physics based game using box2d in cocos2d-iphone. Can any one please help me in creating magnetic coin effect as it is in Temple run and Jet Pack game. In my game my character is a movable plane and the magnetic power appears from opposite direction and once it is collected then its effect remains for few seconds. And in that effect time if any coins are coming from opposite side of the plane then those coins should get attract towards the plane. And those coins are also a box2d body. Right now i am using the SetLinearVelocity to move it to the left end of the screen only changing the x position. In this the once the y position is set its not able to change it. So please any one can help me in this to make magnetic effect work. Any kind of help will be appreciated. Thank you very much.

Share this post

Link to post
Share on other sites
hi ndssia

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;


and m calling this function in my main game play layer (Action Manager)

-(id) init

if( (self=[super init]))

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];

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!