Game Development Community

Some getting started help

by Philip Gregory · in Torque 2D Beginner · 03/18/2013 (6:28 pm) · 14 replies

Starting out, I have three questions:

1.) I wanted to copy the MoveToToy toy and rename the copy to ClickToMove toy (And use the Knight moving West animation instead of the "sight"). When I cop the toy and rename it, then open the toy in T2D, nothing happens or appears. Is there a logical explanation to this?

2.) I got the Knight animation to work (using the stock MoveToToy copy though) and it feels good to be playing around. I want to make an if...else statement to determine if the Knight is moving east or west. The default animation is west. So far my statement looks like:
// Move the Knight to the touched position.
    //Move West
    if (MoveToToy.TargetObject.Position < MoveToToy.SightObject.Position)
    {
      MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveTime );
    }
    //Move East with east animation
    else
    {
       MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveTime ); //Using East Animation or //flipped West animation???
    }
Am I on the right track with this one?

3.) Can I use TorqueScript to vertically flip the West animation (to move "east")?

About the author

Yes... Those are ribs. Current projects: Breaking out of the box in T2D, devoting efforts and talents to Middle School student tech projects (including basic Python programming!)


#1
03/18/2013 (10:01 pm)
1) Did you rename the module in the module.taml file? And rename the module's namespace in the scripts?

2) Sort of. I'd use the difference of the object position and target position, then dot product to get an angle - then figure what cardinal direction you're moving from that.

3) Yes. Sprite.setFlipX(true) and Sprite.setFlipY(true) will flip the sprite on the X and Y axis respectively.
#2
03/18/2013 (10:20 pm)
1.) Simply copying the files won't do the trick, you need to modify the module.taml file as well! Make sure the ModuleID reflects the directory name.

ModuleId="ClickToMoveToy"

Also, in your code, make sure that all functions containing 'MovetoToy::' are replaced with 'ClickToMoveToy::' instead.

2.) There are as many ways to handle input as there are users out there. If it behaves like you want it to, it is valid.

3.) Every Sprite has a FlipX and FlipY property. Set either to true to mirror the sprite on the corresponding axis.
#3
03/19/2013 (5:43 pm)
@ Both:

1.) ModuleID was set to "ActionAdventureToy"
<ModuleDefinition
	ModuleId="ActionAventureToy"
	VersionId="1"
	Description="Uses the move to toy to demonstrate an action adventure RPG."
	Dependencies="ToyAssets=1"
	Type="toy"
	ToyCategoryIndex="3"
	ScriptFile="main.cs"
	CreateFunction="create"
	DestroyFunction="destroy"/>

Both Create and Destroy functions DO EXIST in my main.cs file (since it is the stock MoveToToy script). Both the taml file and script file is in the same folder.

3.) I knew it would be a simple member function! I couldn't find it anywhere for the life of my though!

@Richard:

2.) A little over my head I think. I get the using the difference between the two positions part. -- based on if the click was to right of the Knight, the knight would use the FlipX to walk East, and if it is to the left of the knight, it would use the standard walk animation to the West.

Thanks for your help so far!
#4
03/19/2013 (6:49 pm)
Ok, but are the functions like this?
function ActionAdventureToy::create( %this )
{
...
}
Or did you leave them like this?
function MoveToToy::create( %this )
{
...
}

The create() and destroy() methods have to have the scope of the toy - use the moduleID for the scope class name.
#5
03/19/2013 (6:55 pm)
I've tried changing all instances of MoveToToy to ActionAdventureToy, but it does make since so I will try again in case I missed one.

Right now I'm stuck on getting the Knight to flip when I want to go back west. When I go east, it flips (YAY!). But if I go west, it flips the other direction anyways and I can't get it to flip back.
// Move the sight to the touched position.
    if (MoveToToy.TargetObject.PositionX > MoveToToy.SightObject.PositionX)
    {
      MoveToToy.SightObject.setFlipX (true);      
      MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveTime );
    }
    else // Flip the knight and go the other way
    {
       MoveToToy.SightObject.setFlipX (true);       
       MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveTime );
    }

Edit: This tells me that it's probably always skipping to the else statement. Logic error!
#6
03/20/2013 (12:42 am)
Quote:MoveToToy to ActionAdventureToy

Your code example above sure looks like it's using "MoveToToy" to me. Either change that to your toy name or use "%this" in its place if the code is in a "ActionAdventureToy:xxxx(%this)" method as "%this" is your toy.
#7
03/20/2013 (8:06 am)
And setFlipX(true) flips it, setFlipX(false) does not flip it. If you want it to render flipped, set to true - if you don't want it flipped (i.e. you want it to render in it's original state) set to false.

// Move the sight to the touched position.   
if (ActionAdventureToy.TargetObject.PositionX > ActionAdventureToy.SightObject.PositionX)   
{   
  ActionAdventureToy.SightObject.setFlipX (false);         
  ActionAdventureToy.SightObject.MoveTo( %worldPosition, ActionAdventureToy.moveTime );   
}   
else // Flip the knight and go the other way   
{   
  ActionAdventureToy.SightObject.setFlipX (true);          
  ActionAdventureToy.SightObject.MoveTo( %worldPosition, ActionAdventureToy.moveTime );   
}

Note that all "MoveToToy" were changed to "ActionAdventureToy" in my version of your script....
#8
03/20/2013 (11:12 am)
Let me rephrase the renaming part: In my COPY I renamed all instances of MoveToToy to ActionAdevntureToy and it still does not work. I am using the MoveToToy to go ahead and experiment although I would rather work with the copy.

@Richard - I have still yet to retry renaming everything to make sure I didn't miss anything the first time I went through. And thanks! It's always something simple when it comes to logic. I was thinking if it's flipped once, then it needs to be flipped back :p
#9
03/20/2013 (11:17 am)
@Phil : Try to set the following to true in the main.cs file that is in your top-most directory, it will tell you exactly what went wrong.

I suggest trying these one at a time or your console will be full of text and it will be hard to make sense of it all.

By the way, this is part of a 'tip of the day'. We publish tips every few days, subscribe to this feed for bite-sized tips and tricks!

www.garagegames.com/community/forums/viewthread/133185

----------

setScriptExecEcho( true ); -> Everytime a script file is executed, it will be written out to the console.

AssetDatabase.EchoInfo = true; -> Everytime an Asset is loaded or unloaded, the console will detail the asset activity, mainly the id of the loaded asset, and how many references to this asset exist in the current program.

trace(true); -> Every single time the code enters or exits a function will be listed in the console.

ModuleDatabase.EchoInfo = true; - > The console will tell you when modules are loaded and unloaded as well as the version of the concerned module.
#10
03/20/2013 (7:40 pm)
I still didn't get around to remodifying the taml or trying what Simon did, but I did get question 2 out of the way with a little ingenuity. Turns out that setting it to false was my only issue. Here's what the final (working) function looks like (used in the MoveToToy):
function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
{
    
    
    %knightx = MoveToToy.SightObject.getPositionX();
    
    
    // Set the target to the touched position.
    MoveToToy.TargetObject.Position = %worldPosition;
    %targetx = MoveToToy.TargetObject.getPositionX();
    
    // Diagnostics    
    echo( %knightx );
    echo( %worldPosition );
    
    // Move the sight to the touched position.
    if ( %knightx < %targetx )
    {
      MoveToToy.SightObject.setFlipX (true);      
      MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveTime );
    }
    else // Flip the knight and go the other way
    {
       MoveToToy.SightObject.setFlipX (false);       
       MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveTime );
    }
}
#11
03/21/2013 (12:53 am)
Edit: Please excuse the double post.
#13
03/22/2013 (6:29 pm)
Looks like my Chrome had a glitch on posting (look at the time differences on the triple post). Anyways:

I did miss one thing when replace MoveToToy with ActionAdventureToy:
renaming the package!

Thanks for the help guys!
#14
03/22/2013 (7:56 pm)
Looks like my Chrome had a glitch on posting (look at the time differences on the triple post). Anyways:

I did miss one thing when replace MoveToToy with ActionAdventureToy:
renaming the package!

Thanks for the help guys!