Spawning Objects can't find Animation
by MikeJ · in iTorque 2D · 06/03/2011 (2:01 pm) · 17 replies
Hi. I'm a noob. I'm having a problem creating an object, assigning an animation and then positioning the object.
My Code.
The error I am getting is:
1. There is an animated sprite in my library named'dude_animation1';
2. I have added said animated sprite to my scene and added it to the datablock for the level.
What am I missing???
My Code.
function create_dude(%id,%position){
%dude = new t2dAnimatedSprite(){
sceneGraph = %this;
class="dudeClass";
layer="2";
name = "dude1";
size="130 130";
}
%dude.playAnimation("dude_animation1");
%dude.setPosition(%position);
}The error I am getting is:
t2dAnimationController::playAnimation() - Invalid t2dAnimationDatablock datablock (dude_animation1)
1. There is an animated sprite in my library named'dude_animation1';
2. I have added said animated sprite to my scene and added it to the datablock for the level.
What am I missing???
#2
I am actually referencing the code from the Mole Whacking game to spawn moles. Only problem is that I can't see the actual scene files to see how the animations are included.
Their code:
06/03/2011 (2:30 pm)
Nope, not a behavior. That's a different story entirely. I can't even get behaviors to show up as options so that's out of the question.I am actually referencing the code from the Mole Whacking game to spawn moles. Only problem is that I can't see the actual scene files to see how the animations are included.
Their code:
%mole = new t2dAnimatedSprite()
{
sceneGraph = %this;
class = "Mole";
layer = 4;
size = "9.125 16";
};
// play the right animation according to the color
%mole.playAnimation("animMoleComeOut" @ %color);
#3
to use behaviors, you need to create a "behaviors" folder and place it in the scripts folder. You place them in there, you see your behaviors in editor.
06/03/2011 (2:39 pm)
to see the scene files go to game/data/levels/levelX.t2dto use behaviors, you need to create a "behaviors" folder and place it in the scripts folder. You place them in there, you see your behaviors in editor.
#4
06/03/2011 (2:41 pm)
Ahhh. ok. So do you suggest using behaviors over having all the actions in separate functions within the object's class?
#5
06/03/2011 (2:43 pm)
Well, I was a nothing programer when I joined Torque two years ago. I had very minimal background in HTML and Flash, so I found behaviors just easier to learn with and have stuck with them. If you talk to more experienced programmers, many have said they prefer class scripts. All though I think technically there is no difference in terms of the performance on the engine. Tho.. I could be wrong.
#6
I think I figured out one issue with my sprite...
I have that function that creates the animated sprite within a class. "LevelClass"
I just didn't apply that level class to the Scenegraph.
Now It looks like that error is gone, however my sprite is not appearing on the stage... Should I change
06/03/2011 (2:49 pm)
I'm an OOP programmer, I'm used to PHP and Actionscript so it is a little more natural for me.I think I figured out one issue with my sprite...
I have that function that creates the animated sprite within a class. "LevelClass"
function LevelClass::createdude(%id,%position){I just didn't apply that level class to the Scenegraph.
Now It looks like that error is gone, however my sprite is not appearing on the stage... Should I change
%dude.playAnimation();to
%dude.setAnimation();???
#7
and make sure the info is in the managed AND level datablocks.
ps. I have never used setAnimation yet.
06/03/2011 (2:50 pm)
well you need to include %dude.playAnimation(animationName);and make sure the info is in the managed AND level datablocks.
ps. I have never used setAnimation yet.
#8
Sorry, I'm new. Not sure what that means...
06/03/2011 (2:51 pm)
Quote:and make sure the info is in the managed AND level datablocks.
Sorry, I'm new. Not sure what that means...
#9
06/03/2011 (2:55 pm)
well there is a datablock.cs file for the entire project. As soon as you import any sprite or create any animation into the project, the respective datablocks are automatically created. BUT, you must learn young jedi the ways of the torque. For some reason, I am not sure why, BUT there are also level dataBlaocks. They are held in the levels/datablocks folder. You can pass them into that respective level file simply by clicking a little "chain looking" like button at the topr left of the editor. You will see a list of all project datablocks then you have the option to pass any one into the level_dataBlock.cs. if you dont do this, you will not see your images in the scene when you run your game.
#10
Sorry to be a pain.
06/03/2011 (2:59 pm)
Oh, ok. Gotcha. Yep, I can confirm that the animation datablock is in both files. Still nothing...Sorry to be a pain.
#11
ps. if you need the object to move, usesPhysics must be set to true.
good luck.
::)((!!
06/03/2011 (3:03 pm)
Well I gotta shoot out now. Not sure what else to tell you besides this... if you are wanting to create an animation in script, so say on event. here is an example from me.$awesomeAnimationObj = new t2dAnimatedSprite(awesomeAnimationOb)
{
scenegraph = %this.owner.scenegraph;
animationName = "awesomeAnimation";
mUseSourceRect = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
layer = "31";
Position = "-134.322 -82.357";
size = "18.270 36.540";
usesPhysics = "0";
CollisionActiveSend = "0";
CollisionActiveReceive = "0";
CollisionPhysicsSend = "0";
CollisionCallback = "0";
CollisionCircleScale = "0.1";
CollisionMaxIterations = "0";
BlendColor = "0.000000 0.815686 0.070588 1.000000";
MountOwned = "0";
MountInheritAttributes = "0";
mountID = "41";
mountToID = "40";
group = 27;
};ps. if you need the object to move, usesPhysics must be set to true.
good luck.
::)((!!
#12
just make sure your "animationName" = your actual animation name that you saved your animation as in the editor.
**Then I make sure of this...(Something that gave me a headache for a day). Make sure that when you pass your datablocks into your levelDatablocks that you first pass the imageMap then the animation datablock in that order. If you happen to pass the animation datablock first, before the imageMap datablock, the project will not see the source for the animation.
hope that helps.
06/03/2011 (5:20 pm)
did you get it?just make sure your "animationName" = your actual animation name that you saved your animation as in the editor.
**Then I make sure of this...(Something that gave me a headache for a day). Make sure that when you pass your datablocks into your levelDatablocks that you first pass the imageMap then the animation datablock in that order. If you happen to pass the animation datablock first, before the imageMap datablock, the project will not see the source for the animation.
hope that helps.
#13
As soon as I learn one new thing I get instantly hung up on the next step of the process.
06/03/2011 (6:16 pm)
Yes, my animationName is exactly that of my animation and my ImageMapDatablock is above (before) my Animation Datablock. Torsion is no longer spitting out errors so I'm not even sure why it is not placing the object in the scene but this is getting really frustrating.As soon as I learn one new thing I get instantly hung up on the next step of the process.
#14
06/03/2011 (6:24 pm)
Thanks for your help BTW!
#15
So you didn't get it yet?
What is happening? You are expecting to see an animation, created on call, but nothing appears?
idk. just set echos etc.
?///
06/03/2011 (7:32 pm)
No worries.So you didn't get it yet?
What is happening? You are expecting to see an animation, created on call, but nothing appears?
idk. just set echos etc.
?///
#17
http://pastebin.com/uzpnFe7Q
My Function:
I am actually echoing the data from the instantiated object through the class that I have applied to it and it IS echoing in the console correctly (%this.name). The only problem is that I can't actually see the thing.
----------------------------------------------------------------------
I started with a blank slate with fresh code and had the same problem. Nothing is instantiating.
Here is the process I am taking, perhaps I am wrong at some point:
1. Create new Project.
2. Create New Image Map selecting my sprite sheet.
3. Double-clicking on sprite sheet converting the spritesheet to "Cell" image mode fixing the cell width and height and saving.
4. Create the animation, selecting my image map, adding frames and then naming the animation and saving.
5. Drag my object into the camera or on the stage and add both the ImageMapDatablock, and AnimationDatablock to the Level Datablock via the little "link" button. Making sure that the Image Map is above the Animation.
6. I create a new script in my library, execute that in my "game.cs" file and add the following script:
I thought it was the scenegraph being wrong, so I tried every combination of %this, %scenegraph, %this.object.scenegraph, %this.scenegraph and still nothing.
This one is spitting out the error that it can not find the object block either even though I have it in both the level and main datablocks.
Still... Nothing happens.
06/04/2011 (6:15 am)
My Console log:http://pastebin.com/uzpnFe7Q
My Function:
function architect::create_monster(%id,%position){
%posY = getVariable("$row" @ %position @ "Y");
%posX = $monster_startX;
%walk_animation = $monsters[%id,1] @ "walk";
%nmonster = new t2dAnimatedSprite(){
sceneGraph = %this;
animationName = %walk_animation;
class="monsterClass";
layer = "6";
size = "130 75";
useMouseEvents = "1";
WorldLimitMax = $monster_worldMaxX;
WorldLimitMin = $monster_worldMinX;
WorldLimitMode = "2";
num = %id;
name = $monsters[%id,0];
sprite = $monsters[%id,1];
speed = $monsters[%id,2];
osity = $monsters[%id,3];
blockage = $monsters[%id,4];
health = $monsters[%id,5];
usesPhysics = "1";
};
%nmonster.playAnimation("blobberwalk");
%nmonster.setPosition(13,-29);
}I am actually echoing the data from the instantiated object through the class that I have applied to it and it IS echoing in the console correctly (%this.name). The only problem is that I can't actually see the thing.
----------------------------------------------------------------------
I started with a blank slate with fresh code and had the same problem. Nothing is instantiating.
Here is the process I am taking, perhaps I am wrong at some point:
1. Create new Project.
2. Create New Image Map selecting my sprite sheet.
3. Double-clicking on sprite sheet converting the spritesheet to "Cell" image mode fixing the cell width and height and saving.
4. Create the animation, selecting my image map, adding frames and then naming the animation and saving.
5. Drag my object into the camera or on the stage and add both the ImageMapDatablock, and AnimationDatablock to the Level Datablock via the little "link" button. Making sure that the Image Map is above the Animation.
6. I create a new script in my library, execute that in my "game.cs" file and add the following script:
function makeguy(){
%guy = new t2dAnimatedSprite(){
scenegraph = %this.object.scenegraph;
Position = "12 -29";
animationName = "BlobberAnimation";
size = "130 75";
};
}
makeguy();I thought it was the scenegraph being wrong, so I tried every combination of %this, %scenegraph, %this.object.scenegraph, %this.scenegraph and still nothing.
This one is spitting out the error that it can not find the object block either even though I have it in both the level and main datablocks.
Still... Nothing happens.
Torque Owner rennie moffat
Renman3000