Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Inclination of objects from Tiled Map Editor  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

Azazel

  • Newbie
  • *
  • Posts: 6
    • View Profile
Inclination of objects from Tiled Map Editor
« on: September 13, 2017, 02:54:21 pm »
So, I drew in Tiled Map Editor an isometric map and add layers of object (see the pictures below in a hide).

Then I draw a map through the tinyXml , but with the objects there was a problem. Code I get from https://en.sfml-dev.org/forums/index.php?topic=3023.0 but modifies it somewhat for an isometric map. But I could not change the mapping of objects. To get the rect of my layer of objects, i use sf::Rect but i get an ortogonal rectangle
Object object;
object.name = objectName;
object.type = objectType;
object.sprite = sprite;

sf::Rect<float> objectRect;
objectRect.top = y;
objectRect.left = x;
objectRect.height = height;
objectRect.width = width;
object.rect = objectRect;

How can this rectangle of objects be tilted to isometric view?
(click to show/hide)
The white rectangle in the picture is the visualization of my layer of objects, that is, the way it looks in my code.
Full code here https://pastebin.com/U1NG8eKD
« Last Edit: September 13, 2017, 03:18:53 pm by Azazel »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11029
    • View Profile
    • development blog
    • Email
Re: Inclination of objects from Tiled Map Editor
« Reply #1 on: September 13, 2017, 07:51:35 pm »
The sf::Rect can't be tilted. Instead you'll have to write your own tile rect or similar class that uses the correct isometric math.
If you don't know how, you might want to check one of the various websites on isometric math.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Azazel

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Inclination of objects from Tiled Map Editor
« Reply #2 on: September 14, 2017, 06:19:57 pm »
So, i create my own "rectangle" with sf::Vertex. How i can check intersection of my Vertex(isometric) rectangle and a standart rectangle with sides parallel to the axes?
(click to show/hide)

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Inclination of objects from Tiled Map Editor
« Reply #3 on: September 14, 2017, 07:45:35 pm »
It sounds like your basic problem is that you want a way to check collisions between rotated rectangles? SFML doesn't provide a built-in way to do this, but you could implement the "separating axis theorem" for this. You can google that term to find a lot more information on it.