Your help would be very much appreciated on this matter, let me explain. Days ago I was trying to figure out a simple and effective method for implementing a scrolling system, one of my constraints is that I would like to scroll unique images, not tilesets.
So, I thought I would need to load the full image once, then, create some sort of screen buffer of the same size as the screen and, finally, update this buffer with the data matching the current position of the scene in the full image.
I searched around for a while, and FrameBuffers seemed the way to go in order to implement this kind of stuff, unfortunately, my current PC does not support FrameBuffers, so I’m looking for an alternative way of implementing an efficient scrolling method.
Currently, I’m considering two possible solutions: one based on ImageData Objects and one based on Quads.
I tried to code a simple test based on the former method, the basic idea is this:
- 1. Load the image data with newImageData.
2. Create a buffer, or “canvas”, same size as the screen with newImageData.
3. Paste the current chunk of the image, corresponding to the actual scene, to the “canvas” with ImageData:paste
4. Convert the “canvas” data to a drawable, final image
5. Draw the final image on the screen
Code: Select all
function love.load()
sWidth = 800 --Screen Width
sHeight = 600 -- Screen Heigth
love.graphics.setMode(sWidth, sHeight, false, false, 0)
print('setMode Done')
platformImage = love.image.newImageData("foreground.png")
screenCanvas = love.image.newImageData(sWidth, sHeight)
print('Loaded Resources')
iWidth = platformImage:getWidth()
iHeight = platformImage:getHeight()
speed = 300
x = 0
y = 0
print('Loaded Variables')
end
Code: Select all
function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
print('Scroll right: '..x)
elseif love.keyboard.isDown("left") then
x = x - (speed * dt)
print('Scroll left: '..x)
end
screenCanvas:paste(platformImage,0,0,x,y)
end
Code: Select all
function love.draw()
finalImage = love.graphics.newImage(screenCanvas)
love.graphics.draw(finalImage, 0, 526)
love.graphics.print("FPS: "..love.timer.getFPS() .. '\nMem(kB): ' .. math.floor(collectgarbage("count")), 650, 20)
end
I've attached the love file below, but please, be aware that is somewhat unestable, and will end up eating a good chunk of memory. Scroll foreground with "right" and "left" arrows.