### Author Topic: Some ideas  (Read 2931 times)

0 Members and 1 Guest are viewing this topic.

#### peaman

• Newbie
• Posts: 8
##### Some ideas
« on: May 13, 2008, 01:38:04 pm »
It would be nice if Sprites had separate centers for scale, rotation, and position.
I also don't like it that when you scale a sprite, the rotation center doesn't stay in the  center of the sprite.

A function for checking overlaping of sprites would be nice. It should also consider scale and rotation of the sprites.

bool sf::Sprite::Collides(const fs::Sprite &s1, const fs::Sprite &s2);

So if two non-trasparent pixels of the sprites would overlap, the function would return true.

Btw why have Sprites a method called Scale() and another called SetScale()? Do they differ in any way?

#### SirJulio

• Full Member
• Posts: 241
##### Some ideas
« Reply #1 on: May 13, 2008, 01:59:08 pm »
Hi,

for the scaling stuffs, SetScale is an assign method (Doesn't matter how many times you call SetScale, the final scale wiil the last call), Scale (float, float) keep multiply the actual scale by the factor. Example :

Code: [Select]
`        sf::Image Image;    if (!Image.LoadFromFile("randomImage.bmp"))        return EXIT_FAILURE;    sf::Sprite Sprite(Image);    for(int i = 0; i < 3; i++)        Sprite.SetScale(1.1f, 1.1f);    // final scaling factor is 1.1, 1.1    //..    for(int i = 0; i < 3; i++)        Sprite.Scale(1.1f, 1.1f);    // final scaling factor is 1.331, 1.331`

The same logic apply to Move/SetPosition and Rotate/SetRotation.

For overlapping sprite, you could do it with a simple Sprite encapsulation and some Rect<T>.Intersects call.

#### quasius

• Full Member
• Posts: 166
##### Re: Some ideas
« Reply #2 on: May 13, 2008, 06:53:33 pm »
Quote from: "peaman"

A function for checking overlaping of sprites would be nice. It should also consider scale and rotation of the sprites.

bool sf::Sprite::Collides(const fs::Sprite &s1, const fs::Sprite &s2);

So if two non-trasparent pixels of the sprites would overlap, the function would return true.

What you are suggesting is insanely expensive.  That would likely never be done in a serious project, so putting it in SFML would be a bad idea.  Checking if the bounding boxes (axis-alligned or not) intersect is far more reasonable.  If you need something like per-pixel collision detection, you really need to write your own optimized routines.  You should be doing something like defining an approximate convex hull of the collidable part of the sprite and then doing a convex poly to convex poly collision test.
And as a further point, I'm not really sure collision detection belongs in SFML.  It's a media layer, not some kind of all-in-one game engine.  I'm sure there are plenty of 2D collision detection libraries out there if you don't want to learn it yourself.