• (2 Pages)
  • +
  • 1
  • 2

Beginning SDL - Part 3 - A Sprite/Drawing Class

#16 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Posted 06 August 2013 - 01:13 AM

I didn't access the variable from the sprite class, I accessed it from within the game class.

// inside our Draw function
Sprite::Draw(m_pScreen, testSprite, 300, 300, 0, 0, 50, 50); // in the game class



You can blit anything using the sprite functions as they are public static functions. If you continue through the tutorials you will see that the game class becomes accessible from anywhere, making the m_pScreen variable also accessible.
Was This Post Helpful? 0
  • +
  • -

#17 reversiblean  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-August 13

Posted 06 August 2013 - 04:55 AM

View Poststayscrisp, on 06 August 2013 - 01:13 AM, said:

I didn't access the variable from the sprite class, I accessed it from within the game class.

// inside our Draw function
Sprite::Draw(m_pScreen, testSprite, 300, 300, 0, 0, 50, 50); // in the game class



You can blit anything using the sprite functions as they are public static functions. If you continue through the tutorials you will see that the game class becomes accessible from anywhere, making the m_pScreen variable also accessible.


Hi stayscrisp. Thanks for the quick reply. Now I get:
error: cannot call member function ‘SDL_Surface* Sprite::Load(std::string)’ without object
error: cannot call member function ‘void Sprie::Draw( .... without object

I can get it work by declaring Sprite object instead of declaring SDL_Surface* testSprite. But I feel like sort of making my life harder : )

Please note that I'm new to these OOP concepts.
Was This Post Helpful? 0
  • +
  • -

#18 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Posted 06 August 2013 - 05:30 AM

Sprite::Load returns an SDL_Surface* for you to use. Example usage:

SDL_Surface* mySurface = Sprite::Load("myimage");



Then to draw you use the other functions, you never have to declare or create an instance of Sprite

Sprite::Draw(m_pScreen, mySurface, 300, 300, 0, 0, 50, 50);


Was This Post Helpful? 0
  • +
  • -

#19 reversiblean  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-August 13

Posted 06 August 2013 - 05:54 AM

Oops, sorry I figured it out. I wasn't aware of that static keyword.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2