How to move objects via code?
by FruitBatInShades · in Torque X 2D · 11/06/2009 (11:31 am) · 10 replies
Just bought Torque X 2d and the Platform Starter Kit. Great Products :)
Can anyone give me some pointers in how to approach animating and changing state of items like doors? Not sure which of the main objects to base it on or how to handle the animation. I'd guess I'd create a door class that renders the background, has a door object that it animates through physics till it reaches a certain point, then stops the animation.

Any one got any pointers for a newb :)
(c# is my daily language so just need x2d pointers)
Can anyone give me some pointers in how to approach animating and changing state of items like doors? Not sure which of the main objects to base it on or how to handle the animation. I'd guess I'd create a door class that renders the background, has a door object that it animates through physics till it reaches a certain point, then stops the animation.

Any one got any pointers for a newb :)
(c# is my daily language so just need x2d pointers)
#2
11/07/2009 (12:08 pm)
Any pointers with the code or tutorials about mounting objects via code. I've read through the documentation and not seen anything related to what I'm after :)
#3
The rainy day tutorial from the Documentation has some good code example of this concept. Look for the section that deals with the flowers growing and dying animation. It's part of the Animation Runner. As to how tall you would make the sprite, make it as tall as when the door is open.
11/07/2009 (3:30 pm)
I would disagree about making it a mounted object. I would make it an animated sprite that opens when the player gets close, has the proper key etc.... The rainy day tutorial from the Documentation has some good code example of this concept. Look for the section that deals with the flowers growing and dying animation. It's part of the Animation Runner. As to how tall you would make the sprite, make it as tall as when the door is open.
#4
Can I set up different collision meshes for different frames of the animation?
11/07/2009 (6:32 pm)
I was avoiding a sprite because the object is used on both sides. The top of the door sits up, sticking out of the floor, a second character activates it from underneath the ground so that the player above can pass through.Can I set up different collision meshes for different frames of the animation?
#5
11/08/2009 (7:44 am)
I would create a component that references both the door and the door background. When activated, the component would move the door up by adjusting its velocity. Every tick, it would check the offset between the door and the door background to determine when to stop.
#6
11/08/2009 (8:23 am)
Anyone got any pointers to how to implement this via code? I've tried adding two T2DStaticSprite Properties but they are not selecteable in the game builder!
#7
11/08/2009 (2:15 pm)
You can't add properties to TX object types and have them show up in the builder for editing. You need need write a 'Component' instead. You would then attach the Component to yr objects in TXB. There are examples of using components in the tutorials.
#8
EDIT: T2DSceneObject
11/08/2009 (4:31 pm)
Use T2DSceneNode properties in your component, not T2DStaticSprite.EDIT: T2DSceneObject
#9
How do I get my sprites to render where I want them? What am I doing wrong?
11/09/2009 (3:27 pm)
I feel really thick! I can't get my head round how the system works. I've added the following to my component:public T2DSceneObject BackgroundSprite
{
get { return _BackgroundSprite; }
set { _BackgroundSprite = value; }
}
public T2DSceneObject DoorSprite
{
get { return _DoorSprite; }
set { _DoorSprite = value; }
}How do I get them to render on command? There is a render method but it requires SceneRenderState. I'm guessing I shouldn't be using that! In the builder I've got 2 StaticSprites and assigned them to the properties but they are not rendering! How do I get my sprites to render where I want them? What am I doing wrong?
#10
Since they are in the scene, they should render automatically, unless you made them invisible.
11/17/2009 (5:20 pm)
Create your two static sprites. Drag them into your scene and position them where you want them to be. Next, click on your BackgroundSprite. Go to the window pane on the right and open up the "Scripting" section. In the "Name" section, give it a name: Background1. Do the same thing for the DoorSprite. Give it a name: Door1. Next, add your component to the object you want. In the drop down boxes, choose Background1 for the BackgroundSprite, and choose Door1 for the DoorSprite.Since they are in the scene, they should render automatically, unless you made them invisible.
Torque Owner Ezra