Discord
Login
Community
DARK THEME

Draw func in class

I'm having an issue with making a class with a draw function.

Here's the class definition

Rectangle = class
  constructor = function(x, y, w, h)
    this.x = x
    this.y = y
    this.w = w
    this.h = h
  end
  
  draw = function()
    screen.drawRect(this.x, this.y, this.width, this.height, "rgb(255,255,255)")
  end
end

and here's the declaration

player = new Rectangle(0, 50, 20, 20)

and here is the call

player.draw()

but the square just doesn't draw. It's really confusing...

You're drawing using width and height for rectangle size but initiating in the constructor w and h properties

Oops my bad... thanks for pointing that out!!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community