The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript my 2d game engine problem

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #33268

    hi i wanted to make my own js canvas library (got the idea from js snake :)) and it was all going fine till i came across a problem:

    i have a “class” for a rectangle

    function rect(width,height,x,y,colour,move){
    this.height = height;
    this.width = width;
    this.x = x;
    this.y = y;
    this.colour = colour;

    this.move = undefined;

    this.paint = function(ctx){
    ctx.fillStyle = colour;
    //console.log('rect paint',x,y,height,width);

    the “move” property and the “paint” property are called every frame

    i wanted to make them available to overload with your own custom move and possibly paint function

    like this:;
    var rect = new ENGINE.shapes.rect(10,10,10,10,'#fc1');
    rect.move = function(){
    this.x ++;

    but this dosent work, however the function does get called every frame?

    tl;dr : cant overload move function!

    full code: main.js —
    shapes.js —

    hope you can help as any help is greatly appreciated;



    its ok i have found the solution
    i needed to refer to the variables with this

    this.y = Math.sin(this.x/50)*100;


Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.