Results 1 to 5 of 5

Thread: Problem with the SDL_BlitSurface function

  1. #1

    Problem with the SDL_BlitSurface function

    Hello,

    I'm writing a side scrolling game and basically change the x-coordinate
    of every sprite each frame. I used this technique in my previous
    scroller called Cavern Fighter. Each sprite keeps having its
    x-coordinate decremented until it disappears off the left side of the
    screen and is no longer visible. In the game I'm working on at the
    moment I'm using the same method but have come across a strange problem.
    When my sprite gets to the left edge of the screen the x-coordinate
    starts to go negative. Unfortunately the "SDL_BlitSurface" function
    seems to convert the negative number back to a zero so the sprite never
    scrolls off the screen. Although this creates in interesting effect as
    all the sprites pile-up like some sort of sprite car crash, its not what
    I want.

    Has SDL changed to implement some sort of clipping ? Do I need to set a
    flag ? The version of SDL.dll I am using is 1.2.12.0.

    The function I am using is:

    SDL_BlitSurface (Sprite.ImageSurface, Sprite.ImageDisplayRect,
    m_SDLSurface, Sprite.ImageLocationRect) ;

    When I call it with the Sprite.ImageLocationRect (with an "x" value of
    -1), after the function exits the "x" holds a value of 0.

    Hope someone can help or I'll have to rename my game "Cavern Crash" :roll:

    Ian

  2. #2

    Problem with the SDL_BlitSurface function

    Hi Ian,

    I assume you store sprite location in Sprite.ImageLocationRect variable and you do a "Sprite.ImageLocationRect.x = Sprite.ImageLocationRect.x - 1" to scroll left. This is a bad idea IMHO, because SDL_BlitSurface writes back its info into this variable. That's why there is a 0 in Sprite.ImageLocationRect.x. It writes back the clipped/visible region of this rectangle. 0 is leftmost position you can see on the screen...
    (I hope I'm right, I didnt use SDL since years...)
    Cheers,
    KiCHY
    KiCHY

  3. #3

    Problem with the SDL_BlitSurface function

    I think you have spotted the problem. I was thinking that I was passing in a copy of the sprites location but I'm actually giving it the "live" version. I'll check my code but I'm sure that's what I'm doing as it makes sense that its resetting the Sprites property Should be easy to fix. Thanks for that, I was left scratching my head on that one.

  4. #4

    Problem with the SDL_BlitSurface function

    Quote Originally Posted by KiCHY
    (I hope I'm right, I didnt use SDL since years...)
    Cheers,
    KiCHY
    And the JEDI-SDL has not been the same since. Great to see you on here though.

    Ian, your photo is a lot more feminine than I usually associate with people called Ian. I'll have to change my preconceived ideas about names.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  5. #5

    Problem with the SDL_BlitSurface function

    Quote Originally Posted by savage
    Ian, your photo is a lot more feminine than I usually associate with people called Ian. I'll have to change my preconceived ideas about names.
    I can assure you that members of the PGD site would much rather look at an image of the lovely Sarah Beeny than a dodgy image of me . If anyone is really interested in what I look like you may just be able to see me as I flash past driving a rally prepped Subaru Impreza. There is a short video on my website (shameless plug :roll: )

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •