objects = {}
function objects.load()
objects.ball.image = love.graphics.newImage("images/ball.png")
end
function objects.ball.spawn()
end
function objects.ball.draw()
love.graphics.draw(objects.ball.image,x,y)
end
Inserting into tables
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Inserting into tables
Hi, I have been learning how to use tables. I understand the basic concepts but I don't know how I would do something like being able to spawn multiple objects that all have the same image, etc. At the moment I have this in an objects.lua:
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Inserting into tables
You need to do this at least:
If you have a more specific question, I could help you more.
Code: Select all
function objects.load()
objects.ball = {} -- this
objects.ball.image = love.graphics.newImage("images/ball.png")
end
Help us help you: attach a .love.
Re: Inserting into tables
Ok, so how would I then draw the object in different places. Let's say, get the position of the mouse cursor and draw the multiple instances of the ball at different places and then delete them?
Re: Inserting into tables
You can use this image every time you want to draw it:Jakemason wrote:Ok, so how would I then draw the object in different places. Let's say, get the position of the mouse cursor and draw the multiple instances of the ball at different places and then delete them?
Code: Select all
function love.draw()
love.graphics.draw(objects.ball.image, posx, posy, ..
love.graphics.draw(objects.ball.image, otherposx..
end
Re: Inserting into tables
I'm talking about if the ball that has been drawn needs to be deleted, say if it was a game element.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Inserting into tables
Jakemason wrote:I'm talking about if the ball that has been drawn needs to be deleted, say if it was a game element.
Well, I tend to think the same.richapple wrote:I don't see the reason to delete it though
Anyway, there are many ways to achieve this.You can set an axtra boolean to control whether or not the ball should be drawn.
Code: Select all
function objects.load()
objects.ball = {} -- this
object.ball.shouldDraw = true
objects.ball.image = love.graphics.newImage("images/ball.png")
end
function objects.ball.draw()
if objects.ball.shouldDraw then love.graphics.draw(objects.ball.image,x,y) end
end
So you don't need to "delete" it.
Hope this helps.
Re: Inserting into tables
Ok, so here is what I have but nothing happens when I press space.
Code: Select all
objects = {}
function objects.load()
objects.ball = {}
objects.ball.shouldDraw = false
objects.ball.image = love.graphics.newImage("images/ball.png")
end
function objects.draw()
love.graphics.draw(objects.ball.image, x, y)
end
function objects.update()
x, y = love.mouse.getPosition()
if objects.ball.shouldDraw then love.graphics.draw(objects.ball.image,x,y) end
if love.keyboard.isDown("space") then objects.ball.shouldDraw = true else objects.ball.shouldDraw = false end
end
Re: Inserting into tables
Hi. Like Roland said, you have to check the "shouldDraw" boolean from the "draw" function:
Also, you don't need to call "draw" from the "update" function:
Code: Select all
function objects.ball.draw()
if objects.ball.shouldDraw then
love.graphics.draw(objects.ball.image,x,y)
end
end
Code: Select all
function objects.update()
if love.keyboard.isDown("space") then
objects.ball.shouldDraw = true
else
objects.ball.shouldDraw = false
end
end
Re: Inserting into tables
Ok, so now I have:
and still nothing appears :/
Code: Select all
objects = {}
function objects.load()
objects.ball = {}
objects.ball.shouldDraw = false
objects.ball.image = love.graphics.newImage("images/ball.png")
end
function objects.draw()
if objects.ball.shouldDraw then love.graphics.draw(objects.ball.image,x,y) end
end
function objects.update()
x, y = love.mouse.getPosition()
if love.keyboard.isDown("space") then objects.ball.shouldDraw = true else objects.ball.shouldDraw = false end
end
Re: Inserting into tables
Do you call objects.load, objects.update and objects.draw in love.load, love.update and love.draw?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Who is online
Users browsing this forum: Google [Bot] and 3 guests