PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Problem when a sprite leaves the screen

Hi all,

I have noticed that if we draw a sprite and we move it slowly outside the screen, instead of disappearing smoothly, it disappears at once. I mean, as soon as a pixel is going to be outside the screen, the whole sprite will be hidden.

This is ok for small sprites, but if we have a big one, the effect is very bad.

Is there an easy way of avoiding this?

If you want to see this effect, open the example program MFC, and comment out the following lines, so the sprites will not bounce once they reach the end of the screen.

Code:
// Update direction X
if (koord.x < 2)
dir.x = 2;
else if (koord.x > (long)(dwScreenWidth - m_dwSpriteWidth - 2))
dir.x = -2;

// Update direction Y
if (koord.y < 2)
dir.y = 2;
else if (koord.y > (long)(dwScreenHeight - m_dwSpriteHeight - 2))
dir.y = -2;


Thanks
InexorableTash · 18 Apr 2007, 05:21 UTC
Short answer: call pDestinationSurface->SetClipper( NULL ) before you do any blting and you should be set.

The default behavior is that a Blt will fail if any part of the destination rectangle is offscreen. (Basically, you've passed in invalid coordinates!)

If you set a clipper (see http://www.gapidraw.com/docs/gapidraw/36/gapisurface-main.htm#SetClipper), the behavior changes so that if the destination rectangle is partially outside the clipping region, the source/destination rectangles are adjusted for you.
Thanks a million for your detailed answer and for explaining how it works.

I have tried your suggestion and it works great now.

Regards.