Main Menu

SpriteCollisionClass Question

Started by Mick Berg, September 04, 2005, 01:02:58 PM

Previous topic - Next topic

Mick Berg

Is it required to use the SpriteCollisionClass system? As I only have one of each type of sprite in my project, and not clouds of asteriods, it just causes confusion to my already overheated brain. Or could I put all the sprites in the same class?
Thanks.

kevin

When a sprite is created, it's assigned a collision class of 1 by default.   So if you never change it,  you'd just use this to test for collisions

Mick Berg

QuoteWhen a sprite is created, it's assigned a collision class of 1 by default.   So if you never change it,  you'd just use this to test for collisions
But I still have to put the last parameter, the class, in each SpriteHit command, don't I? Would you consider making this unnecessary in a future upgrade?
Thanks.

kevin

#3
Optional parameters are already on the to-do list.  Although, I don''t really see how adding two extra characters (,1) is such an inconvenience.

it sounds more like you want this SpritesOverlap(SpriteA,SpriteB).

Mick Berg

Yes, I found SpritesOverlap and it works fine. I thought the last parameter for SpriteHit had to be %0001, or something similar, which overheated my brain. I didn't realise it could be a simple number. Thanks for your patience with my newbie-ism.

kevin

#5
%0001 is just the binary representation of the integer value 1.     So the % symbol tells PlayBASIC (and the programmer) that the following number (of up to 32 digits) is in binary form, rather than the default integer/decimal (base 10) form.

 In  binary (base 2)  each column can only be two states  1=true, 0=false,    and each column is as multiple of 2.  

 i.e a four bit binary number has these columns.  

High bit  8,4,2,1   lowbit

So some quick (four 4bit) representations

 %0001   =   1           ( 0*8 ) + (0*4) +(0*2) + (1 * 1)
 %0010  =   2           ( 0*8 ) + (0*4) +(1*2) + (0 * 1)
 %0011   =   3           ( 0*8 ) + (0*4) +(1*2) + (1 * 1)
 %0100   =   4           ( 0*8 ) + (1*4) +(0*2) + (0 * 1)
 %0101   =   5           ( 0*8 ) + (1*4) +(0*2) + (1 * 1)
 %0110   =   6           ( 0*8 ) + (1*4) +(1*2) + (0 * 1)
 %0111   =   7           ( 0*8 ) + (1*4) +(1*2) + (1 * 1)
 %1000   =   8           ( 1*8 ) + (0*4) +(0*2) + (0 * 1)

etc etc

%1010   =   10           ( 1*8 ) + (0*4) +(1*2) + (0 * 1)
; etc
 %1111   =   15           ( 1*8 ) + (1*4) +(1*2) + (1 * 1)


The more bits you have the higher the range the binary number can represent..

 i.e a eight bit binary number has these columns.  

128 , 64 , 32 , 16 , 8 , 4 , 2 , 1

 %00000001   =   1         (0*128)+(0*64)+(0*32)+(0*16)+ ( 0*8 ) + (0*4) +(0*2) + (1 * 1)
 %10000001   =   129         (1*128)+(0*64)+(0*32)+(0*16)+  (0*8 ) + (0*4) +(0*2) + (1 * 1)
etc


 It's often easier when dealing with things like classes in binary.  
 

(login required)