Back to StarCatcher Project
StarCatcher Project
First javascript file starter code
Instructions:
Use the code below to make your javascript file for this project.
Make a new file in your editor and save it as 'scScripts.js' next to your 'StarCatcher' folder. Copy and paste the section below into this new file.
// StarCatcher Scripts for the game made by Soft Dev 2015 // when the web page window loads up, the game scripts will be read window.onload = function() { //load canvas var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"), w = canvas.width = 800, h = canvas.height = 500; //load images var starImg = new Image(); starImg.src="images/star.png"; // moving stars around the screen and update the players movement var sx=1; function starsUpdate () { // to move the stars around sx++; ctx.drawImage(starImg, sx, 40, 40, 40); } //Our main function which clears the screens // and redraws it all again through function updates, // then calls itself out again function main(){ ctx.clearRect(0,0,w,h); starsUpdate(); requestAnimationFrame(main); } main(); }