Page 1 of 1

Posted: Thu Jun 27, 2002 7:49 pm
by BackupUser
Restored from previous forum. Originally posted by Iontichy.

Hi all,
i have little problem with SpritePixelCollision in my
game. I have a background sprite with a hole (transparent)
in it. This should be the border of the game. Inside the
border sprite can move a ship sprite. Now i want to check
if the ship collides with the border, but SpritePixelCollision
returns always 1.
I have written a simple example of my problem. You can download it at:

http://mitglied.lycos.de/iontichy123/sp.zip

Can anybody tell me what i'm doing wrong, PLEASE!
Thanx in advance...


---------------
star traveler

Posted: Thu Jun 27, 2002 11:55 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.

Hi Iontichy
I tested your example and having the same problem... I added "TransparentSpriteColor(#Sprite, Red, Green, Blue)" and tested with the same result...

I think that the result problem of the "SpritePixelCollision(#Sprite1, x1, y1, #Sprite2, x2, y2)" is that you are using a box with a white border and INSIDE this box the background is empty or better to say "just transparent/black.

Maybe "SpritePixelCollision()" will only remove all transparent pixels outside of your Image (if you haveing a airplane for example) and dont remove transparent pixels inside your border-box...

Because it makes no sence to check a collision inside a image for example (if you have two circles for example and check this two circles for a collision, you are only interested in the outa pixels and not the transparent pixels inside the circle, isnt it? Hope you understand what i try to tell you...

For your source, you should draw the white border box with the 2dDrawing commands... You will know the position and size of your black gamefield, so you could check for any collisions to the border - just check if your object


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten

Posted: Fri Jun 28, 2002 12:48 am
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.

Hi Iontichy
Maybe you have understand my last posting!? However, i have recoded your example to show you a way without "SpritePixelCollision(#Img_Sphere, x1, y1, #Img_Background, x2, y2)" for Sphere and Background image. There are different ways how to handle the collision and all the stuff inside the box... Maybe the following (working) source will help you... Good luck and happy coding

Note: You need your original "Sphere.bmp" file, you can find in the archive:

Code: Select all

;-----------------------------------
;
; Example for your Ball Collision... 
;
; (28-Jun-2002 - 02:25am)
;
;-----------------------------------
;
    #scrw = 640              ; screenwidth
    #scrh = 480              ; screendheight
    #scrd = 16               ; screendepth 
    ;
    ;-------- Init some other Stuff --------
    ;
    #Img_Sphere = 0          ; Image number 0
    ;    
    ;-------- Init all needed Stuff --------
    ;
    If InitSprite() = 0 Or InitKeyboard() = 0 And InitMouse() = 0
       MessageBox_ (0,"Can't open DirectX 7 or later", "Your Ball Collision Example", #MB_ICONINFORMATION|#MB_OK)
       End
    EndIf
    ;
    If OpenScreen(#scrw, #scrh, #scrd, "Your Ball Collision Example") = 0                             
       MessageBox_ (0,"Could not open 640x480x16 screen", "Your Ball Collision Example", #MB_ICONINFORMATION|#MB_OK) 
       End                                                                                     
    EndIf
    ;
    ;-------- Load needed Stuff --------
    ;
    LoadSprite  (#Img_Sphere, "sphere.bmp", 0)                     ; We dont need the Background image :wink:
    SphereW = SpriteWidth (#Img_Sphere)                            ; Get width of Image
;
;========================================
; M a i n L o o p  ->  test routine   
;========================================
;
    Repeat
        ClearScreen(0,0,0)
        ;
        ;-------- Draw our white border box --------
        ;
        StartDrawing(ScreenOutput())
            Box (  0,   0, 200, 18, RGB(255,255,255))              ; top white box
            Box (  0,   0,  18,200, RGB(255,255,255))              ; left white box
            Box (  0, 182, 200, 18, RGB(255,255,255))              ; upper white box
            Box (182,   0,  18,200, RGB(255,255,255))              ; right white box
        StopDrawing()
        ;   
        ;-------- Get MousePos + DebugInfo --------
        ;
        mposx = MouseX()                                           ; X position of mouse
        mposy = MouseY()                                           ; Y position of mouse
        ;
        If (mposx  182-SphereW) Or (mposy  182-SphereW) 
            collision = 1
          Else 
            collision = 0
        EndIf
        ;
        Debug collision
        ;
        ;-------- Move And Display Sphere Object --------
        ;
        If mposx  182-SphereW : mposx = 182-SphereW : EndIf      ; Check right wall
        If mposy  182-SphereW : mposy = 182-SphereW : EndIf      ; Check upper wall
        ;
        DisplayTransparentSprite (#Img_Sphere, mposx, mposy)
        FlipBuffers()
        ;
        ;--------
        ;
        ExamineMouse()
        ExamineKeyboard()
    Until KeyboardPushed(#PB_Key_Escape)
;
End
;
;-----------------------------------
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten

Posted: Fri Jun 28, 2002 6:37 am
by BackupUser
Restored from previous forum. Originally posted by Iontichy.

Hi MrVainSCL,
ich habs schon verstanden was Du meinst ;D
Thank you for your great example.
But unfortunatly this doesn't solve my problem,
because my (real) background isn't just a square.
Its totaly irregular and thats why i'm try to
using SpritePixelCollision.
Any other sugesstions?


Edited by - Iontichy on 28 June 2002 07:38:01

Posted: Fri Jun 28, 2002 7:47 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Make some parts out of the big sprite.
Dont use 1 big sprite with transparency
in the middle, but use 4 sprites (4 sides)
and dont draw in the middle.

This way you could check all 4 sides
for the collision.

cya,
...Danilo

(registered PureBasic user)

Posted: Fri Jun 28, 2002 8:12 am
by BackupUser
Restored from previous forum. Originally posted by Iontichy.

Thanx Danilo for your posting.
I think my example give you the wrong idea.
The background i use don't have 4 sides.
It is very irregular and contains the whole level
whith tunnels an caves and so on.
If i understand the command SpritePixelCollision,
it should return 1 only if any pixel of the two sprites collides
no matter where the pixels inside the sprites appear.
I'm wrong?
Maybe this is a question for fred...

---------------
star traveler