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

Author Topic: Get Size and Position of texture/sprite  (Read 1727 times)

0 Members and 1 Guest are viewing this topic.

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Get Size and Position of texture/sprite
« on: June 09, 2012, 10:46:19 pm »
Hello,

I'm trying to get position and size of sprite and texture but I'm getting this error:

error is on wsprintf...

Code: [Select]
Unhandled exception at 0x74df9d60 in Lucid Dreaming.exe: 0xC0000005: Access violation reading location 0x00000320.
part of code:

Vector2u PlayerSize = tBackground[0].getSize();
                                char test[512];
                                wsprintf(test, "%s", PlayerSize);
                                MessageBox(NULL, test, NULL, NULL);

and position is returnin NULL value

Vector2f PlayerPosition = sBackground.getPosition();
                                char test[512];
                                wsprintf(test, "%s", PlayerPosition);
                                MessageBox(NULL, test, NULL, NULL);

also is there any way to return them as int x,y?
« Last Edit: June 10, 2012, 01:56:25 am by SEnergy »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Get Size and Position of texture/sprite
« Reply #1 on: June 10, 2012, 10:08:06 am »
%s expects a null-terminated C string, nothing else (especially not a sf::Vector2).

Look at the documentation of the sf::Vector2 class to find out how to extract its x and y components.
Laurent Gomila - SFML developer

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Get Size and Position of texture/sprite
« Reply #2 on: June 10, 2012, 01:25:07 pm »
What you want is to use either %u (unsigned integer) or %f (float) for each of the X and Y values in the vector.

For example:
Vector2u PlayerSize = tBackground[0].getSize();
char test[512];
wsprintf(test, "%u, %u", PlayerSize.x, PlayerSize.y);
MessageBox(NULL, test, NULL, NULL);
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Get Size and Position of texture/sprite
« Reply #3 on: June 10, 2012, 01:28:18 pm »
Or better: use the C++ functions instead of this unsafe C stuff.

std::ostringstream oss;
oss << PlayerSize.x << PlayerSize.y;
std::string str = oss.str();
Laurent Gomila - SFML developer

 

anything