Mouse Move Component torque X
by Dany · 08/11/2007 (3:13 am) · 6 comments
My First Blog :)
First of all , My mother tongue is not English. I try to explain my component with simple sentence.
when I began with torque X , it was to create little game on PC and not on X360 , I had looked, how use the mouse like a classic game, but nothing.
I tried to make a component for the mouse , and exploit the collision detection.
that worked with bind command stick or lever, and velocity, but the movement of the mouse is not like a mouse and the other problem is no detection when the collision end.
I tried with the position property , but when you set a position of a sprite without velocity , the method collision doesn't works, then I set a Velocity of 0.01f and th mouse pointer respond to a collision but I had the same problem , no detection when you leave the sprite.
I tried with another garagegame component , the Trigger component : there are 3 method
On enter , On Stay , and On Leave
after many try, I had maked this component you can download it from Here
if the first link doesn't works try Here
it is a complete project with the component (mouseExmple)
How to use It:
you must use Two sprite : One for you mouse pointer and One for precise selection ( in the exemple its a red pixel)
add the pixel to your project and add the mouse component to this pixel.
there are 2 public properties reelWidth, and reelheight its you reel dimension of you game (exemple 800*600)
set the worldlimit to this pixel same size of you cam (difficult its just a pixel :))
give a name to your cam (in the exmple its MyCam) if you set another name change the code
set a new object type (mouse) and assign this type of object to your pixel
add a sprite and named it "Mouse" for another name change the code
add a linkpoint component to this sprite
for all objects manipulated by the mouse
add trigger component (enable -> collide with mouse -> and set the on stay and on leave method)
try it
I hope that I didn't forgot anything but all the code are in the project
this component need improvment like a property to set the cam name and the name of the sprite used for the pointer , ...
give me your feedback
thanks
Elday
First of all , My mother tongue is not English. I try to explain my component with simple sentence.
when I began with torque X , it was to create little game on PC and not on X360 , I had looked, how use the mouse like a classic game, but nothing.
I tried to make a component for the mouse , and exploit the collision detection.
that worked with bind command stick or lever, and velocity, but the movement of the mouse is not like a mouse and the other problem is no detection when the collision end.
I tried with the position property , but when you set a position of a sprite without velocity , the method collision doesn't works, then I set a Velocity of 0.01f and th mouse pointer respond to a collision but I had the same problem , no detection when you leave the sprite.
I tried with another garagegame component , the Trigger component : there are 3 method
On enter , On Stay , and On Leave
after many try, I had maked this component you can download it from Here
if the first link doesn't works try Here
it is a complete project with the component (mouseExmple)
How to use It:
you must use Two sprite : One for you mouse pointer and One for precise selection ( in the exemple its a red pixel)
add the pixel to your project and add the mouse component to this pixel.
there are 2 public properties reelWidth, and reelheight its you reel dimension of you game (exemple 800*600)
set the worldlimit to this pixel same size of you cam (difficult its just a pixel :))
give a name to your cam (in the exmple its MyCam) if you set another name change the code
set a new object type (mouse) and assign this type of object to your pixel
add a sprite and named it "Mouse" for another name change the code
add a linkpoint component to this sprite
for all objects manipulated by the mouse
add trigger component (enable -> collide with mouse -> and set the on stay and on leave method)
try it
I hope that I didn't forgot anything but all the code are in the project
this component need improvment like a property to set the cam name and the name of the sprite used for the pointer , ...
give me your feedback
thanks
Elday
#2
10/10/2007 (5:08 am)
Great idea! Too bad that link still isn't working (gives you zero length file). Could you repair it? Or send it to my e-mail team@lonelytroops.com.
#3
03/28/2008 (11:25 am)
Is there any way to cause killCollision with the object INSTEAD of mounting it to the mouse?
#4
did you want use the pointer like a visor and when you press your mouse button you kill the sprite under it instead of mounting it
is it correct ?
Elday
03/28/2008 (12:41 pm)
Hello Matthew , I don't understand your question ! did you want use the pointer like a visor and when you press your mouse button you kill the sprite under it instead of mounting it
is it correct ?
Elday
#5
03/31/2008 (12:57 pm)
Yes, that is correct. Honestly, I could really settle for 1 of 2 ways. I'm looking for a situation when, as you said, you click on a sprite you kill it OR I'd be happy just being able to move the mouse over a sprite and causing it to die. Im trying to establish basic collision detection with the mouse for a game and your example is great, except for the fact that I'm trying to set it to do kill collision instead of mounting. At the moment, through the Torque X builder, I can have an object move toward the mouse and the object dissappears. However, when I move the mouse over the object instead of moving the object toward the mouse, nothing happens.
#6
I checked the possibility and I founded 2 way.
1 - as you said you pass the mouse over the sprite and i disapear or you create a oncollision method to start an animation of explosion before the destruction of the sprite
but remember this : there are no collision without velocity on your object !!!
then set a velocity on your sprite (not the mouse) on my exemple (if you have downloaded) its garagegame logo, if you want a static sprite set a velocity of 0.001f its very very slow and it seems static
set on TXB the collision with mouseP and kill collision
normally when you pass on it he disapear
Second way
create a new sprite ( a pixel ) in TXB give it name and object type (like "bullet" or another name as you wish ), and set it to template , and visibilitylevel = 0 (not for the debug)
you change the method pushleft , instead of mounting object you create the bullet from the template and position is = to the mouse pointer.
your target object must be set to kill collision with the bullet type
if you have another question you can leave a message on this email address : ld_torque@brutele.be
elday
04/01/2008 (10:40 am)
Hello Watthew,I checked the possibility and I founded 2 way.
1 - as you said you pass the mouse over the sprite and i disapear or you create a oncollision method to start an animation of explosion before the destruction of the sprite
but remember this : there are no collision without velocity on your object !!!
then set a velocity on your sprite (not the mouse) on my exemple (if you have downloaded) its garagegame logo, if you want a static sprite set a velocity of 0.001f its very very slow and it seems static
set on TXB the collision with mouseP and kill collision
normally when you pass on it he disapear
Second way
create a new sprite ( a pixel ) in TXB give it name and object type (like "bullet" or another name as you wish ), and set it to template , and visibilitylevel = 0 (not for the debug)
you change the method pushleft , instead of mounting object you create the bullet from the template and position is = to the mouse pointer.
your target object must be set to kill collision with the bullet type
if you have another question you can leave a message on this email address : ld_torque@brutele.be
elday

Torque Owner GrantleyDay
However the link isn't working and I cannot download you example.... Is there any chance you can email it to me: enjoyingsf@hotmail.com?