0
\$\begingroup\$

I'm quite experimented in objective C, but now i'm tried cocos2D and his features.

I need to add a body on a spritesheet (if possible on a classic 'UIImageView'), in order to detect collisions after.

Is there a way to create a box2D body, and that it suits sprite position ?

Because i wrote :

-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    CGPoint current = myUIImageView.center;
    int accelerator = 25;
    if (current.y > 70 && current.y < 407)
    {
        current.y -= acceleration.y*accelerator;
    }
    else if (current.y <= 70)
    {
        if (acceleration.y < 0)
        {
            current.y -= acceleration.y*accelerator;
        }
    }
    else if (current.y >= 407)
    {
        if (acceleration.y > 0)
        {
            current.y -= acceleration.y*accelerator;
        }
    }
    myUIImageView.center = current;
}

and found some codes, but looks very hard...

Thanks for your help !

\$\endgroup\$
1
\$\begingroup\$

Have you looked into CCPhysicsSprite?

Otherwise you can use the b2body.userData pointer to store sprite information after you've created your physics body.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.