BoxColl problem

Previous topic - Next topic

MrPlow

Hi,

I have a screen divided in to 16x16 sections

Using for loops that are stepped by 16 from 1 to 800 and 1 to 512 (high)

An array of an objects is placed within the confines of the grid by a measure of 16x16 squares or a multiple of the same...

But the item I move around the screen (also 16x16) is not flush with some sections of the sprite array and every second section of the grid is out or incorrectly...any ideas??

Code (glbasic) Select
FUNCTION hitobject: xx,yy

FOREACH w IN waters[]

IF BOXCOLL(xx,yy,16,16,w.wx,w.wy,w.width,w.height) THEN RETURN 1
NEXT


ENDFUNCTION



Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

matchy


The vague issue of flushing only reminds me of rounding to integers someone.  :glare:

Based on your collision thread sample code, I'm not sure where to start although I simply suggest that loops shouldn't be stepped absolutely but perhaps rather relatively with the co-ordinates calculated on the grid position multiplied by the tile sprite width.



fuzzy70

I had a similar problem with my code with the colour selection part

Code (glbasic) Select
// Check Mouse zone
FUNCTION MouseArea:
IF my>=10 AND my<=228 AND mx>=10 AND mx<=228 THEN PieceClicked((mx-10)/22,(my-10)/22) // Mouse clicked in Playarea
IF my>=270 AND my<=276 // Select Colours
IF mx>=207 AND mx<=220 // 200-206=Blue, 207-213=Red, 214-220=Green
    colour=(mx-200)/7
    ELSE
    colour=0
    ENDIF
ENDIF
ENDFUNCTION


Defining the variable at the start as an Integer instead of leaving it as a float fixed the problem. The code  colour=(mx-200)/7 was causing it & took a while to figure out what was going wrong as the math was right.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Ian Price

Make sure your variables are returning integers rather than floats. As Matchy stated rounding errors can cause issues (especially if you're testing for a specific integer and you're getting a float returned).

You can of course use ABS to get an integer, but just make the variable INT and it shouldn't be necessary.
I came. I saw. I played.

MrPlow

I got it working !!

My calcs were wrong... my x and y of the sprite were correct (odd numbers)
but my waters sections x (odd) y(even)

So along the way I evened out a 'y' axis value.

I really need to use my debugger better from now on!!

Thanks Guys!
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs