How to make an image constantly scroll?
Posted: Fri Dec 19, 2014 7:26 pm
Hey everyone, I am a bit of a newbie when it comes to Lua and Love2D, and I have decided to try to make a small game with it. I am trying to make an image scroll infinitely over the screen, but I can only get it to scroll once, and then it disappears.
What I want is a starfield that basically flies by constantly giving the illusion that you are flying in game.
Here is the code I have already (main.lua), its quite a bit.
Does anyone have any ideas on how to do this?
Thanks in advance
What I want is a starfield that basically flies by constantly giving the illusion that you are flying in game.
Here is the code I have already (main.lua), its quite a bit.
Code: Select all
require "menu"
function love.load()
--Load the Object
version =" 0.1.1"
screenWidth = 800 --Screen Width
screenHeight = 600 -- Screen Heigth
gamestate = "menu"
titleMedium = love.graphics.newFont(45)
menuBackground = love.graphics.newImage("assets/menu/menuBackground.jpg")
menuMusic = love.audio.newSource("assets/menu/music.mp3", "static")
platformImage = love.image.newImageData("assets/background.jpg")
starImage = love.image.newImageData("assets/star_overlay.png")
stars = love.graphics.newImage("assets/star_overlay.png")
player = love.graphics.newImage("assets/player.png")
startButton = love.graphics.newImage("assets/menu/start.png")
quitButton = love.graphics.newImage("assets/menu/quit.png")
love.window.setMode(screenWidth, screenHeight)
print('setMode Done')
screenCanvas = love.image.newImageData(screenWidth, screenHeight)
screenCanvas1 = love.image.newImageData(screenWidth, screenHeight)
print('Loaded Resources')
bWidth = platformImage:getWidth()
bHeight = platformImage:getHeight()
sWidth = starImage:getWidth()
sHeight = starImage:getHeight()
playerSpeed = 15
starSpeed = 90
nStars = 100
xB = 0
yB = 0
xS = 0
yS = 0
print('Loaded Variables')
--Main Menu Buttons
button_spawn(startButton, 300, 250, "start")
button_spawn(quitButton, 300,330, "quit")
love.audio.play(menuMusic)
if gamestate == "playing" then
end
print("Spice Invaders v" .. version .. " loaded.")
end
function love.update(dt)
--Update the Object
if gamestate == "playing" then
if love.keyboard.isDown("d") then
xB = xB + (playerSpeed * dt)
elseif love.keyboard.isDown("a") then
xB = xB - (playerSpeed * dt)
end
if love.keyboard.isDown("s") then
yB = yB + (playerSpeed * dt)
elseif love.keyboard.isDown("w") then
yB = yB - (playerSpeed * dt)
end
-- yS = yS - (starSpeed * dt)
screenCanvas:paste(platformImage,0,0,xB,yB)
-- screenCanvas1:paste(starImage,0,0,xS,yS)
end
end
function love.draw()
--Draw the Object
if gamestate == "playing" then
love.graphics.setColor(255,255,255)
finalImage = love.graphics.newImage(screenCanvas)
--finalImage1 = love.graphics.newImage(screenCanvas1)
love.graphics.draw(finalImage, -1, -1)
-- love.graphics.draw(finalImage1, -1, -1)
love.graphics.print("FPS: "..love.timer.getFPS() .. '\nMem(kB): ' .. math.floor(collectgarbage("count")), 650, 20)
love.graphics.draw(player, 350, 250)
end
if gamestate == "menu" then
love.graphics.draw(menuBackground, 0, 0)
button_draw()
love.graphics.setColor(255, 255, 255)
love.graphics.print("Music Copyright by: SS Productions", 10, 580)
end
end
function love.focus(bool)
end
function love.keypressed( key, unicode )
end
function love.keyreleased( key, unicode )
end
function love.mousepressed( x, y, button )
if gamestate == "menu" then
button_click(x,y)
end
end
function love.mousereleased( x, y, button )
end
function love.quit()
end
Thanks in advance