Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Html5 game

Hello everybody,

When Randy Hoyt was going through the workshop on Html5 Game Design, I was successful in creating a canvas, but when he drew the vertical rectangle, it did not execute. Any suggestions? Here's my code.

var canvas = document.GetElementById("canvas"); var context = canvas.getContext("2d");

imgFrog = new Image(); imgFrog.src = "images/mikethefrog.png"; imgFrog.addEventListener("load",init, false);

var requestAnimFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); };

function init() { requestAnimFrame(update); }

function update() {

context.fillRect( 10, 10, 40, 380, "#000000");


requestAnimFrame(update);

}

If this is not the issue, does anyone know what it is. You might need to refer to the video. Thanks.

3 Answers

I´m having exactly the same problem, any idea how to solve it? I cannot understand why is happening. The code is the same as it is in the video.

What text editor are you using? It could be a problem with the text editors we're coding on.

I figured out the problem, in the video the route for the images is /images but in the files the route is /img. Now it works.

I think I understand, would you be able to post that bit of code? Thanks!