SFML community forums

Help => General => Topic started by: Petre2710 on January 08, 2020, 08:50:58 pm

Title: Sprite Pointer?
Post by: Petre2710 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?
Title: Re: Sprite Pointer?
Post by: Rosme 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.
Title: Re: Sprite Pointer?
Post by: Mortal 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 );