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

Author Topic: [SFML 2.0] Collision  (Read 7401 times)

0 Members and 1 Guest are viewing this topic.

wtf

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SFML 2.0] Collision
« on: February 20, 2012, 11:52:33 pm »
I am using SFML 2.0, and i need help with the collision class. i am attempting to use the collision class posted on the SFML website http://www.sfml-dev.org/wiki/en/sources/simple_collision_detection

Due to the new updates of SFML 2.0 it will not work so could some one help me fix this by providing what needs to be changed.

Things that do not work:
* TransformToGlobal()
* Offset()
* GetSubRect()
* GetWidth()
* GetHeight()
* TransformToLocal()
* GetPixel()
* GetSize()

Please help with the problums, or inform me of a alternate method.
-Thank you :)

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
[SFML 2.0] Collision
« Reply #1 on: February 21, 2012, 03:43:40 am »
Most of those are moved to the Texture class or have either been renamed or removed altogether. Hope that helps. :)
I have many ideas but need the help of others to find way to make use of them.

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
[SFML 2.0] Collision
« Reply #2 on: February 21, 2012, 04:23:24 am »
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
[SFML 2.0] Collision
« Reply #3 on: February 21, 2012, 11:28:39 am »
* GetSubRect(): use GetGlobalBounds() taking in account the transformations. GetLocalBounds() for to ignore the transforms.
* TransformToLocal() can now be done transforming a point using the inverse matrix ( sprite.GetInverseTransform().TransformPoint(p) )
* TransformToGlobal() same as above but with GetTransform(), not the inverse
* GetPixel() is still on Image class. If you use textures, first copy the texture to a image using CopyToImage()
* GetSize(), GetWidth(), GetHeight(): use the methods provided by the Texture class GetWidth() and GetHeight()

escher

  • Newbie
  • *
  • Posts: 8
    • View Profile
[SFML 2.0] Collision
« Reply #4 on: February 21, 2012, 08:00:42 pm »
Quote from: "julen26"
* GetPixel() is still on Image class. If you use textures, first copy the texture to a image using CopyToImage()


Most of the differences are easy changes if you read the docs, but this one concerns me a bit. The documentation specifically says that CopyToImage is slow (and it makes sense that it would be), so using this in a collision detection system seems like it might be a bad idea.

What the tutorial code is working with is an sf::Sprite object. Is there any way to directly access the pixel data from there? I can see a way using the GetTexture and GetTextureRect to work backwards, and then use sf::Texture's Pixels member to do the pixel-based comparison, but this seems kludgy.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
[SFML 2.0] Collision
« Reply #5 on: February 21, 2012, 08:13:54 pm »
Quote from: "escher"
The documentation specifically says that CopyToImage is slow (and it makes sense that it would be), so using this in a collision detection system seems like it might be a bad idea.
I think using sf::Texture in a collision system is generally a bad idea. If you do need pixel-perfect collision, maybe a bool array/matrix/bitset is the better choice.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
[SFML 2.0] Collision
« Reply #6 on: February 21, 2012, 08:14:38 pm »
In the doc..
Quote
Since they live in the graphics card memory, the pixels of a texture cannot be accessed without a slow copy first. And they cannot be accessed individually. Therefore, if you need to read the texture's pixels (like for pixel-perfect collisions), it is recommended to store the collision information separately, for example in an array of booleans.


It's a slow operation, but using the right technique it can be easy and fast.
http://www.sfml-dev.org/forum/viewtopic.php?t=6958

EDIT: Sorry, Nexus posted before...

 

anything