Page 1 of 1

Problem with creating body in different class

Posted: Sun Feb 17, 2013 8:24 pm
by Brodal
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?

Re: Problem with creating body in different class

Posted: Mon Feb 18, 2013 12:48 am
by Boolsheet
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.