Clipping dd7surfaces on the edge of the screen...

Mithrandel
03-16-2002, 10:05 PM
So, here's the situation - two multi-thousand ton starships, bristling with enough weaponry to make any enemy's day go seriously downhill, are floating through space. One goes a little faster than the other, when suddenly...

BAM. The second starship reaches the edge of the screen, and disappears. Hum. This isn't good.

How am I supposed to clip dd7surfaces when they seach the edge of the screen to avoid this abrupt, un-intentional decloaking?

((Here's the code I'm currently using...))
Public Sub DisplaySprites()

Dim SrcRect As RECT
Dim i As Integer
Dim X As Integer, Y As Integer

'Set up the source rectangle
For i = 1 To UBound(Ships)

With SrcRect
.Bottom = Ships(i).Height
.Left = 0
.Right = Ships(i).Width
.Top = 0
End With

If i = 1 Then
'Blit the surface on to the backbuffer at the specified location, using the transparent color key of the source
X = (400 - (Ships(1).Width / 2))
Y = (300 - (Ships(1).Width / 2))
Call BackBuffer.BltFast(X, Y, Ship(Ships(1).Facing), SrcRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
Else
X = (Ships(i).posX - Viewport.Left)
Y = (Ships(i).posY - Viewport.Top)
Call BackBuffer.BltFast(X, Y, Ship(Ships(i).Facing), SrcRect, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
End If
Next i

End Sub

porthios
03-17-2002, 04:45 PM
After you find the X / Y COordiantes, do a little check like this:


If X + Ships(i).Width > 0 And X < {resolution} Then
If Y + Ships(i).Height > 0 And Y < {resolution} Then
***Clip check
End If
End If


There we check to see if the ship even needs to be painted onto the screen. If it passes all IFs, then we do the clip check shown below:


If X < 0 Then
SrcRect.Left = -X
End If
If Y < 0 Then
SrcRect.Top = -Y
End If

If X + Ships(i).Width > {resolution} Then
SrcRect.Right = (X + Ships(i).Width) - {resolution}
End If
If Y + Ships(i).Height > {resolution} Then
SrcRect.Bottom = (Y + Ships(i).Height) - {resolution}
End If


There, that should clip the edges off, by checking to see how much of the surface is going over the edge, and only getting so much of it to display. If somethings wrong with this code, someonw check it, I had to rewrite it quickly cause Netscape screwed up ^_^

Note: Replace {resolution} with the resolution for width/height, you shall know which applies

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum