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

Author Topic: tree sprite doesn't draw  (Read 1108 times)

0 Members and 1 Guest are viewing this topic.

AzkaIsHere

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
tree sprite doesn't draw
« on: April 18, 2018, 10:31:12 pm »
hello, I have a problem, my trees don't spawn in the map, this is the tree class:

class Tree
{
public:
   Tree(string directory)
   {
      t.loadFromFile(directory);
   }
   
   void treeTexture()
   {
      for (size_t i = 0; i < 1000; i++)
      {
         tree.setTexture(t);
         tree.setScale(1, 2);
      }
   }

   void treePosition()
   {
      for (size_t i = 0; i < 1000; i++)
      {
         tree.setPosition(rand() % 10560 + 0, rand() % 10560 + 0);
      }
   }

   void treeDraw(RenderWindow &app)
   {
      for (size_t i = 0; i < 1000; i++)
      {
         app.draw(tree);
      }
   }

private:
   Texture t;
   Sprite tree[1000];
};

and this is the main function:

Tree tree("shapes/world/tree.png");

tree.treeDraw(app);

can you tell me why I can't see them?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10901
    • View Profile
    • development blog
    • Email
Re: tree sprite doesn't draw
« Reply #1 on: April 19, 2018, 08:10:50 am »
You can't just use a for loop but never apply the index on the array. The posted code doesn't even compile.

You're using big random coordinates, so the trees might just be placed outside of your view.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AzkaIsHere

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: tree sprite doesn't draw
« Reply #2 on: April 19, 2018, 10:53:44 am »
the problem was that I didn't reference the treeposition and treetexture function in the main function outside of the loop, since it was inside, it repeatedly spawned trees in different positions so the result was I couldn't see them

 

anything