No I think you don't understand me, or i don't understand you :'/
I Have already done:
- Gray tiles are not walkable tiles
- white tiles are walkable tiles
- blue tile is the player tile
I want to move the player with pathfinding to the correct tile when mouse clicked into one tile.
I implement the tile system position on map -> real world with this function :
void IsoTile::setPositionOnMap(int x, int y)
{
mPositionInMap.x = x;
mPositionInMap.y = y;
if (y % 2 == 1)
{
mPositionInWindow.x = x * mSpriteWidth + mSpriteWidth / 2;
mPositionInWindow.y = y * mSpriteHeight / 2;
}
else
{
mPositionInWindow.x = x * mSpriteWidth;
mPositionInWindow.y = y * mSpriteHeight / 2;
}
mPositionInWindow.x *= mScale.x;
mPositionInWindow.y *= mScale.y;
mSprite.setScale(mScale);
mConvex.setScale(mScale);
mSprite.setPosition(mPositionInWindow);
mConvex.setPosition(mPositionInWindow);
}
PS: mScale is a vector2f that includes the width/height of the tiles and width/height of the window.
So, if I works like you tell me with coordinates it won"t work because there is 4 transparent edge include in each IsoTile.
and for the convexshape at the isotile initialization:
mConvex.setOutlineColor(sf::Color::Red);
mConvex.setOutlineThickness(0.8);
mConvex.setPointCount(4);
mConvex.setPoint(0, sf::Vector2f(0, mSpriteHeight / 2));
mConvex.setPoint(1, sf::Vector2f(mSpriteWidth / 2, 0));
mConvex.setPoint(2, sf::Vector2f(mSpriteWidth, mSpriteHeight / 2));
mConvex.setPoint(3, sf::Vector2f(mSpriteWidth / 2, mSpriteHeight));
IsoTile.hpp
#include "Entity.hpp"
class IsoTile: public Entity
{
private:
sf::Vector2i mPositionInMap;
sf::Vector2f mPositionInWindow;
sf::Vector2f mScale;
public:
bool isWalkable = true;
int mId = -1;
IsoTile();
IsoTile(int tileWidth, int tileHeight);
const sf::Vector2f getPositionInWindow() { return mPositionInWindow; };
const sf::Vector2f getTileScale() { return mScale; };
const sf::Vector2i getPositionOnMap() { return mPositionInMap; }
void setPositionOnMap(int x, int y);
void setPositionOnMap(sf::Vector2i &position);
void setId(int id);
int getId() { return mId; };
void setTexturePosition(int x, int y);
void setDimension(int width, int height);
void setDimension(sf::Vector2i dim);
static int getIdWithPosition(int x, int y);
};
Entity.hpp
#include <vector>
#include <cmath>
#include <iostream>
#include <SFML/Graphics.hpp>
enum Direction { Up, Down, Left, Right };
class Entity
{
public:
sf::Sprite mSprite;
sf::ConvexShape mConvex;
int mSpriteWidth = 50;
int mSpriteHeight = 50;
Direction mDirection;
Entity();
Entity(int width, int height);
void setDimension(int width, int height);
void setDimension(sf::Vector2i dim);
void update();
};