SFML texture usage issue

£可爱£侵袭症+ 提交于 2020-01-21 19:17:50

问题


I want to make a tilemap but when I run this code, the tiles becomes white, the texture has a problem. I know it that from the sf::Texture reference here says that the texture must exist in order to that the sprite can use it. But I dont know how to make it possible.
Here's the code:

class Tile
{
private:
sf::Sprite sprite;
sf::Texture tex;

public:
     Tile(int x, int y, sf::Texture tex)
    {
this->tex = tex;
this->sprite.setTexture(this->tex);
this->sprite.setPosition(x, y);

    }
    void render(sf::RenderWindow* target)
    {
    target->draw(this->sprite);
    }


class Tilemap
{
private:
Tile tiles[36][64];
sf::Texture tex[4];

public:
//const/dest
Tilemap()
{
this->tex[0].loadFromFile("Resources/Tilemap/Water/water1.png");

int x = -WIDTH+WIDTH/2;
int y = -HEIGTH/2;
for (int i = 0; i < 36; i++)
{
    for (int j = 0; j < 64; j++)
    {
        this->tiles[i][j] = Tile(x, y, this->tex[0]);
        x += 60;
    }
    y += 60;
    x = -WIDTH + WIDTH / 2;
}

}


render(sf::RenderWindow* target, sf::Vector2f pos)
{
for (int i = 0; i < 34; i++)
{
    for (int j = 0; j < 64; j++)
    {
        this->tiles[i][j].render(target);
    }
}
 };
 Tilemap map;
 map = Tilemap();

Thank you in advance for any answers :)

来源:https://stackoverflow.com/questions/59669702/sfml-texture-usage-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!