Mar 26, 2014 01:51 AM
(This post was last modified: Mar 26, 2014 03:12 AM by Toph Beifong.)
So iv been learning Love2D and my project was simple, make a snake game. So i decided to load each segment of the snake separately via a loop but one the loop is complete the snake disappears and i haven't even go to movement yet.
EDIT: since solved this, used a multi dimentional table to store the image position in: code below.
Code
function love.load()
love.graphics.setBackgroundColor(000,000,000)
segmentImage = love.graphics.newImage('images/segment.png')
startingPositionX = 200
startingPositionY = 200
bodyLength = 4;
end
function buildSnake()
segmentCount = 1;
while segmentCount <= bodyLength do
love.graphics.draw(segmentImage, startingPositionX, startingPositionY)
startingPositionX = startingPositionX - 35
segmentCount = segmentCount + 1
end
--
end
function love.draw()
buildSnake()
endEDIT: since solved this, used a multi dimentional table to store the image position in: code below.
Code
function love.load()
love.graphics.setBackgroundColor(000,000,000)
segmentImage = love.graphics.newImage('images/segment.png')
startingPositionX = 200
startingPositionY = 200
bodyLength = 4;
count = 0
segmentControl = {}
while count < bodyLength do
startingPositionX = startingPositionX - 20
table.insert(segmentControl, {x=startingPositionX, y=startingPositionY})
count = count + 1
end
end
function love.draw()
for i = 1, 3 do
love.graphics.draw(segmentImage, segmentControl[i].x, segmentControl[i].y)
end
end



