WickerChild
07-19-2011, 02:38 PM
Hello, I'm new to javascript and html5.
I've been having problems with some simple(?) lines of code.
var ctex;
var totalX = 400;
var totalY = 300;
var racpad = new Image();
racpad.src = 'Imgs/paddle.gif';
var brixadow = new Image();
brixadow.src = 'Imgs/brickLight.gif';
function initCnv()
{
canvas = document.getElementById('canvas01');
ctex = canvas.getContext('2d');
AppStep();
}
function clearcv(x)
{
ctex.clearRect(0, 0, totalX, totalY);
ctex.fillStyle = x;
ctex.beginPath();
ctex.rect(0, 0, totalX, totalY);
ctex.closePath();
ctex.fill();
}
function AppStep()
{
clearcv('black');
ctex.drawImage(racpad, totalX/2, totalY-50);
}
What I'm trying to do is to simply turn the canvas black and show a small gif on it. Upon executing initCnv(), the canvas turns black as it should, while the sprite image doesn't show up at all.
I can't figure out what's going on, I scoured the code for syntax errors, even tried other image formats but to no avail. Image paths are also correct.
Maybe the problem's an extremely noobish one, but I still couldn't get a clue, so I thought I'd ask for help around here.
Thanks for your time!:)
I've been having problems with some simple(?) lines of code.
var ctex;
var totalX = 400;
var totalY = 300;
var racpad = new Image();
racpad.src = 'Imgs/paddle.gif';
var brixadow = new Image();
brixadow.src = 'Imgs/brickLight.gif';
function initCnv()
{
canvas = document.getElementById('canvas01');
ctex = canvas.getContext('2d');
AppStep();
}
function clearcv(x)
{
ctex.clearRect(0, 0, totalX, totalY);
ctex.fillStyle = x;
ctex.beginPath();
ctex.rect(0, 0, totalX, totalY);
ctex.closePath();
ctex.fill();
}
function AppStep()
{
clearcv('black');
ctex.drawImage(racpad, totalX/2, totalY-50);
}
What I'm trying to do is to simply turn the canvas black and show a small gif on it. Upon executing initCnv(), the canvas turns black as it should, while the sprite image doesn't show up at all.
I can't figure out what's going on, I scoured the code for syntax errors, even tried other image formats but to no avail. Image paths are also correct.
Maybe the problem's an extremely noobish one, but I still couldn't get a clue, so I thought I'd ask for help around here.
Thanks for your time!:)