Josheir said:
Note the left and right marioSprites
You need to decouple your low level resource handling from the rest of the game. Sprite stuff should be in the resource loader and drawing code only.
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Josheir said:
Note the left and right marioSprites
You need to decouple your low level resource handling from the rest of the game. Sprite stuff should be in the resource loader and drawing code only.
Josheir said:
I am making a different character move using the original function so I need pointers to use the sprite and positioning, etc.
No, use polymorphism if nothing else.
That's all fine and all, being more organized using the polymorphism, and it is great.
My other real problem is that I am passing each sprite to one function (move/draw) at different times. The program is working really weird and just displays the changes using the first image when both images are on the screen and the functions parameters are for the other.
Is this more understandable?
Josheir
Josheir said:
I am passing each sprite to one function (move/draw) at different times.
Let's say you have a player that has a life meter. Based on the life meter, the character looks more and more bloody. In your game logic you have a variable βhealthβ. In your draw code you display the correct graphic based on the health variable. You do not send the graphic (sprite) around your game logic. Never.
In your game logic, you should have variables that tell if the character is facing left/right. Is jumping. ect. The drawing code can take information from the game logic. The game logic should know zero about what is being drawn. Separate those 2 concerns. Imagine the game logic as not existing at all on the screen.
I will decouple, but for the ongoing program I want to make sure that :
void Foo(sf::sprite & r_p);
Foo (a_different_sprite);
is valid and can be called with different values? I know it is stupid and takes a second to answer with yes or no. I am considering refactoring.
Josheir
I think the reason for the coupling in the first place is that SF::Sprite has convenient member functions like setPosition().
Josheir
Josheir said:
I want to make sure that : void Foo(sf::sprite & r_p); Foo (a_different_sprite); is valid and can be called with different values?
If sprite is a game object class and more than just a resource then it's probably ok to pass it in game logic. I don't like it being called sprite but anyway...
I don't see any problem with the quoted code. If you don't want the Foo function to change the sprite object, use const correctness.
void Foo(const sf::sprite & r_p);