• Content Count

  • Joined

  • Last visited

About Chuxx

  • Rank
  • Birthday 11/14/1991

Profile Information

  • Gender
  • Location
    Computer Desk
  • Interests
    Knowledge, Programming and Music.

Contact Methods

  • Twitter
  1. Hi, I'm fairly new to game programming using HTML5. Although saying that I have been using Javascript for many years and will continue to do so for years to come. Basically I have made a couple of very basic games up to now just practising in general for when I decide to consider making a more serious attempt at a game for people to play. I noticed while learning some of the basics that there was quite a lot of code that I had to rewrite almost exactly the same for all the basic games I made, so I figured "Why not make a file that I can reuse for almost all games I intend to make?". Well I begun doing so and soon ran into a few "scope" problems, I figured out a way around them but then after reading a few threads on these forums when I first landed here yesterday, I am afraid that my style of OOP (So to speak) with Javascript is not the best way to go about things. I was just looking for pointers in regards to where this file can be improved due to not programming the way accepted by most Javascript developers? function Canvas(canvasID){ this.canvasID = canvasID; this.canvasDOM = document.getElementById(this.canvasID); this.ctx = this.canvasDOM.getContext('2d'); this.width = this.canvasDOM.width; this.height = this.canvasDOM.height; this.clear = function(){ this.ctx.clearRect(0, 0, this.width, this.height); }; this.fill = function(color){ this.ctx.fillStyle = color; this.ctx.fillRect(0, 0, this.width, this.height); };}var engine = new function(){ this.running = false; this.animator = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame; this.start = function(){ this.running = true; this.tick(); }; this.stop = function(){ this.running = false; }; this.tick = function(){ if(!this.running) return; update(); render();, function(){ engine.tick(); }); };} Now there are a few things I am sure are terribly wrong, the most prominent being in the tick method of the engine instance where I call itself by using "engine.tick()" . This is where, as I mentioned before, I had "scope" issues. Any advice regarding how I should change that would be much appreciated. Now the way in which I currently (And intend to continue if possible) using this file for my games is like so - var canvas = new Canvas("gameCanvas");engine.start();function update(){ canvas.clear(); //update game}function render(){ //render game} I hope you manage to decipher what I mean by this and understand my programming. Thanks in advance, Chuxx.