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

Author Topic: Isometric Maps Questions  (Read 2809 times)

0 Members and 1 Guest are viewing this topic.

yovano_c

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Isometric Maps Questions
« on: August 25, 2016, 05:44:33 pm »
Hello,
I've so many problems to implements isometric maps. It's looks good apparently but I have issues with colliding... i want to show the rect of the tile, and i cannot understand how to draw the rect for the iso tile of a 53*36 wide .png :

I use :

float size = sqrtf(powf((53 / 2), 2) + powf((36 / 2), 2));
mRect.setSize(sf::Vector2f(size, size));
mRect.rotate(45.f);
 

But it gives me this:

So, I have few questions :

1/ How can I put the blue rect, right onto the blue isometric tile?
2/ How can I implements the colliding system because look at the output console, it's colliding when the player rect goes underneath because the rect around the player goes over the blue rect even if the player is far away the real tile.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Isometric Maps Questions
« Reply #1 on: August 25, 2016, 08:08:36 pm »
Quote
1/ How can I put the blue rect, right onto the blue isometric tile?
Your tile is not rectangular, so good luck for covering it with a rotated rectangle ;)
You'd better compute the 4 corners separately and draw two simple triangles.

Quote
2/ How can I implements the colliding system because look at the output console, it's colliding when the player rect goes underneath because the rect around the player goes over the blue rect even if the player is far away the real tile.
Take a collision rectangle that only covers the player's feet. Or transform the player's position back to tile coordinates and check if the corresponding tile is walkable or not.
Laurent Gomila - SFML developer

yovano_c

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Isometric Maps Questions
« Reply #2 on: August 25, 2016, 09:37:21 pm »
Thanks for my first question, I will looking for the second now but I resolved it with that :

sf::Vector2f vec(0 * mSpriteWidth / 2, 2 * mSpriteWidth / 2);
    sf::Vector2f vec2(0, 0);
    vec2.x = vec.x - vec.y;
    vec2.y = (vec.y + vec.x) / 2;
    convex.setPosition(vec2);
    convex.setFillColor(sf::Color::Yellow);
    convex.setPointCount(4);
    convex.setPoint(0, sf::Vector2f(0, mSpriteHeight / 2));
    convex.setPoint(1, sf::Vector2f(mSpriteWidth / 2, 0));
    convex.setPoint(2, sf::Vector2f(mSpriteWidth, mSpriteHeight / 2));
    convex.setPoint(3, sf::Vector2f(mSpriteWidth / 2, mSpriteHeight));

It's simple, I forgot the height of the 3d way of the tile but it's looks very good

yovano_c

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Isometric Maps Questions
« Reply #3 on: August 26, 2016, 08:55:44 am »
Ih I have a function like this :

void IsoTile::setPositionOnMap(int x, int y)
{
    sf::Vector2f vec(x * mSpriteWidth / 2, y * mSpriteWidth / 2);
    sf::Vector2f vec2(0, 0);
    vec2.x = vec.x - vec.y;
    vec2.y = (vec.y + vec.x) / 2;
    convex.setPosition(vec2);
}
 


how can I implements the getter ->
const sf::Vector2i IsoTile::getPositionOnMap()
?

yovano_c

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Isometric Maps Questions
« Reply #4 on: August 26, 2016, 09:54:57 am »
I really don't know why but it seems to work :

const sf::Vector2f IsoTile::getPositionOnMap()
{
    int save = mSpriteWidth / 2;
    int det = save * save + save * save;
    sf::Vector2f pos = convex.getPosition();
    sf::Vector2f vec(0, 0);
    // x * save - y * save = pos.x;
    // y * save + x * save = pos.y * 2
    vec.x = vec.x = (-save * pos.y * 2 - save * pos.x) / det * -1;
    vec.y = (pos.x * save - pos.y * 2 * save) / det * -1;
    return vec;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Isometric Maps Questions
« Reply #5 on: August 26, 2016, 10:05:13 am »
Or you could simply store a sf::Vector2i position in IsoTile.
Laurent Gomila - SFML developer

yovano_c

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Isometric Maps Questions
« Reply #6 on: August 26, 2016, 10:22:59 am »
lol that's right, I'm too dumb x')

 

anything