Hi guys.
I am newbie to Box2D.
I am using cocos2d-x-3.8.
I managed to import tile map and apply collision which I made in Tiled Map file (tmx).
I used Rectangle type and it is static.
I moved the map using Parralax Node.
Unfortunately, when I tried to move my character this collision on ground doesn't move either....
I used PTM_RATIO 64.
Tile Map per pixel is 32 x 32.
Codes for collision rectangle from Tile Map.
Code to move character.
Please help me guy.
I am newbie to Box2D.
I am using cocos2d-x-3.8.
I managed to import tile map and apply collision which I made in Tiled Map file (tmx).
I used Rectangle type and it is static.
I moved the map using Parralax Node.
Unfortunately, when I tried to move my character this collision on ground doesn't move either....
I used PTM_RATIO 64.
Tile Map per pixel is 32 x 32.
Codes for collision rectangle from Tile Map.
Code: Select all
auto position = Point(object["x"].asFloat() / PTMRATIO, object["y"].asFloat() / PTMRATIO);
float width = object["width"].asFloat() / PTMRATIO;
float height = object["height"].asFloat() / PTMRATIO;
b2PolygonShape *rectshape = new b2PolygonShape();
b2Vec2 vertices[4];
int vindex = 4;
vertices[0].x = position.x + 0.0f;
vertices[0].y = position.y + 0.0f;
vertices[1].x = position.x + 0.0f;
vertices[1].y = position.y + height;
vertices[2].x = position.x + width;
vertices[2].y = position.y + height;
vertices[3].x = position.x + width;
vertices[3].y = position.y + 0.0f;
rectshape->Set(vertices, vindex);
auto fix = new FixtureDef();
fix->fixture.shape = rectshape;
fix->fixture.density = 10;
fix->fixture.friction = 0.5;
fix->fixture.restitution = 0.6;
Code to move character.
Code: Select all
b2Vec2 force = b2Vec2(30, 30);
bodyHero->ApplyLinearImpulse(force, bodyHero->GetPosition(), true);
Please help me guy.