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

Author Topic: Need help passing sprite object as parameter in function  (Read 2803 times)

0 Members and 1 Guest are viewing this topic.

Charlie

  • Newbie
  • *
  • Posts: 10
    • View Profile
Need help passing sprite object as parameter in function
« on: June 15, 2011, 11:17:15 pm »
I'm not the best with C++ and was wondering how I can pass a sprite object as a parameter in a function.. I have an example below.
Note the example serves no purpose, I'm just wondering how this is executed correctly..

This is the function:
Code: [Select]

void SetX(sf::Sprite object)
{
object.SetX(100);
}


This is the call to the function:
Code: [Select]

SetX(Sprite3);

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Need help passing sprite object as parameter in function
« Reply #1 on: June 15, 2011, 11:30:17 pm »
Use references, if you don't want to copy the parameter.
Code: [Select]
sf::Sprite& object
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Charlie

  • Newbie
  • *
  • Posts: 10
    • View Profile
Need help passing sprite object as parameter in function
« Reply #2 on: June 15, 2011, 11:35:15 pm »
Thanks, that's what I needed. :)