Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
11-10-2012, 10:47 AM #1
- Join Date
- Nov 2012
- Thanked 0 Times in 0 Posts
Uncaught ReferenceError: FPS is not defined how i can correct this error
window.onload = function()
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var FPS = 50;
var width = 450;
var height = 450;
this.x = 20;
this.y = 20;
this.radius = 10;
this.speedX = 2;
this.speedY = 2;
this.color = '#000000';
this.draw = function()
context.arc(this.x, this.y, this.radius, 0, Math.PI*2, true);
context.fillStyle = this.color;
var ball = new Ball();
if(ball.x + ball.radius >= width || ball.x - ball.radius <= 0)
ball.speedX *= -1;
if(ball.y + ball.radius >= height || ball.y - ball.radius <= 0 )
ball.speedY *= -1;
ball.x = ball.x + ball.speedX;
ball.y = ball.y + ball.speedY;
// clear stage
context.clearRect(0, 0, width, height);
11-10-2012, 12:53 PM #2
- Join Date
- Jun 2002
- London, England
- Thanked 2,542 Times in 2,520 Posts
Make FPS a global variable - declare it outside the function.
BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
Last edited by Philip M; 11-10-2012 at 12:58 PM.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
11-10-2012, 04:06 PM #3
This code makes little sense. Ball is a constructor, so why call it without new in the onload handler?
FPS is declared in the onload handler but never referenced.
Nothing appears to alter FPS, so why use it solely as a divisor for a constant?Code:1000/FPS);