SFML community forums

Help => Graphics => Topic started by: CL90 on February 08, 2012, 04:17:12 pm

Title: sf::Sprite -> function
Post by: CL90 on February 08, 2012, 04:17:12 pm
hi there!

is it possible to give a pointer to a sf::Sprite into a function?

something like that (verry simple overview):
Code: [Select]
int main(){
  sf:Sprite ship(Image);
  function(ship);
  App.Draw(ship);

  return 0;
}



function(??? *ship){
   .... // calculate something...
   ship.SetRotation(mov.angactual);
}



what typ of pointer is a sf:Sprite? is it a Multipointer?
Title: sf::Sprite -> function
Post by: Zinlibs on February 08, 2012, 04:40:27 pm
hello !

yes of course :
Code: [Select]

int main()
{
  sf:Sprite ship(Image);
  function(&ship);
  App.Draw(ship);

  return 0;
}

void function(sf::Sprite *ship)
{
   .... // calculate something...
   ship->SetRotation(mov.angactual);
}


but this is better with a reference :
Code: [Select]

int main()
{
  sf:Sprite ship(Image);
  function(ship);
  App.Draw(ship);

  return 0;
}

void function(sf::Sprite &ship)
{
   .... // calculate something...
   ship.SetRotation(mov.angactual);
}
Title: sf::Sprite -> function
Post by: CL90 on February 08, 2012, 05:32:08 pm
thanks!

works perfectly =)

nice to have some people here around! =)