mouseDown, worldPosition
by rennie moffat · in Torque Game Builder · 12/14/2009 (12:17 pm) · 7 replies
hi I am sure I am answering my own question correctly here but I would like to ask.
on a mouseDown event, %worldPosition is the position of the mouse at the time of mouse down and remains that point until the next mouseDown?
on a mouseDown event, %worldPosition is the position of the mouse at the time of mouse down and remains that point until the next mouseDown?
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
A related question, at least to my own pursuits here is that I am not getting this code to work for some reason. I have added in echos and the one that is not being called is in onMouseDown
if anyone has insight I would appreciate it.
12/14/2009 (2:17 pm)
cool, great steve, thanks.A related question, at least to my own pursuits here is that I am not getting this code to work for some reason. I have added in echos and the one that is not being called is in onMouseDown
if (!isObject(CubeOnMouseDownBehavior))
{
%template = new BehaviorTemplate(CubeOnMouseDownBehavior);
%template.friendlyName = "Cube Moves to Clicked pt on MouseDown";
%template.behaviorType = "Mouse Input";
%template.description = "Moves the object to MousePosition on mouse down";
%template.addBehaviorField(cubeSpeed, "The speed at which the object moves.", float, 45.0);
}
function CubeOnMouseDownBehavior::onBehaviorAdd(%this, %scenegraph)
{
%this.owner.setUseMouseEvents(true);
echo("---inside onBeAdd We are");
}
echo("---ouside before MouseDown We are");
function CubeOnMouseDownBehavior::onMouseDown(%this, %modifier, %worldPosition)
{
///this echo is not being called and I dont know why!!!!!
echo("---InsideMouseDown We are");
%this.owner.setImpulseForce(%this.cubeSpeed);
}if anyone has insight I would appreciate it.
#3
function SceneWindow2D::OnMouseDown(%this, %mod, %coords, %click)
{
// insert code here
}
12/15/2009 (6:07 pm)
I don't use behaviors at all, I use the callback, like this -function SceneWindow2D::OnMouseDown(%this, %mod, %coords, %click)
{
// insert code here
}
#4
If I class,
function SceneWindow2D::onMouseDown(%this, %mod, %coords)
{
%coords = %this.destination();
//where destination is then passed to another object (cube)
%this.destination = $destination;
%this.gotToDestination(%this.destination);
}
function cube::goToDestination()
{
$cube.moveTo($destination, %speed);
//cube is previously set as $cube
}
I have been writing various forms of this to allow my cube to move to any world position on mouse down (which does NOT have to occur over the cube object only in the sceneWindow2D.
:?
You see my trouble is linking my sceneWIndow to my object. Thats why behaviors are questionable for me for this task.
12/15/2009 (6:47 pm)
nice. yah see then I am using setMouseEventCallback, and setObjectMouseEvent(true).If I class,
function SceneWindow2D::onMouseDown(%this, %mod, %coords)
{
%coords = %this.destination();
//where destination is then passed to another object (cube)
%this.destination = $destination;
%this.gotToDestination(%this.destination);
}
function cube::goToDestination()
{
$cube.moveTo($destination, %speed);
//cube is previously set as $cube
}
I have been writing various forms of this to allow my cube to move to any world position on mouse down (which does NOT have to occur over the cube object only in the sceneWindow2D.
:?
You see my trouble is linking my sceneWIndow to my object. Thats why behaviors are questionable for me for this task.
#5
In theory, I should be able to link my sceneWindow2d class with any object right? including my $cube (player/hero). Correct, if so, a link concrete link could be mad simply by typing sceneWindow2D as a super class to a cube class?
12/15/2009 (9:12 pm)
Just had a thought.In theory, I should be able to link my sceneWindow2d class with any object right? including my $cube (player/hero). Correct, if so, a link concrete link could be mad simply by typing sceneWindow2D as a super class to a cube class?
#6
I think it has been mentioned in other threads before, but you are trying to run before you can even crawl, let alone walk.
That's not how namespaces (the class, super class fields) work at all. They are a way for specific objects to inherit methods from a more general, base class. For example, you can have two objects in your scene - an apple and an orange. Now an apple is not the same thing as an orange but you can give both of them the class "fruit" and they then share a group of methods.
I think it would do you a lot of good if you go through the documentation provided online and offline by TGB. Read the Torquescript overview, do the fish game tutorial (not the behavior one), do the breakout tutorial on TDN. In the first section of the breakout tutorial it shows a clear example of how to pass the %worldPosition from onMouseMove to a separate function, which is similar to what you are struggling with above. I know you are probably anxious to work on the game ideas you have but in the end you will save yourself a lot of time and frustration if you first make the effort to do as many tutorials as possible and really understand how the Torquescript code is being used in each of them.
12/16/2009 (10:57 am)
Rennie,I think it has been mentioned in other threads before, but you are trying to run before you can even crawl, let alone walk.
Quote:In theory, I should be able to link my sceneWindow2d class with any object right? including my $cube (player/hero). Correct, if so, a link concrete link could be mad simply by typing sceneWindow2D as a super class to a cube class?
That's not how namespaces (the class, super class fields) work at all. They are a way for specific objects to inherit methods from a more general, base class. For example, you can have two objects in your scene - an apple and an orange. Now an apple is not the same thing as an orange but you can give both of them the class "fruit" and they then share a group of methods.
I think it would do you a lot of good if you go through the documentation provided online and offline by TGB. Read the Torquescript overview, do the fish game tutorial (not the behavior one), do the breakout tutorial on TDN. In the first section of the breakout tutorial it shows a clear example of how to pass the %worldPosition from onMouseMove to a separate function, which is similar to what you are struggling with above. I know you are probably anxious to work on the game ideas you have but in the end you will save yourself a lot of time and frustration if you first make the effort to do as many tutorials as possible and really understand how the Torquescript code is being used in each of them.
#7
Thanks.
12/16/2009 (12:30 pm)
I realize this is a complex move, but if I can get that I can move light years ahead. I can write basic code for objects, but I am trying to link the sceneWindow to a sceneobject I am having difficulty with. I have bought a new book and looking all thru TDN. I will get it eventually, with or with out "being told how" or as I like to say being shown.Thanks.
Torque Owner Steve D