Hi all,
i'm trying to make a simple scrolling game with pg that moves automatic at constant speed.
I create the map with tiled and for every collidable tile i create i physics body like that:
//Create Collision with Objects
for (int x = 0; x < self.m_Map.mapSize.width; x++){
for (int y = 0; y < self.m_Map.mapSize.height; y++) {
//Tile GID
int tileGID = [self.m_MapMetaLevel tileGIDAt:ccp(x, y)];
if(tileGID){
//Dictionary
NSDictionary *properties = [self.m_Map propertiesForGID:tileGID];
if(properties){
//Collision
NSString *collision = [properties objectForKey:@"Collidable"];
//If Exists collision
if(collision && [collision isEqualToString:@"true"]){
//CCSprite
CCNode *label = [CCNode node];
//Create Body for Collision
CGRect rect = CGRectMake(self.m_Map.tileSize.width * x,
(self.m_Map.mapSize.height * self.m_Map.tileSize.height) - (self.m_Map.tileSize.height * y) - self.m_Map.tileSize.height,
self.m_Map.tileSize.width,
self.m_Map.tileSize.height);
CCPhysicsBody *physicsBody = [CCPhysicsBody bodyWithRect:rect
cornerRadius:0];
physicsBody.affectedByGravity = NO;
physicsBody.type = CCPhysicsBodyTypeStatic;
physicsBody.collisionType = @"ground";
[label setPhysicsBody:physicsBody];
[self.gameplayNode addChild:label];
}
}
}
}
}
and set the update method of my hero like that:
-(void)update:(CCTime)delta
{
[self.physicsBody applyImpulse:ccpMult(CGPointMake(180.0f, 0.0f), delta)];
}
when the hero runs on the ground, stops randomly each time it encounters a new PhysicsBody created with the code posted above.
Why this?