0

我还有这个不错的汽车课:

local car={};
local car_mt = { __index=car };

local this;
function car.new(_x, _y)
    local ncar=
    {
        img=display.newImageRect("test_car.png",50,120,true);
        x=0;
        y=0;
        main_frame=function(self)
            self.img.x=self.x;
            self.img.y=self.y;
        end
    }
    function ncar:set()
        self.x=_x;
        self.y=_y;
        Runtime:addEventListener("enterFrame",self.main_frame(self));
    end
    ncar:set();
    return setmetatable(ncar,car_mt);
end
return car;

我这样称呼它:

function scene:enterScene( event )
    local group = self.view
    physics.start();
    local car1=pcar.new(200,200);

end

它工作正常,例如,它给了我一个错误“断言失败”

> getOrCreateTable 
> addEventListener 
> addEventListener
> Runtime:addEventListener("enterFrame",self.main_frame(self));

在显示器上,一切似乎都很好。怎么了?

4

1 回答 1

1

终于通过这个解决了:

    main_frame=function(self)
        return function(event)
            self.img.x=self.x;
            self.img.y=self.y;
        end
    end
于 2013-03-10T11:17:10.040 回答