Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there any object here ?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01017390
Message ID:
01017522
Views:
20
This message has been marked as a message which has helped to the initial question of the thread.
>Is there a way to know if any object is placed at a certain location ?
>For example if I want to place an object ( a shape) at a certain location,
>i'd like to know if another object occupies the place where I want to put
>it.....
>Comments and appreciations about my english are not welcome :-)
>
>Alessio

Here is a collision method used to test if another object touch the current one on the same container.
This method test for an object of the same class, but it's easy to change it to test for any class.

You can call it after a move (in mouseup) to test for collision.
* method IsCollision
*
* test if 'this' touch another object in the parent container
*

x1=this.Left
x2=this.Left+this.Width
y1=this.Top
y2=this.Top+this.Height
FOR i=1 TO this.parent.ControlCount
	lTouch=.F.
	oPan=this.parent.Controls(i)

         * remove 'oPan.Class=this.Class' to test for any object

	IF oPan.Class=this.Class AND oPan <> this
		lTouch=.T.
		DO CASE 
			*too low
			CASE oPan.Top>=y2
				lTouch=.F.
			*too far right
			CASE oPan.Left>=x2
				lTouch=.F.
			*too high
			CASE oPan.Top+oPan.Height<=y1
				lTouch=.F.
			*too far left
			CASE oPan.Left+oPan.Width<=x1
				lTouch=.F.		
		ENDCASE 	
	ENDIF
	oPan=.NULL.
	IF lTouch
		RETURN .T.
	ENDIF 
ENDFOR 
RETURN .F.
HTH :)
If we exchange an apple, we both get an apple.
But if we exchange an idea, we both get 2 ideas, cool...


Gérald Santerre
Independant programmer - internet or intranet stuff - always looking for contracts big or small :)
http://www.siteintranet.qc.ca
Previous
Reply
Map
View

Click here to load this message in the networking platform