πŸŽ‰ Celebrating 25 Years of GameDev.net! πŸŽ‰

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!

References can't be used with more than one variable.

Started by
24 comments, last by Josheir 4Β years, 1Β month ago

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.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Advertisement

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.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

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.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

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

This is SFML.

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);

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Now, finally, can you tell me about this:

void Foo(sf::sprite * p_sprite);

Foo(sf::sprite & anotherSprite);

Thanks.

Josheir

Couldn't edit again.

EDIT:

Foo(& anotherSprite);

This topic is closed to new replies.

Advertisement