Note that there are some explanatory texts on larger screens.

plurals
  1. POBox2D and SneakyInput collision detection
    primarykey
    data
    text
    <p>I am creating a game, where there is a ball, and there are some rectangles, as they were tables.</p> <p>Well, it's working with Box2d, so I can move the ball freely with my SneakyInput joystick, and here is my problem:</p> <p>I have a "table" and my ball, made with LevelHelper and SpriteHelper. Everything seems to work properly here. My ball is dynamic and my table is kinematic (tried with static too). There is no gravity in my world.</p> <p>Well, when I'm moving the ball, it collides just for a second with the table, and it can't go through it for that second. After that, it does.</p> <p>I tried with the boxes that come with the Cocos2D HelloWorld file, and my ball does the same, collide with them for a second or so, and then I can go through them, and it won't collide again.</p> <p>Do you have any ideas?</p> <p>Here you have some code:</p> <pre><code>{ -(id) init { if( (self=[super init])) { self.isTouchEnabled = YES; // init physics b2Vec2 gravity = b2Vec2(0,0); world = new b2World(gravity); //load from level loader = [[LevelHelperLoader alloc] initWithContentOfFile:@"Level1"]; [loader addObjectsToWorld:world cocos2dLayer:self]; [self schedule: @selector(tick:) interval:1.0f/60.0f]; [self draw]; [self initJoystick]; //This load some example sprites for collisions // Use batch node. Faster CCSpriteBatchNode *parent = [CCSpriteBatchNode batchNodeWithFile:@"blocks.png" capacity:100]; spriteTexture_ = [parent texture]; // doesn't use batch node. Slower spriteTexture_ = [[CCTextureCache sharedTextureCache] addImage:@"blocks.png"]; CCNode *parent = [CCNode node]; [self addChild:parent z:0 tag:kTagParentNode]; [self scheduleUpdate]; } return self; } -(void) tick: (ccTime) dt{ //scaled velocity for joystick CGPoint scaledVelocity = ccpMult(joystick.velocity, 120); world-&gt;Step(dt, 10, 10); for (b2Body* b = world-&gt;GetBodyList();b; b=b-&gt;GetNext()){ CCSprite *myActor = (CCSprite*)b-&gt;GetUserData(); if (b-&gt;GetUserData() != NULL){ if (b-&gt;GetType() == b2_dynamicBody &amp;&amp; myActor == [loader spriteWithUniqueName:@"prota"]){ b-&gt;SetTransform(b2Vec2(b-&gt;GetPosition().x+scaledVelocity.x*dt/PTM_RATIO,b-&gt;GetPosition().y+scaledVelocity.y*dt/PTM_RATIO), 0); //move sprite to body position myActor.position = ccp(b-&gt;GetPosition().x * PTM_RATIO, b-&gt;GetPosition().y * PTM_RATIO); } } } } </code></pre> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload