Changing the visiblity of t2dStaticSprites
by RollerJesus · in Torque Game Builder · 12/17/2008 (7:30 am) · 6 replies
If I call the playAnim("#") function from the onMouseDown, everything seems to work fine but when I call the playIntroAnim() function, nothing shows up regardless of how high I set %introDelay.
$ANIMATION is set to true...
Some help here would really be appreciated.
$ANIMATION is set to true...
Some help here would really be appreciated.
function playIntroAnim()
{
if($ANIMATION)
{
if($DEBUG)
{
echo("Playing intro animation.");
}
%introDelay = 250;
schedule(%introDelay, 0, showBaseImage);
schedule(%introDelay, 0, playAnim, 1);
schedule(%introDelay, 0, showBaseImage);
schedule(%introDelay, 0, playAnim, 2);
schedule(%introDelay, 0, showBaseImage);
schedule(%introDelay, 0, playAnim, 3);
schedule(%introDelay, 0, showBaseImage);
schedule(%introDelay, 0, playAnim, 4);
schedule(%introDelay, 0, showBaseImage);
}
showBaseImage();
}
//Show lights out image
function showBaseImage()
{
if($DEBUG)
{
//echo("showBaseImage was called");
}
introAnimation.Visible = false;
RedPress.Visible = false;
yellowPress.Visible = false;
BluePress.Visible = false;
GreenPress.Visible = false;
baseImage.Visible = true;
}
//Triggers for the lights
function playAnim(%color)
{
%tempColor = %color;
if($ANIMATION)
{
if(%tempColor == 1) //Green
{
RedPress.Visible = false;
yellowPress.Visible = false;
BluePress.Visible = false;
GreenPress.Visible = true;
}
if(%tempColor == 2) //Red
{
yellowPress.Visible = false;
BluePress.Visible = false;
GreenPress.Visible = false;
RedPress.Visible = true;
}
if(%tempColor == 3) //Yellow
{
RedPress.Visible = false;
BluePress.Visible = false;
GreenPress.Visible = false;
yellowPress.Visible = true;
}
if(%tempColor == 4) //Blue
{
RedPress.Visible = false;
yellowPress.Visible = false;
GreenPress.Visible = false;
BluePress.Visible = true;
}
}
}
#2
When you go into the console with your debug turned on, do you see your echo statement? If so I would think it is playing but something is masking it, or maybe its position is way off.. Also does it know the sceneGraph? Just shooting in the dark to help stimulate some more ideas. Good luck, hope you figure it out.
Dane
12/17/2008 (4:32 pm)
I am sure I will probably not be any help but I figured I would try since I am also all over here begging for help :). I see that when you play the baseImage it sets the introAnimation.visible to false. Have you tried adding in the IntroAnimation function to set the visibility to true as well? I am pretty sure you have already tried this, only other thing I can guess is maybe the layer order?When you go into the console with your debug turned on, do you see your echo statement? If so I would think it is playing but something is masking it, or maybe its position is way off.. Also does it know the sceneGraph? Just shooting in the dark to help stimulate some more ideas. Good luck, hope you figure it out.
Dane
#3
I was hoping I could get this to work as I planned because I fire off the sounds and am using the playAnim() function in the mouse callback, but alas it seems as if this plan wasn't meant to be. So, I fell back to a previous design where I created an animated sprite with the images called by playAnim() and call it as like so:
So now the intro plays but I still haven't figured out the other part that is using the playAnim() functions. I created all the images as a buttonClass and I'm working on extending some callbacks for them because as far as I can tell, the old code wasn't working because TGB was just ripping right through them and paying no mind to the schedule call since it wasn't attached to an object. (ie: I could step through in the debugger and all those calls were being made in the original playAnim()).
Patrick
12/17/2008 (7:32 pm)
Thanks for the ideas Dane!I was hoping I could get this to work as I planned because I fire off the sounds and am using the playAnim() function in the mouse callback, but alas it seems as if this plan wasn't meant to be. So, I fell back to a previous design where I created an animated sprite with the images called by playAnim() and call it as like so:
function playIntroAnim()
{
playSE("startGame", $VOLUME); //Play start sound
if($ANIMATION)
{
if($DEBUG)
{
echo("Playing intro animation.");
}
IntroAnimation.setVisible(true);
IntroAnimation.playAnimation(IntroAnimation, true, 0, true);
}
}So now the intro plays but I still haven't figured out the other part that is using the playAnim() functions. I created all the images as a buttonClass and I'm working on extending some callbacks for them because as far as I can tell, the old code wasn't working because TGB was just ripping right through them and paying no mind to the schedule call since it wasn't attached to an object. (ie: I could step through in the debugger and all those calls were being made in the original playAnim()).
Patrick
#4
12/17/2008 (9:09 pm)
You know, you are scheduling each of those events to happen at the same time, not one after another ;)
#5
I've stepped through it and the array is populated correctly, it executes as planned but it only shows the last image in the array.
My current idea here is to just stop using t2dStaticSprites and use t2dAnimatedSprites again so I can call the:
schedule($PLAYSPEED, 0, showBaseImage)
from the buttonClass::onAnimationEnd callback.
12/18/2008 (8:31 am)
I kinda figured that's what was happening but I still can't figure out why this doesn't work.function playAnimation()
{
for(%j = 0; %j < $ROUND; %j++)
{
%temp = $Pattern.get(%j);
playAnim(%temp);
schedule($PLAYSPEED, 0, showBaseImage);
}
}I've stepped through it and the array is populated correctly, it executes as planned but it only shows the last image in the array.
My current idea here is to just stop using t2dStaticSprites and use t2dAnimatedSprites again so I can call the:
schedule($PLAYSPEED, 0, showBaseImage)
from the buttonClass::onAnimationEnd callback.
#6
You would need to schedule them at an interval:
This should replicated what you had in your first post, except add a 1 second delay between each schedule.
12/18/2008 (11:31 am)
If you are scheduling them to all happen at the same time, then they will all execute at the same time and you won't see anything happen.You would need to schedule them at an interval:
for (%i = 0; %i < 10; %i++)
{
if (((%i + 1) % 2) == 0)
{
schedule(%introDelay + %i * 1000, 0, playAnim, (%i + 1) / 2);
}
else
{
schedule(%introDelay + %i * 1000, 0, showBaseImage);
}
}This should replicated what you had in your first post, except add a 1 second delay between each schedule.
Torque Owner RollerJesus
Dream. Build. Repeat.
Anyone have a minute to share some ideas? I'd really like to get this squared away so I can move on to the sound.
Pah - lease!