My problem is that i make my world in the love.load() but i want to move the creation of different bodies and all that they need to different classes. But for some reason it won't let me, complains about having the wrong parameters.
The error i am getting is :
player.lua:13: Incorrect parameter type: expected userdata.
Traceback
[c]: in function 'newBody'
player.lua:13: in function 'init'
class.lua:47: in function 'new'
main.lua:5: in function 'load'
[c]: in function 'xpcall'
And the code in the init function of my player class is:
Player = class:new()
function Player:init(x, y, physWorld)
self.x = x
self.y = y
self.width = 32
self.height = 32
self.image = love.graphics.newImage("body.png")
--Create the physical body
self.body = love.physics.newBody(physWorld, 100, 100, 0, 0)
self.shape = love.physics.newRectangleShape(32,32)
self.fixture = love.physics.newFixture(self.body, self.shape, 1)
return self
end
Does anyone know what the problem to this could be?
Problem with creating body in different class
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Problem with creating body in different class
It looks to me like the third argument passed to Player:init is nil. Perhaps you initialize the player before you create the world? Hard to say without the full code.
Shallow indentations.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 12 guests