Code:
// This next one I want text to fade in.
// I thought that I'd be able to set the alpha channel to a variable but that doesn't seem to be working.
// Any ideas?
// Global variables
var frame_no = 1;
var c, ctx, int;
// Sytax error fixed, added extra functionality for fade in or out. Thanks Aea!
function textFade(tPX, tPY, text, no_of_frames, current_frame, fS, in_out, style)
{
if (in_out==1)
{
var alpha = (current_frame/(no_of_frames-fS));
ctx.fillStyle = "rgba(255, 255, 255, " + alpha + ")";
ctx.font = "bold 16px Arial";
ctx.fillText(text, tPX, tPY);
}
else
{
var alpha = (1-(current_frame/(no_of_frames-fS)));
ctx.fillStyle = "rgba(255, 255, 255, " + alpha + ")";
ctx.font = style;
ctx.fillText(text, tPX, tPY);
}
}
function drawCanvas()
{
// When the animation starts with values input.
if ((frame_no >= 0) && (frame_no <=15))
{
textFade(250, 50, "Hello World", 15, frame_no, 0, 0, "bold 24px Arial");
}
}
Bookmarks