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

Author Topic: copy a subrect to a new sf::Sprite?  (Read 2013 times)

0 Members and 1 Guest are viewing this topic.

sammyF

  • Newbie
  • *
  • Posts: 7
    • View Profile
copy a subrect to a new sf::Sprite?
« on: April 01, 2011, 01:35:37 pm »
In SFML1.6, is there any way to create a new sf::Sprite out of a subrect? I'm currently trying to modify the collision detection routine from the wiki so that it doesn't try to do pixel perfect collision detection of the whole sheet.

bbye,
Sammy

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
copy a subrect to a new sf::Sprite?
« Reply #1 on: April 01, 2011, 01:54:17 pm »
Quote
In SFML1.6, is there any way to create a new sf::Sprite out of a subrect?

What do you mean? Every sprite has a sub-rect, you can set it with SetSubRect.

Quote
I'm currently trying to modify the collision detection routine from the wiki so that it doesn't try to do pixel perfect collision detection of the whole sheet.

Which source code is it? I don't remember seeing a code that behaves this way.
Laurent Gomila - SFML developer

sammyF

  • Newbie
  • *
  • Posts: 7
    • View Profile
copy a subrect to a new sf::Sprite?
« Reply #2 on: April 01, 2011, 02:25:35 pm »
I mean this one : http://www.sfml-dev.org/wiki/en/sources/simple_collision_detection . From the warnings it sends, it looks like it is using *all* the pixels of the 1024x128 image sequence the sprite is subRect'd from, instead of just checking the current subRect.
So I thought about creating a new image out of the subRect, and send THAT instead to the Collision::PixelPerfect (which is what I was asking about)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
copy a subrect to a new sf::Sprite?
« Reply #3 on: April 01, 2011, 02:48:58 pm »
So you want to create an image, not a sprite. You must use sf::Image::Copy.

But the original source code doesn't use all the pixels, only those contained in the intersection rectangle:
Code: [Select]
       for (int i = Intersection.Left; i < Intersection.Right; i++) {
            for (int j = Intersection.Top; j < Intersection.Bottom; j++) {
Laurent Gomila - SFML developer

sammyF

  • Newbie
  • *
  • Posts: 7
    • View Profile
copy a subrect to a new sf::Sprite?
« Reply #4 on: April 01, 2011, 03:29:19 pm »
Yep! That's what I was looking for! thanks :)

 

anything