Okay, so I'm trying to use Canvas to make a simple little thing where you can move a ball around using the Wii U GamePad. If you don't know, the Wii U has a web browser which is capable of reading controller input. Here's
all the info. It's really neat ^_^
Anyway, I've got my code and everything works fine except for the loop, and I just can't tell why. Here, first just look at my code. Bear with me, I'm just copy-pasting the whole thing.
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = 854;
canvas.height = 480;
// Creates the canvas and sticks it on the page.
var circleX = 427;
var circleY = 240;
// Starts the circle in the center of the canvas.
// I'll try "var circleX = canvas.width / 2" after I'm sure everything else works. One thing at a time.
circleX = circleX + wiiu.gamepad.lStickX + wiiu.gamepad.rStickX;
circleY = circleY + wiiu.gamepad.lStickY + wiiu.gamepad.rStickY;}
// Moves the circle if the Wii U Gamepad analog sticks are being moved.
ctx.clearRect(0, 0, canvas.width, canvas.height);}
// Erases the canvas. Kind of...kind of an obvious one, there >_>
ctx.arc(circleX, circleY, 10, 0, Math.PI*2, true);
// Draws a filled circle with radius 10 at (circleX,circleY)
Okay, if I follow this up by simply posting the code...
...it works! I can move the circle around fine and dandy. Note that I had to offset the intervals so that you could see the circle; if I had them all at 10 milliseconds, it'd blink too fast.
But, if, instead of the previous code, I do this...
// The game loop.
// Runs jamesLoopton every ten milliseconds.
...it doesn't work! Nothing does anything, I just stare at a blank canvas.
What am I doing wrong, why doesn't this work?