-
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 : (http://image.noelshack.com/fichiers/2016/34/1472138395-grass.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: (http://image.noelshack.com/fichiers/2016/34/1472138496-screen-shot-2016-08-25-at-5-21-16-pm.png)
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.
-
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.
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.
-
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
-
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()
?
-
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;
}
-
Or you could simply store a sf::Vector2i position in IsoTile.
-
lol that's right, I'm too dumb x')