Anyone see anything wrong with this code?

BlitzPlus Forums/BlitzPlus Programming/Anyone see anything wrong with this code?

sswift(Posted 2005) [#1]
This works:

X1 = BOBX#(BOB_MenuItem(Loop)) - BOBWidth(BOB_MenuItem(Loop))/2
Y1 = BOBY#(BOB_MenuItem(Loop)) - BOBHeight(BOB_MenuItem(Loop))/2
					
X2 = BOBX#(BOB_MenuItem(Loop)) + BOBWidth(BOB_MenuItem(Loop))/2
Y2 = BOBY#(BOB_MenuItem(Loop)) + BOBHeight(BOB_MenuItem(Loop))/2
					
If (Mouse_X >= X1) And (Mouse_X <= X2) And (Mouse_Y >= Y1) And (Mouse_Y <= Y2)



But this won't work:

If BOB_RectOverlap(BOB_MenuItem(Loop), Mouse_X, Mouse_Y, 1, 1)

; -----------------------------------------------------------------------------------------------------------------------------------
; This function returns TRUE if the bounding rectangle of a BOB overlaps the specified region of the screen.
; -----------------------------------------------------------------------------------------------------------------------------------
Function BOB_RectOverlap(ThisBOB.BOB, Rect_X, Rext_Y, Rect_Width, Rect_Height)
	
	X1 = Floor(ThisBOB\Position_X#-ThisBOB\Handle_X#)
	Y1 = Floor(ThisBOB\Position_Y#-ThisBOB\Handle_Y#)
	
	Return ImageRectOverlap(ThisBOB\Image, X1, Y1, Rect_X, Rect_Y, Rect_Width, Rect_Height)

End Function



Anyone got any ideas why this isn't working? ImageRectOverlap isn't supposed to take transparent pixels into account, and even if it did, the image I'm checking against is mostly opaque pixels.

Increasing the width and height of the rectangle I'm testing the image against has no effect, so it is not a bug with rectangles that have a 1x1 size.

I've checked the data, the image width and height are being returned properly in the function. The handle coordinates are in the center of the image as expected. (Note I'm not using the image handle stuff Blitz has, the handle I refer to are the offsets I add to the position of the image.)

I've tried clicking all over the screen to see if maybe something is messed up and I can hit something, but I hit nothing. It is as if the ImageRectOverlap command does not work.

I'm sure I've just made some stupid mistake though, I am tired.


WolRon(Posted 2005) [#2]
I don't see anything wrong with it. Perhaps your Position_X# (or Y#) or Handle_X# (or Y#) or Mouse_X (or Y) aren't holding the correct values?


skidracer(Posted 2005) [#3]
I would have thought ImageRectOverlap would already take into account the image handle.


Who was John Galt?(Posted 2005) [#4]
In the function definition - "Rext_Y"


sswift(Posted 2005) [#5]
Falken:
That was it. I figured it out this morning while the forums were down. :-)

STIPUD TPYOS!


sswift(Posted 2005) [#6]
OH, and I would just like to thank every person who has ever bought my BOBS system for fixing this bug on their own and not reporting it to me, since it has been in there since day 1. :-)


sswift(Posted 2005) [#7]
Skid:

"I would have thought ImageRectOverlap would already take into account the image handle."


My BOB system until recently didn't allow you to use image handles except with normal masked or non-masked blitting.

I just added handles to the system though, so now instead of using image handles, you specify the BOB handles. I have to do this because the BOB system allows you to blit with all sorts of different blending modes and alpha. It needs to be able to do that manually, and handle clipping. Blitz doesn't provide a way to get the location of the handle you have specified for an image, so I can't get the handle. And it makes more sense to specify handles on a per BOB basis rather than a per image basis since you may use the same image on more than one BOB.


Grey Alien(Posted 2005) [#8]
The fact that the BB IDE doesn't complain about typos and is happy to use an undeclared variable with value 0 has caused me sooo much wasted time, it's a real bummer.


LineOf7s(Posted 2005) [#9]
Grey, try this:

http://www.quickiegames.com/tools/preprocessor/features.html

Featuring, amongst other things:
Option Explicit
Option Explicit is enabled by including the preprocessor directive "#Option Explicit" at the top of your source code. It will give an error whenever a variable is implicitly defined.


Free, too. Good ole Micky Richtenfrankensteiner. :o)