Game Development Community

Move "Hero" to left/right/up/down with 4 or more sprites?

by Tolga A. · in Torque X 2D · 09/19/2007 (2:11 pm) · 11 replies

Hi,

I can move my sprite with w,a,s,d or the arrow keys. Ok, but he is moving with ONE sprite, so... i'm just moving the sprite, that means I am not "walking".

Can somebody help me?

I want that if I walk to right, that the the Sprite "HeroRight" appears, if I walk down, the Sprite "HeroDown" appears?

I Also need a walking animation script, for an example I have 3 Sprites for walking down...
"HeroDown1", "HeroDown2", "HeroDown3"?

That's for the animation.

Thanks for help

About the author

Recent Threads


#1
09/22/2007 (4:42 am)
Noone knows a solution? XD
#2
09/25/2007 (3:16 pm)
Ok, it seems that it is impossible to do it with TXB right?
I mean, if noone knows a solution... there will be just the 360 Degree turning of my Hero in "90 Degree Topdown view" >.<

I can not realize my game with TXB, does anybody knows another good program?
#3
09/26/2007 (9:11 pm)
What I did was create an Animation component. This component has a property called state. When the sprite should be stopped (show animation stopped) state is set to STOPPED, when it should be showing the walking animation state = WALKING. In the ProcessTick I check for two things, which way the "character" or "monster" is facing and then I show the current animation based on its state.

e.g.

//Figure out which way the enemy is facing, North, NE, E, etc..
SetFacing();

//Animation
ShowAnimation();


In the show animation I load the specific animation data based on the character or monsters state AND which way he/it is facing:

for example:

public void ShowAnimation()
{
//Check which way the Actor is facing, then what Actor is doing, then show that animation
switch (_facing)
{
case NORTH:
switch (_state)
{
case WALKING:
if (((T2DAnimatedSprite)_sceneObject).AnimationData != anim_walk_north)
{
((T2DAnimatedSprite)_sceneObject).AnimationData = anim_walk_north;
((T2DAnimatedSprite)_sceneObject).PlayAnimation();
}
break;
case STOPPED:
if (((T2DAnimatedSprite)_sceneObject).AnimationData != anim_stopped_north)
{
((T2DAnimatedSprite)_sceneObject).AnimationData = anim_stopped_north;
((T2DAnimatedSprite)_sceneObject).PlayAnimation();
}
break;


etc.....

where for example:

anim_stopped_north = TorqueObjectDatabase.Instance.FindObject("Aidan_Stopped_N");

does that makse sense?

RH
#4
09/28/2007 (4:20 pm)
Hello,
first of all, thanks to you

yeah it looks well, but i do not know where i should insert the script?

I'm very new at this... maybe, with a sample which i could change it would really help me to understand.
Because inserting is a problem for me, as i called, im very new at scripting. :)
#5
09/29/2007 (10:42 am)
I highly recommend you do the tutorials, this is where I started (I am new too). Run through both tutorials(Blaster and Microbes), liks to them can be found in the documentation, which if you did a default install will be at: (type in your browser) "C:\Program Files\GarageGames\Torque X\v1.0.5.1\Docs\default.htm".

It shows you how to create "components", these are blocks of code which you then attach to your objects using the TXB editor. I simply created an animation component and added it my Character and any Monsters so they can display animations.
#6
09/30/2007 (3:41 am)
Yeah but this tutorial has a bug.
At point 2 (Blaster) "Hooking up the Code", there is the code:

" SceneLoader.Load(@"data\levels\tutorial.txscene"); "

but this code is not working, because the "(" and is an invalid token. So i do not know what i should do.
I changed the words, which i needed to change like "tutorial.txscene" into Debugstage.txsene (i called my scene so^^)

So, what now? XD
#7
09/30/2007 (4:35 pm)
I am unsure as to the exact issue. The code line you show should be in the proj by default in the BeginRun method and should not need modifying...
#8
10/01/2007 (11:51 am)
Maybe i can mail you the programm so you can help?
but only if you want ;)
#9
10/01/2007 (9:08 pm)
I am sorry I don't have time. I am having enough issues getting my own one to work (I am stuck on an issue right now), and my time is very limited.

Sorry.

Rh
#10
10/02/2007 (7:46 am)
Hey, of course it's not a problem^^
I will try some other methods,...

but thanks for a lot of help!