Discord
Login
Community
DARK THEME

Class "is not a function"

MAking a game with a class as the player

PlayerClass = class

constructor = function(x,y)

this.x = x
this.y = y
this.spawnX = x
this.spawnY = y
this.speedX = 0
this.speedY = 0
this.width = 20
this.height = 20
this.gravity = -0.5
this.jumpHeight = 6
this.acceleration = 1
this.friction = 0.8

end

draw = function()

Obj.draw.poly(this.x,this.y,this.width,this.height,"#FFF")

end

end

init = function()

player = PlayerClass(0,40)

end

It gives the error

Warning: PlayerClass(0,40) is not a function

sorry for the bad formatting

I solved it, didn't use "new" for the class.

Post a reply

Progress

Status

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