Datablocks and Sprite Animations
by C Martin · in Torque Game Builder · 09/10/2008 (6:17 am) · 11 replies
Hi All,
Just wondering if you could answer a question for me. I need to load a sprite sheet and iterate through the cells on a per-frame basis. Can someone give me some info on how to achieve this? I've had a look at the PlatFormer player tutorial - but it's a bit light on background info (which datablocks file should it go in? What IS a datablock??) - and overly complex to get get a basic gist of what I need to do.
Any thoughts would be greatly appreciated!
Just wondering if you could answer a question for me. I need to load a sprite sheet and iterate through the cells on a per-frame basis. Can someone give me some info on how to achieve this? I've had a look at the PlatFormer player tutorial - but it's a bit light on background info (which datablocks file should it go in? What IS a datablock??) - and overly complex to get get a basic gist of what I need to do.
Any thoughts would be greatly appreciated!
About the author
#2
I had a look at the animation builder, but doesn't quite give the flexibility I require - I need to translate the character at different rates during the playing of the animation and on specific frames. As well as that the character can be viewed from 8 different angles and i'll need to be able to switch/blend betwen the appropriate frames when this occurs. It's a pretty basic animation, but there are some complexities introduced by the 8 potential animation states.
So basically i'm looking for information on iterating through the cells of a spritesheet so I can handle these requirements.
I can do this in most other languages easily, but i'm just getting familiar with how TGB and Torque Script works and there are appears to be a lot of assumed knowledge in the tutorials.
Thanks again for your time.
09/10/2008 (7:28 am)
Hey, thanks for the reply. :)I had a look at the animation builder, but doesn't quite give the flexibility I require - I need to translate the character at different rates during the playing of the animation and on specific frames. As well as that the character can be viewed from 8 different angles and i'll need to be able to switch/blend betwen the appropriate frames when this occurs. It's a pretty basic animation, but there are some complexities introduced by the 8 potential animation states.
So basically i'm looking for information on iterating through the cells of a spritesheet so I can handle these requirements.
I can do this in most other languages easily, but i'm just getting familiar with how TGB and Torque Script works and there are appears to be a lot of assumed knowledge in the tutorials.
Thanks again for your time.
#4
everything has to do with logic and time events.
look for onAnimationEnd method
09/10/2008 (10:20 am)
Check the mole tutorial, it will be very useful to understand what you are trying to do.everything has to do with logic and time events.
look for onAnimationEnd method
#5
09/11/2008 (3:39 am)
Thank you very much for your assistance. That seems to be what i'm looking for (both of you) :)
#6
I've got a couple of additional questions to get me over the line:
1. How do you actually determine what your scenegraph is in code? - Think i've answered this - I can use the return value from sceneWindow2D.loadLevel() correct?
2. How do I actually create a datablock? I can see how I can use the functions above, but my issue is that I can't actually get an image to display - there are no errors on the console, and no hints as to what i've done wrong:
I'm using the following code - which is out of a (pretty out of date) tutorial on the TDN:
// The game startup script
function startup(%mySceneGraph)
{
// set up the enemy
datablock t2dImageMapDatablock(enemyship1ImageMap)
{
imageMode = full;
imageName = "~/data/images/enemy";
};
%enemy = new t2dStaticSprite() { scenegraph = %mySceneGraph; };
%enemy.setSize( "5 5" );
%enemy.setPosition("0 0");
%enemy.setImageMap( enemyship1ImageMap , 0);
%enemy.setVisible(true);
}
Thanks in advance guys - your help has been much appreciate so far!
09/16/2008 (5:15 am)
Ah god - not quite there! :)I've got a couple of additional questions to get me over the line:
1. How do you actually determine what your scenegraph is in code? - Think i've answered this - I can use the return value from sceneWindow2D.loadLevel() correct?
2. How do I actually create a datablock? I can see how I can use the functions above, but my issue is that I can't actually get an image to display - there are no errors on the console, and no hints as to what i've done wrong:
I'm using the following code - which is out of a (pretty out of date) tutorial on the TDN:
// The game startup script
function startup(%mySceneGraph)
{
// set up the enemy
datablock t2dImageMapDatablock(enemyship1ImageMap)
{
imageMode = full;
imageName = "~/data/images/enemy";
};
%enemy = new t2dStaticSprite() { scenegraph = %mySceneGraph; };
%enemy.setSize( "5 5" );
%enemy.setPosition("0 0");
%enemy.setImageMap( enemyship1ImageMap , 0);
%enemy.setVisible(true);
}
Thanks in advance guys - your help has been much appreciate so far!
#7
%enemy = new t2dStaticSprite() { scenegraph = %mySceneGraph; config=enemyship1ImageMap; };
I *think* this should work.
09/16/2008 (7:35 am)
Try:%enemy = new t2dStaticSprite() { scenegraph = %mySceneGraph; config=enemyship1ImageMap; };
I *think* this should work.
#9
new t2dSceneWindow(sceneWindow2D) {...}
This should be your games sceneWindow.
Now according to: TGB Reference
You should be able to call getSceneGraph();
This should get you the current scenegraph.
As to why the config line works on the new t2dStaticSprite is that datablocks are used to define the "static" data used during creation. Its a bit complicated but if you study some of the samples and do some experimentation you should be able to figure out how datablocks work..
Another way that I learned was to use the editor to add sprites to a level, then open the .t2d (level) files and see what the editor created.
09/16/2008 (7:47 pm)
Regarding how to determine your scenegraph, If you look into your .gui files, you should find something similar to the following:new t2dSceneWindow(sceneWindow2D) {...}
This should be your games sceneWindow.
Now according to: TGB Reference
You should be able to call getSceneGraph();
This should get you the current scenegraph.
As to why the config line works on the new t2dStaticSprite is that datablocks are used to define the "static" data used during creation. Its a bit complicated but if you study some of the samples and do some experimentation you should be able to figure out how datablocks work..
Another way that I learned was to use the editor to add sprites to a level, then open the .t2d (level) files and see what the editor created.
#10
Datablock Reference
09/16/2008 (7:55 pm)
Also, another way that should work to create your t2dStaticSprite is something like:%enemy = new t2dStaticSprite()
{
scenegraph = %mySceneGraph;
imagemap = enemyship1ImageMap;
size = "5.0 5.0";
position = "0.0 0.0";
...
};Datablock Reference
#11
Thanks again. :)
09/17/2008 (7:37 am)
There is a lot of really good information there - thanks! I think once I get my head around the paradigms used in TGB it will all come together. Thanks again. :)
Associate James Ford
Sickhead Games