Images are showing up but not moving
by Craig Griffiths · in Torque Game Builder · 10/20/2009 (7:18 pm) · 5 replies
I've got my food rendering on the screen by dragging and dropping it onto the scene rather than doing it through code. I realized the way I'm rendering and doing the collision test won't work out when I implement my menu because I'm going to need to be able to make the food disappear and reappear whenever the user wants. I've got a function that creates the food, and an update function that moves them. When I drag the food onto the scene the update works. When I render the food onto the scene through the code I can see them but they won't move. Also I'm a little confused on getWord() and getWorldPoint() to use them properly. I'm getting an error in console saying t2dSceneWindow::getWorldPoint() - Invalid number of parameters! I would like to get a random position for the x and y each time createFood is called. Unless anyone knows a way where I can drop the objects onto the screen and be able to render and not render them at will through a menu.
Thanks,
Craig
Thanks,
Craig
function TurtleFood::onLevelLoaded(%this, %scenegraph)
{
//Create 5 food items
for( %i = 0; %i < 5; %i++ )
{
%screenPos = getWord( %this.currentPosX, %i );
%worldPos = sceneWindow2D.getWorldPoint( %screenPos);
%this.createFood( %worldPos );
}
%this.updateMovement();
}
function TurtleFood::createFood( %worldPos )
{
//Create some food
%food = new t2dStaticSprite()
{
imageMap = "sea_urchin_1ImageMap";
frame = "0";
canSaveDynamicFields = "1";
Position = %worldPos;
size = "7.500 7.500";
WorldLimitMode = "NULL";
WorldLimitMin = "-47 -33";
WorldLimitMax = "47 36";
class = "TurtleFood";
};
sceneWindow2D.getSceneGraph().addtoScene( %food );
}
#2
like
as you can see, is as easy as 1, 2, 3 ... so, all you need is to define them, and assign a value to them ... and remember where to use them, so you dont hog up the memory with vars that wont be used .
10/21/2009 (1:14 pm)
to define and use dynamic field thru code, you just define them, and use them.like
%this.my_dynamic_var = 100; %this.my_dynamic_var_2 = "foo":
as you can see, is as easy as 1, 2, 3 ... so, all you need is to define them, and assign a value to them ... and remember where to use them, so you dont hog up the memory with vars that wont be used .
#3
10/21/2009 (6:18 pm)
Thank you very much, the more problems I run across using tgb the easier the solutions get.
#4
10/22/2009 (12:33 pm)
I've tried looking in the forums and I can't seem to find what I'm looking for. I realized by doing this my food doesn't have a collision box so how would you create a collision box around the object in code and is there a function that I can call that will display the box?
#5
now, when it comes about the collision... if you wanna enable the collisions of an object, you use this:
theres another set of commands that let you resize the collision box, define the collision mode and other things, but i just dont remember them right now, btu as usual, since they are in the Docs, you can take a look at them (under the section of reference>SceneObjects) and you'll find them... or you can make a search for Collision on the TGB network, and again, you'll find it.
GL.
10/22/2009 (12:52 pm)
if you wanna display the collision box, you need to enable the debug mode... for that, you need the command setDebugOn(%mode) ... check the docs to see what are the modes and what each mode actually does (if im not mistaken, out of the top o my head, the mode 5 will let you show the collision boxes).now, when it comes about the collision... if you wanna enable the collisions of an object, you use this:
%this.setCollisionActive(true, true)this activates the sending and receiving collision of the object.
theres another set of commands that let you resize the collision box, define the collision mode and other things, but i just dont remember them right now, btu as usual, since they are in the Docs, you can take a look at them (under the section of reference>SceneObjects) and you'll find them... or you can make a search for Collision on the TGB network, and again, you'll find it.
GL.
Craig Griffiths