Swapping animation for sprite?
by Adam Griffiths · in Torque Game Builder · 02/26/2008 (5:57 am) · 4 replies
Hey all,
I'm trying to get an animated sprite to change into a single image after collision with an object, but i can't seem to get it to work. I've been using the BahaviourPlayground example (swap image on collision) and have tried to change the t2dImageMapDatablock from ImageMap to Animated (see code), i've also tried t2dAnimatedSpriteDatablock but it either has no effect or stops single images from working altogether.
i've also changed the %this.owner.setImageMap(%this.image, %this.frame); to be .setAnimated etc too.
I have few programming skills (i'm an artist not a programmer). I'd really appreciate any help offered
I'm trying to get an animated sprite to change into a single image after collision with an object, but i can't seem to get it to work. I've been using the BahaviourPlayground example (swap image on collision) and have tried to change the t2dImageMapDatablock from ImageMap to Animated (see code), i've also tried t2dAnimatedSpriteDatablock but it either has no effect or stops single images from working altogether.
i've also changed the %this.owner.setImageMap(%this.image, %this.frame); to be .setAnimated etc too.
I have few programming skills (i'm an artist not a programmer). I'd really appreciate any help offered
//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
if (!isObject(SwapImageOnCollisionBehavior))
{
%template = new BehaviorTemplate(SwapImageOnCollisionBehavior);
%template.friendlyName = "Swap Image On Collision";
%template.behaviorType = "Effects";
%template.description = "Switches the image of an object when it collides";
%template.addBehaviorField(image, "The image to swap to", object, "", t2dImageMapDatablock);
%template.addBehaviorField(frame, "The frame of the image to swap to", int, 0);
}
function SwapImageOnCollisionBehavior::onBehaviorAdd(%this)
{
%this.owner.collisionCallback = true;
}
function SwapImageOnCollisionBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if (isObject(%this.image))
%this.owner.setImageMap(%this.image, %this.frame);
}
#2
The only problem is i cannot select an animation from the swap image event, it will only allow for single images to be used. Also i cannot create an animated (single image) sprite as TGB doesn't allow for .gif or alternative animated sprite formats?
I created an animation (of a single sprite) but when i try to select it from the oncollision swap image option box the animation is never available to select, only single images.
Hope that makes sense?
many thanks
Adam
02/26/2008 (8:09 am)
Many thanks for the reply Dan, The only problem is i cannot select an animation from the swap image event, it will only allow for single images to be used. Also i cannot create an animated (single image) sprite as TGB doesn't allow for .gif or alternative animated sprite formats?
I created an animation (of a single sprite) but when i try to select it from the oncollision swap image option box the animation is never available to select, only single images.
Hope that makes sense?
many thanks
Adam
#3
02/26/2008 (9:09 am)
@Adam - You'll need to create your own behavior, or modify this one. Instead of a line like this:%template.addBehaviorField(image, "The image to swap to", object, "", t2dImageMapDatablock);you'll want something like
%template.addBehaviorField(animation, "The animation to play", object, "", t2dAnimationDatablock);This will let you select animations in the behavior rollout in TGB. Does that make sense?
#4
many thanks Dan :-)
02/26/2008 (9:29 am)
Yes, many thanks, i've already tried it with the t2dAnimationDatablock, but didn't use the playAnimation function, i'll give it a whirl.many thanks Dan :-)
Torque Owner Dan Maruschak