Create animation
by Danny Mejia · in Torque Game Builder · 02/21/2007 (7:38 pm) · 9 replies
I need to Create t2dAnimatedSprite()
Here is what I have
function CreateShape(%this)
{
%s = new t2dAnimatedSprite()
{
scenegraph = %this.scenegraph;
class = Shape;
};
%s.setAnimation(white_skull_animAnimation);
%s.setPosition(50,50);
}
Here is what I have for the keyboard:
function Shape::onLevelLoaded(%this, %sceneGraph)
{
moveMap.bind(keyboard, "w", "CreateShape;");
}
But nothing happen. I need the shape to be made when I press down a button.
Here is what I have
function CreateShape(%this)
{
%s = new t2dAnimatedSprite()
{
scenegraph = %this.scenegraph;
class = Shape;
};
%s.setAnimation(white_skull_animAnimation);
%s.setPosition(50,50);
}
Here is what I have for the keyboard:
function Shape::onLevelLoaded(%this, %sceneGraph)
{
moveMap.bind(keyboard, "w", "CreateShape;");
}
But nothing happen. I need the shape to be made when I press down a button.
About the author
#2
function createBlock()
{
%piece = new t2dAnimatedSprite() { scenegraph = scenewindow2d.getSceneGraph(); };
%piece.setSize(5.25, 5.25);
%piece.playAnimation(animAnimationName);
%piece.setLayer(0);
%piece.setPostion(100,100);
return %piece;
}
Am able to call this from the console. I have try to put this in the Main.cs like this:
function setupKeybinds()
{
new ActionMap(moveMap);
moveMap.bind("keyboard", "a", "createBlock();");
}
So am just doing something worng when try to call the method from the key board.
Thanks for any help.
02/22/2007 (7:52 am)
What I need is the create a new t2dAnimatedSprite() when I press down a key. Where should I put my moveMap.bind calls at. The Player will also be able to move the block left and right. But the block dose not apper until the player press the space bar. Here is my New function for the block:function createBlock()
{
%piece = new t2dAnimatedSprite() { scenegraph = scenewindow2d.getSceneGraph(); };
%piece.setSize(5.25, 5.25);
%piece.playAnimation(animAnimationName);
%piece.setLayer(0);
%piece.setPostion(100,100);
return %piece;
}
Am able to call this from the console. I have try to put this in the Main.cs like this:
function setupKeybinds()
{
new ActionMap(moveMap);
moveMap.bind("keyboard", "a", "createBlock();");
}
So am just doing something worng when try to call the method from the key board.
Thanks for any help.
#3
02/22/2007 (8:03 am)
There are several places you could do it. Try in game.cs, in the startGame function, after the level load.
#4
02/22/2007 (9:01 am)
Ok I got the method to call when I press the space bar. But it call the method two time for each press. How can I stop this?
#5
02/22/2007 (9:15 am)
You could either switch to bindCmd which lets you define separate functions for key press and key release, or you could modify your function so that it understands if it's being called with a press or release:function createBlock(%val)
{
if (%val == 1)
{
// do some stuff
}
}
#6
02/22/2007 (9:17 am)
Ok I got the method to call when I press the space bar. But it call the method two time for each press. How can I stop this?
#7
02/22/2007 (9:18 am)
Thanks I will try that in a few mins.
#8
02/22/2007 (10:12 am)
Thanks I will try that in a few mins.
#9
02/22/2007 (1:31 pm)
Ok that works. Thanks
Torque Owner Dan Maruschak
Even if the function was called, I think the syntax on your keybind may be a bit off. I get warnings in the console when I try to do it the way you have it. This works a little better for me:
So, that would get your function called, but your CreateShape function isn't exactly written the way you want it to be for the way it's called. The moveMap.bind function will cause the function to be called with an argument of "1" when the key is pressed and "0" when it's released (so it will be called a total of two times for each key press). You've written the function as if it were a method and are expecting an object to get passed to it. Since the %this parameter won't be set to any kind of useful object in the function, you'll need to get the scenegraph in another way, such as: