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

Author Topic: Sprite Pointer?  (Read 1868 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprite Pointer?
« on: January 08, 2020, 08:50:58 pm »
Hy how can i get a sprite as a pointer?

I've tried:

Sprite Piece_1;
Sprite* Selected_Piece;
Selected_Piece = Piece_1;

and it doesn't work.
it says that can't convert a Sprite to Sprite*;

I need this because I am making a game, and I need a pointer to a sprite, base on a switch(ID_Piesa) selected from multiples sprites;
If there is another way, can you tell me?


  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Sprite Pointer?
« Reply #1 on: January 09, 2020, 05:32:56 pm »
1- This is basic C++. I suggest reading a good book before doing anything like this if you don't know this.
2- Sprite are lightweight, texture are heavy. Just create a sprite on the fly.
3- Read 1 again. This is very basic C++ and you should know this before trying to make a game.
Code Concept
Rosme on IRC/Discord


  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Sprite Pointer?
« Reply #2 on: January 09, 2020, 11:19:06 pm »
i agree with Rosme about reading a c++ book. pointers and references are most important features in c++ language. if you had difficulties to grasp these concepts then you may consider to switch to other programming language that don't use low level features like java or c#.

to solve the compiler warning in you code, just assign the memory address of your main sprite to the pointer sprite by using the address-of "operator(&)" like this:

Selected_Piece = &Piece_1;

and you can use the pointer by dereference it. if you were needed it, with "operator(*)", like this:

window.draw(*Selected_Piece );
« Last Edit: January 09, 2020, 11:31:54 pm by Mortal »