Problem with creating body in different class

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Brodal
Prole
Posts: 1
Joined: Sun Feb 17, 2013 8:15 pm

Problem with creating body in different class

Post 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?
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Problem with creating body in different class

Post 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.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests