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

Author Topic: Need help with tutorial "Designing your own entities with vertex arrays"  (Read 1851 times)

0 Members and 1 Guest are viewing this topic.

bisthebis

  • Newbie
  • *
  • Posts: 19
    • View Profile
Hi folks !
I'm using SFML since 2 days and I'm reading all official tutorials before doing any true project.
As a matter of practising, I've decided to improve the TileMap class of this tutorial.

I want to load a Tilemap from a picture instead of a int[]. So I'm overloading the load method :
bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);  //Tutorial original method
bool load(const std::string& tileset, sf::Vector2u tileSize, const sf::Image &tiles, unsigned int width, unsigned int height); //My new method

Here is the implementation :
bool load(const std::string& tileset, sf::Vector2u tileSize, const sf::Image &tiles, unsigned int width, unsigned int height)
{
    sf::Vector2u tailleImage = tiles.getSize();
    int* tiles_num = new int[tailleImage.x * tailleImage.y];
    for (int j = 0; j < tailleImage.y; j++)
    {
        for (int i = 0; i < tailleImage.x; i++)
        {
            tiles_num[i+j*tailleImage.x] = tiles.getPixel(i, j).r;
        }
    }
    this->load(tileset, tileSize, tiles_num[], width, height);
    bool ok =  true;
    delete tiles_num;
    return ok;


}

When compiling I get two errors :
-Invalid use of "this" in non-member function
-expected primary-expression before ']' token.

I understand none of them...
Could someone help me ? :)


PS : If i use the same algorithm outside of the object, it works... I guess I've messed with pointers
« Last Edit: August 01, 2015, 09:07:43 pm by bisthebis »

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
The function you've given is not declared as a member function, so you cannot use this, because this returns a pointer to the instance which this function is being called from. It is not a member function so is not being called from an object so no this. Secondly when you pass tiles_num in the same line as the this, you use the index operator with no index given.

bisthebis

  • Newbie
  • *
  • Posts: 19
    • View Profile
Thanks, I feel stupid to have missed the member delcaration  ;D
About the array, I removed the [] and it works.

Thousand of thanks :)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
I've decided to improve the TileMap class of this tutorial.
I disagree with this statement as saving the level data in an image seems wasteful whereas saving the level data as raw bytes seems to make much more sense  :D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

bisthebis

  • Newbie
  • *
  • Posts: 19
    • View Profile
Well I guess you're right. Though when I said "improving", it only meant "adding more methods" ^^
I'm not working on any serious project, so optimisation feels more like sa good habit than a necessity

 

anything