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

Author Topic: Drawing New Graphics  (Read 2037 times)

0 Members and 1 Guest are viewing this topic.

hthornto

  • Newbie
  • *
  • Posts: 7
    • View Profile
Drawing New Graphics
« on: January 31, 2017, 02:22:07 am »
I am creating a simple rock paper scissors game. When the player wins or loses, the screen should clear and the words loser or wins appears on the screen. I am able to draw the rock paper scissors; however, it will not clear the screen and draw the new texts. Instead the debugger breaks the program. I am not sure how to fix this issue.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Drawing New Graphics
« Reply #1 on: January 31, 2017, 03:38:55 am »
Since you should be clearing and drawing on every cycle, to draw something different, continue clearing but draw different things.

Instead the debugger breaks the program. I am not sure how to fix this issue.
It doesn't clear but it crashes? What does the debugger say/do? Which issue?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

hthornto

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing New Graphics
« Reply #2 on: January 31, 2017, 04:08:26 am »
My render function looks like this:
   texture.clear();
   if (win == true)
   {
      texture.draw(_results.loadText("Win"));
   }
   else if (lose == true)
   {
      texture.draw(_results.loadText("Loser"));
   }
   else
   {

      texture.draw(_scissors.scisssorsdraw());
      texture.draw(_rock.rockDraw());
      texture.draw(_paper.paperDraw());
   }
      texture.display();
      
      _render.clear();
      sf::Sprite sprite(texture.getTexture());

      _render.draw(sprite);
      _render.display();


The debugger gives this
+      this   0x006ff1a0 {_render={...} _mouse={...} _events={type=MouseButtonPressed (9) size={width=0 height=305 } ...} ...}   MainGame *
+      sprite   {m_vertices=0x006fdf34 {{position={x=-107374176. y=-107374176. } color={r=204 'Ì' g=204 'Ì' b=204 'Ì' ...} ...}, ...} ...}   sf::Sprite

« Last Edit: January 31, 2017, 04:17:49 am by hthornto »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Drawing New Graphics
« Reply #3 on: January 31, 2017, 04:19:25 am »
What's the issue?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

hthornto

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing New Graphics
« Reply #4 on: January 31, 2017, 04:23:40 am »
It breaks with an error at this point I do not understand right after trying to draw the text.  I am thinking it is the redrawing. Maybe it is the text code. I am including the loading text function that I created.
sf::Text& WinLost::loadText(std::string messange)
 {
   
   
   
   
   
   text.setFont(loadFont("Fonts/chintzy.ttf"));
   
   
   text.setString(messange);
   text.setPosition(80, 90);
   text.setCharacterSize(24);
   
   return text;
}


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Drawing New Graphics
« Reply #5 on: January 31, 2017, 04:37:07 am »
The font needs to exist even after the function ends. You should store it elsewhere and pass it into (make available to) this function.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

hthornto

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing New Graphics
« Reply #6 on: January 31, 2017, 05:57:18 am »
Thanks, it made a big difference.

 

anything