I searched everywhere, even planet source code doesn't have anything on the subject. Is it even possible? I know there is a sample on dx4vb but I can't use that cause my engine is very different. Anybody know how clippers can be used in fullscreen mode so that the sprites don't just disappear off screen when they get to the edge, but leave gradualy?
Normally, most people do their own clipping in full-screen games. The DirectDrawClipper usually slows down a game more than implementing your own clipping.
Sorry from bringing this thread back, but how would you go about making your own clipping? Would you need to detect when the sprite is about to leave the screen area and then somehow gradually chop it off so that the edge of the sprite never touches the edge of the screen? How would you do that? Just subtract from the right and left properties of the sprite?
Thanks, but I don't understand what I should replace the (OBJECT) with in the last line
I've replaced ScreenWidth and ScreenHeight with 800 and 600 cause thats the resolution my game uses. Then I replaced nWidth and nHeight with the width and height of my object I'm trying to clip. I've changed "With RECT_OF_OBJECT" to With "rBlock1"
But what do you mean by Render (OBJECT) if I replace it with "Block1" which I defined as Dim Block1 As DirectDrawSurface7
it gives me an error, if I replace it with "rBlock1" which is the rect, I also get an error. What should I put in there?
Originally posted by Sastraxi I've got an EXTREMELY efficient piece of clipping code for VB. It's as efficient as I can get it, anyway...
VB Code:
Dim ObjRect As RECT
Dim ScreenRect As RECT
Dim visix As Boolean, visiy As Boolean, visix2 As Boolean, visiy2 As Boolean, visi As Boolean
With ScreenRect
.Right = ScreenWidth - 1
.Bottom = ScreenHeight - 1
End With
With RECT_OF_OBJECT
'add in your data
visix = ((Abs(.Left) - .Left) = 0)
visiy = ((Abs(.Top) - .Top) = 0)
visix2 = Not (.Right >= ScreenRect.Right)
visiy2 = Not (.bottom >= ScreenRect.Bottom)
visi = visix And visix2 And visiy And visiy2
End With
If visi Then You_Can_Render_This_Object_So_Do_So!
I've changed a few things (nWidth = ScreenRect.Right, nHeight = ScreenRect.Bottom), and I think I've now made it perfectly clear what I mean by Render(OBJECT)
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Just remembered something. If you want this to be a clipper, you need to change all RECT_OF_OBJECT.Right with .Left, .Bottom with .Top (but only for that RECT). I copied this code from one where this was used to check collision with the wall.
And here's the logic:
visix: If the absolute (above zero) version of the number is different than the original version, it's under 0 (non-absolute), and thus shouldn't be drawn.
visiy: same as visix, on the y axis
visix2: If the number is over or equal to the screen's width, it will return true. However, since this is a visibility check we'll inverse this to make the check FALSE.
Here's some further optimised, and fixed, code:
VB Code:
Dim ObjRect As RECT
Dim ScreenRect As RECT
Dim visix As Boolean, visiy As Boolean, visix2 As Boolean, visiy2 As Boolean, visi As Boolean
With ScreenRect
.Right = ScreenWidth
.Bottom = ScreenHeight
End With
With RECT_OF_OBJECT
'add in your data
visix = ((Abs(.Right + 1) - .Right + 1) = 0)
visiy = ((Abs(.Bottom + 1) - .Bottom + 1) = 0)
visix2 = (.Left < ScreenRect.Right)
visiy2 = (.Top < ScreenRect.Bottom)
visi = visix And visix2 And visiy And visiy2
End With
If visi Then You_Can_Render_This_Object_So_Do_So!
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
LOL, just saw what you were trying to do, sorry... all this does is check if a sprite is off the screen. However, you can use BLTFast that doesn't stretch the sprite to do this. Simply change the rect!
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Thats some pretty advanced code just to check if sprite is off screen. My code would look something like- If sprite.x => 800 and sprite.y => 600 then Sprite_IS_Of_Screen LOL
This is how I blit all my objects: backbuffer.BltFast SpriteX + sx1, SpriteY + sy1, SpriteSurf, rSpriteSurf, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
the sx1 and sy1 are for the sliding background so that the sprites don't leave a trail.
I'm afraid I don't understand what you mean by changing the rect. Do you mean subtaract from it when sprite gets close to the edge of the screen? like rSpriteSurf.Left = rSpriteSurf.Left - 1 ?
Wait, you will have to useBLT instead of BLTFAST. When it gets close to the left, take away 1 from the width of the rect, and add 1 to the offset of the RECT that takes data from the source image. Do this for each edge and you'll be done.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Well, here is my little program. It is suppose to be a sliding world where the red circle is the main character. I did a clipping check on the big red block which is blitted to the background, but it still disappears when it touches any edge of the screen. Can someone please take a look and see what I'm doing wrong. You'll find all the clipping code under "CheckClip" sub.