Drag The Box

BlitzPlus Forums/BlitzPlus Programming/Drag The Box

Apollonius(Posted 2005) [#1]
I got this Image:
. Global BOX = LoadImage("box.jpg")

Then we have the following Variables:
. Global BOX_X, BOX_Y
. ImageWidth(BOX), ImageHeight(BOX)
. MouseX(), Mouse(Y)

Theres two things I want to do.
#1. Find a way to return the X and Y Values of where
the Mouse Clicked on the image.

For that we need to know the X and Y of the Mouse, the BOX's X and Y, the BOX's Width and Height, to then compare them and make the Math Algo that would return thoses value.

What I'm missign is the Algo to find such thing.

#2. How would I go about making an algo to see if we have clicked on the image or not, without using image overlapsing commands?

Probably by comparing the BOX's X and Y with the Width and Height of the Image but I wonder how I would do such a thing.

I can see it in my mind but I can't seem to come out with thoses codes.

Could anyone assist me with this?
Using clear code that is readable, not suggesting anyone's code is messy, but you know lol.

Thanks for the Help.


Regular K(Posted 2005) [#2]
[CODE]
if mousex()>=x and mousex()<=x+width and mousey()>=y and mousey()<=y+height
; collision!
endif
[/CODE]


Apollonius(Posted 2005) [#3]
MrSAK,
I'm having abit of trouble undersanding it, could you explain it abit to me, please :|


Regular K(Posted 2005) [#4]
x is boxes x position
y is its y position
width is how wide it is
height is how height it is

if the mouse is inside the box, then do this

cant really explain it much better :P


Apollonius(Posted 2005) [#5]
ok i get it now, thanks :)


Apollonius(Posted 2005) [#6]
I got some problems here,
If MouseDown(1) Then
	If ( MouseX() >= box_x And MouseX() <= box_w ) Then
		If ( MouseY() >= box_y And MouseY() <= box_h ) Then
			box_x = box_x + 5
			box_y = box_y + 5
		EndIf
	EndIf
EndIf


This is suppose to detect if the mouse is located on the image, and move the image if thats the case, but it isnt doing its job, what did i do wrong?

This is my source,
Graphics 640,480,32,2
SetBuffer BackBuffer()
ClsColor(190,190,190):Cls:Flip

; VARIABLES
Global exitGame = False
Global title = LoadImage("gfx/title.jpg")
Global content = LoadImage("gfx/content.jpg")
Global box_x, box_y
Global dragged = False

box_x=20
box_y=20
box_w=ImageWidth(title)
box_h=ImageHeight(title)

Repeat
; START {
Cls

If MouseDown(1) Then
	If ( MouseX() >= box_x And MouseX() <= box_w ) Then
		If ( MouseY() >= box_y And MouseY() <= box_h ) Then
			box_x = box_x + 5
			box_y = box_y + 5
		EndIf
	EndIf
EndIf

DrawImage title, box_x, box_y
DrawImage content, box_x, box_y+18

Flip 


; EXIT GAME
If KeyDown(1)
exitGame=True
EndIf

; END    }
Until (exitGame = True)
End

; FUNCTIONS
Function saveGame()

End Function



Regular K(Posted 2005) [#7]
you need to add the boxes x to the width and the boxes y to the height


Apollonius(Posted 2005) [#8]
How do I make it so, if the mouse moves, the title image follows...?

Life how to return if the mouse has moved abit left then move the window abit left?

If MouseDown(1) Then
	If ( MouseX() >= box_x And MouseX() <= box_x + box_w ) Then
		If ( MouseY() >= box_y And MouseY() <= box_y + box_h ) Then
			box_x = box_x - MouseX()
			box_y = box_y - MouseY()
		EndIf
	EndIf
EndIf



Apollonius(Posted 2005) [#9]
so.. like i tryed this:
			m1=MouseX()
			m2=MouseY()
			box_x = MouseX() - m1
			box_y = MouseY() - m2

.. Tryed to compare where it was when u hited down and mouved ur your mouse.. i dunno.. gah

help please