Game Development Community

How to change animations when a sprite is moused over?

by Andrew H · in Torque Game Builder · 07/31/2011 (5:14 pm) · 3 replies

I am trying to make a menu screen, with all the buttons being sprites. I want them to change color (animation) when moused over. Is there a mouse event for when something is moused over, and if so, how can I use it to change animations?

#1
07/31/2011 (8:16 pm)
@Laura - Yes, there is such a behavior. Look in the BehaviorPlayground project that ships with the engine. There is a mouse hover behavior that makes something happen. I don't have it in front of me, so I do not know the exact behavior code.
#2
07/31/2011 (8:37 pm)
@Michael

Oh, thanks! Looks like what I need is genericButton.cs!
#3
07/31/2011 (10:11 pm)
This code should also do the trick, depending on how your code and animations are set up:

if (!isObject(MouseOverAnimate))
{
   %template = new BehaviorTemplate(MouseOverAnimate);
   
   %template.friendlyName = "Mouse Over Animate";
   %template.behaviorType = "GUI";
   %template.description  = "Play an animation when the mouse moves over this object. ";
 
   %template.addBehaviorField(anim, "The animation to play", string, "test");   
} 
 

function MouseOverAnimate::onBehaviorAdd(%this)
{ 
    %this.owner.setUseMouseEvents(true);  
}

function MouseOverAnimate::onMouseEnter(%this, %modifier, %worldPos)
{
  if ( isobject(%this.anim) )       
    %this.owner.playAnimation(%this.anim);
}