Drawing a blinking textsprite
BasiliosZ

The new draw functions (documented here) are very interesting. Usually they're intuitive enough that I can figure out how to use them.

Now I'm trying to create a blinking TextSprite - for example something saying "Achievement Unlocked!". Is the blink_ function the best way to go about it?  The blink_ function requires a third parameter, another draw function - what can I use there? 

All 5 Comments
Gio

wade.drawFunctions.blink_(), like some others, does not directly draw anything - rather it modifies an existing draw function (turning it on and off periodically in this case). So you would do something like this:
 

textSprite.setDrawFunction(wade.drawFunctions.blink_(1, 1, textSprite.draw));

I am passing textSprite.draw as the last parameter, which is the current draw function of the text sprite.

This is if you want the textSprite to blink only. In the same way, you can also concatenate functions: for example you could change the transparency of the sprite (using an alpha_ function), and then make that blink, like this:

textSprite.setDrawFunction(wade.drawFunctions.blink(1, 1,wade.drawFunctions.alpha_(0.7, textSprite.draw)));
BasiliosZ

Excellent - thanks!

Adrian Browne

I have been using the quick and dirty version of blink, as:

mysprite.setDrawModifiers([{type: 'blink', timeOn: 2, timeOff: 1}])

this is fine, but how to turn blink OFF? I tried setting   {type: 'blink', timeOn:1, timeOff:0}  but no luck

any thoughts please

krumza

HI! You find answer here

You can use this code:

var a = new Sprite('sprite.png',1);
var b = new SceneObject(a);
b.originalDrawFunction = b.getSprite().getDrawFunction();
wade.addSceneObject(b,true);
wade.addEventListener(b, 'onMouseIn');
wade.addEventListener(b, 'onMouseOut');

b.onMouseIn = function() 
{
    this.getSprite().setDrawModifiers([{type: 'blink', timeOn: .05, timeOff: .05}]);
};

b.onMouseOut = function() 
{
    this.getSprite().setDrawFunction(this.originalDrawFunction); 
};

 

Adrian Browne

krumza,

thanks. works well.

Post a reply
Add Attachment
Submit Reply
Login to Reply