PDA

View Full Version : Scrolling background



KunoNoOni
November 30th, 2005, 08:27
I'm attempting to make my first Lua game. Its a side scrolling shooter and I'm trying to get the background to scroll. the approach I'm trying to use seems sound but I think the problem is that I'm not understanding the function
nil image:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])

Well I understand that the first x,y and image source is the size of my background and the background image itself. Its the second part I'm kinda fuzzy about. I also understand what the alpha is for.

Can someone clearly explain what the second part is? My idea for scrolling the background is to do this:

1. clear the screen
2. blit the background minus 8,272 of the background image
3. blit the missing 8,272 at the end of the previous blit.

If someone know a better way to scroll the background I'm all ears :)

cancan
November 30th, 2005, 09:24
the second part represent the portion of the image you want to blit.

sourcex and sourcey are the x and y position of the portion of the image you want to have and width and height are the length in the x and y direction.

To take the whole image you have to select:
screen:blit(0, 0, image, 0, 0, image:width(), image:height(), true)

For the scrolling you can maybe have an image bigger than the screen and just change the sourcex and sourcey of the image source with 480 as width and 272 as height (if the scrolling is for the whole screen).

Did never tried it, it's just an idea.

shiftybill
December 1st, 2005, 08:47
hey i needed one of these so i made one
background.png should be 240x272

System.usbDiskModeActivate()
background = Image.load("Background.png")
x = 0
x2 = 480


while true do

screen:blit(x, 0, background, false)
x = x - 1
screen:blit(x2, 0, background, false)
x2= x2 - 1

if x < -480 then
x = 480
end
if x2 < -480 then
x2 = 480
end

screen.waitVblankStart()
screen.flip()
end

KunoNoOni
December 2nd, 2005, 06:58
Thanks guys, I'll check these out :)

shiftybill
December 15th, 2005, 09:16
im using my background code in my shooter game which should be ready for a release soon!! :cool: 1945 eat ya heart out!