Re: Love Remove Image command Request
Posted: Wed Oct 13, 2010 1:37 pm
It appears as if you are coming from a more object-oriented background, Lua (and LOVE) are lower-level than this. Below is a simple code sample that explains what your object.removeMe() method above is actually doing at a lower level, which is how you would have to implement it in Lua. Maybe this can help get you on the right track:isn't that better to store the object to a variable (as an object), so that later can use object.scaleX, object.getPostX, object.RemoveMe
Code: Select all
-- We're going to draw some balls on the screen
function love.load()
-- Some basic variables about our game
game = {}
game.width = love.graphics.getWidth()
game.height = love.graphics.getHeight()
-- Some data about our balls
max_balls = 10
ball_radius = 20
-- This table will store each ball that will be drawn on screen
balls = {}
end
function love.draw()
-- Draw all of the balls that are in the balls table
for _, ball in pairs(balls) do
love.graphics.circle("fill", ball.x, ball.y, ball_radius)
end
end
function love.keypressed(key)
-- Add and subtract balls, the subtraction part here is like your object.removeMe()
if key == "kp+" and #balls < max_balls then
table.insert(balls, 1, {x = math.random(game.width - ball_radius), y = math.random(game.height - ball_radius)})
elseif key == "kp-" and #balls > 0 then
table.remove(balls)
end
-- Quit the game
if key == "escape" then
love.event.push("q")
end
end