Tiled Maps Collisions cpp;


how can my character not move through the “ground” layer.many thank

Are you using box2d as physcis engine? if yes, i recommend you to apply this class: Create Box2D bodies with TMX Objects layer! Cocos2d-x 3.0
But it doesn’t work for polylines and polygon shapes. The sizes are not correct.

Read my topic for more info (lastest posts): Problems with tiled maps
I’m fighting weeks ago about this problem
:frowning:

1 Like

Wouldn’t it be easier to use custom properties for that? In my opinion a complete physics engine is too much overhead. You can just test for collision and check the properties. I don’t have any source (because I didn’t need it), but I would do it this way. This way every object can be a blocker (also polylines and polygon shapes). It’s just an idea, but it will need more own code (or you find any existing).

1 Like

It did not work

thanks for your suggestions :slight_smile:

I tried adding physics to the "ground" layer.

From my point of view, if your game uses box2d as a physics engine, collisions must be managed by box2d.
You could use custom properties for each tile, but in this way the collisions are not detected in box2d world. I think conceptually that would be wrong.

That’s right. But what if you didn’t use box2d yet? The original poster didn’t mentioned box2d. :face_with_monocle:

I think if you develop a game, unless it’s very simple, a physics engine will be used. The example mentioned was with box2d but it applies to all physics engines that handle collisions :stuck_out_tongue:

The game that is mentioned in this post is obvious that it uses collisions :smile:
if the physics engine handles collisions (that is, all physics engines :smiley: ) the correct way is to handle collisions with the engine. It is my opinion.

I can code a game without any physics engine and with collisions. This game wouldn’t be “simple”, but I understand your point of view. As always, you can say: It depends… :wink:

1 Like

I would never develop my own collision manager. It’s like reinventing the wheel.
:yum:

1 Like

:rofl::rofl::rofl::rofl::rofl:
yep

ground tiled map

body player


It does not work well

As i said: it depends…

Sometimes it’s way more affective to have own code, because you know what happens. I saw many tripple A company videos on YouTube and they mostly didn’t use the std::string. Don’t know if it’s because of old codebase or because of speed, but it’s a fact, that they reinvent the wheel multiple times…

And I never wrote, that you shouldn’t use box2d. I only said, that sometime a simpler solution would be better for your custom needs :wink: If box2d works for you, it’s totally fine.

2 Likes