Reputation: 2606
I'm trying to create my own class in corona based on this example It looks like:
local car={};
local car_mt = { __index=car };
function car.new()
local ncar=
{
img=display:newImage("test_car.png");
}
return setmetatable(ncar,car_mt);
end
return car;
And it's called at level by this:
local pcar=require("car")
...
function scene:enterScene( event )
local group = self.view
physics.start();
local car1=pcar.new();
end
The image exists in the same folder, but i get:
bad argument #-2 to newImage (Proxy expected, got nil)
I saw some similar issues in the Net, and it seems to me that newImage()
doesn't know where to place a picture. But how can I say it if the class it made to be used for any stage?
Upvotes: 3
Views: 683
Reputation: 80639
Oh, the error is because you're calling newImage
function as:
display:newImage( "test_car.png" )
which is the wrong syntax. The above statement actually means:
display.newImage( display, "test_car.png" )
which, obviously is wrong.
The correct method would be:
display.newImage( "test_car.png" )
Read more about the corona API here.
Upvotes: 6