Game Development Community

SetPosition ??

by Bruno · in Torque X 2D · 08/18/2007 (6:56 am) · 7 replies

Hi.,

I'm tryng to interpolate the current sprite position to a new position.
From the documentation :

Changes position of object optionally updating spatial data. Use this method with updateSpatialdata=false rather than Position property if you have several updates to make to the object in order to save unneeded calls to UpdateSpatialData. However, UpdateSpatialData must be called in the end or else the scene container may have old data.


So, this seems what i need., however, i can't get it to work, nothing happens.
This is my code :

T2DStaticSprite mytest = TorqueObjectDatabase.Instance.FindObject("testo1");

Microsoft.Xna.Framework.Vector2 xpto;
xpto.X = 250;
xpto.Y = -70;
mytest.SetPosition(xpto,true);

I also call this, but still no go :
mytest.UpdateSpatialData();

I know everything else is working, because if i call
mytest.WarpToPosition(xpto, true);

The sprite moves, however and as expected, it's immediatly.

Can anyone help help ?? :)

thanks,
Bruno

#1
08/19/2007 (4:19 pm)
Anyone ?
#2
08/20/2007 (8:48 am)
You shouldn't need to use the xpto vector at all in that way--try something like (off the top of my head here):

mytest.Position = new vector2(250, -70);
#3
08/20/2007 (9:49 am)
Hi Stephen,

Yeah, that works, but that puts the sprite immediatly in that position.I was thinking setPosition works like the moveTo(from TGB). Doens't it have the same functionality ?

thanks,
Bruno
#4
08/20/2007 (9:54 am)
No, you would want to create a new component most likely that handles your movement interpolation, and apply that component to objects that need that style of movement.

It would most probably use a series of mytest.Position sets over time in accordance with your interpolation algorithm.
#5
08/20/2007 (12:57 pm)
Or use a physics component and work out the correct velocity.
#6
08/20/2007 (3:46 pm)
Thanks for the ideias.

Let me try to explain what i'm tryng to do.
I have a puzzle board, and i simply want to slide all the pieces to the left or to the right.
The ideia of a component was a good one, but i don't know how to interface it with the pieces.

I can make a component that moves the position of the piece 32 units on a processtick function, but how to trigger the function to happen ?

For example, when i press a key i can do this :

T2DStaticSprite original = TorqueObjectDatabase.Instance.FindObject("testo2");
T2DStaticSprite mytest = (T2DStaticSprite)original.Clone();
mytest.Components.AddComponent(new MoveTo());
TorqueObjectDatabase.Instance.Register(mytest);

This kind of works, but makes a clone of the original object, and i end up with 2 objects in the screen, 1 in the original position, and a clone moving.

I can't add a component to the "original" object, because i get an assert complaining that i can't add components after the object is registered.

I could try to add the component to the original object in the TGX editor, but then once the game starts they will all start moving.
Is there a way to trigger an even inside the component ? If there is, i could add the moveTo component in TGX, and trigger the movement when i wanted.

I hope this makes some sense.,
thanks,

Bruno
#7
08/20/2007 (4:22 pm)
Ok, i got it working :)
To the ones interested, this shows how to :

http://www.garagegames.com/mg/forums/result.thread.php?qt=56233