SFML community forums
Help => General => Topic started by: wtf 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 :)
-
Most of those are moved to the Texture class or have either been renamed or removed altogether. Hope that helps. :)
-
Use the class list
http://www.sfml-dev.org/documentation/2.0/annotated.php
-
* 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()
-
* 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.
-
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.
-
In the doc..
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...