News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

sprite collision off with sprite overlap not working ?

Started by micky4fun, November 23, 2008, 06:21:30 AM

Previous topic - Next topic

micky4fun

Hi Kevin

been using spriteoverlap with spritecollision turn off , but spriteoverlap still returns a 1 value
ie your example below

am i doing something wrong ??


thanks mick


PlayBASIC Code: [Select]
Cls RGB(0,0,255)
GetImage 1,0,0,32,32

Cls RGB(0,255,00)
GetImage 2,0,0,32,32

; =============================
; Part 2- Create some sprites
; =============================

; Create Sprite 1, and assign it image 1
CreateSprite 1
SpriteImage 1,1
CenterSpriteHandle 1
; Enable Collision for Sprite #1 i have disabled it with a zero , but no joy?
SpriteCollision 1,0
; Set Sprite #1 to collision Class %0001
SpriteCollisionClass 1,%0001


; =====================================================
; Create a bunch fo sprites to check collision against
; =====================================================

For Sprites=2 To 50
CreateSprite Sprites
SpriteImage Sprites,2
x=Rnd(GetScreenWidth()-32)
y=Rnd(GetScreenHeight()-32)
PositionSprite sprites,x,y

; Enable Collision for this sprite i have disabled it with a zero , but no joy?
SpriteCollision Sprites,0

; Set sprite to Collision Class %0010
SpriteCollisionClass Sprites,%0010


Next



; =============================
; Part 3- The Main Loop
; =============================

; Start a DO/Loop
Do
; Clear the screen
Cls RGB(0,0,0)
; Display a message
Print "Manual Sprite Collisions"

; Position the Sprite 1 at the mouses position
PositionSprite 1,MouseX(),MouseY()

; Manually chek sprite #1 against the other sprites
ThisSprite=SpriteHit(1,GetFirstSprite(),%0010)

For Spr=2 To 50
; Check if Sprite 1 hits this sprite
If SpritesOverlap(1,Spr)
Print "Hit Sprite:"+Str$(Spr)
EndIf
Next

; Draw All of the sprites
DrawAllSprites

; Draw the screen
Sync

; Loop back to the DO statement
Loop




kevin

 SpritesOverlap  is for manual checking between a pair of sprites.  Since it's manual, it assumes you know what you want to compare with and how.

 if you only want to detect impacts upon certain sprites, then SpriteHIT the way to go.



PlayBASIC Code: [Select]
For Spr=2 To 50
; Check if Sprite 1 hits this sprite
if GetSpriteCollision(spr)
If SpritesOverlap(1,Spr)
Print "Hit Sprite:"+Str$(Spr)
EndIf
endif
Next



micky4fun

#2
Thanks
Kevin

i have sorted that out now ,

thanks for your help

mick  :)