|
Submit
Your Own Code
PSP Lua CodeBase : Diagonal
Background ScrollingDescription:
Hey guys!! Well, when i was writing Times of War i came up with
this diagonal scrolling and though i should post it here so if
someone needs to use it they know where to find it!!!
oh, and some credit would be nice, thanks!!! Madcupid
-- EVILMANA.COM PSP LUA CODEBASE
-- www.evilmana.com/tutorials/codebase
-- Diagonal Background Scrolling
-- SUBMITTED BY: Madcupid
background1A = Image.load("area 51/background1A.png")
-- here you load the 4 images needed
background1B = Image.load("area 51/background1B.png")
-- remember that these 4 images will have
background1C = Image.load("area 51/background1C.png")
-- to be blitted all times at the same time
background1D = Image.load("area 51/background1D.png")
-- note that you only load the 4 images if they are
-- different from each other, or else you can load
-- only one and blit it several times in the loop!
-- here you define the starting position for each background image,
its height and width
Background1 = {x = 0, y = 0}
Background2 = {x = 480, y = 0}
Background3 = {x = 0, y = -272}
Background4 = {x = 480, y = -272}
backgroundWidth = 480
backgroundHeight = 272
-- this function will make the 4 images scroll diagonally function
backgroundMoving()
Background1.x = Background1.x - 4 -- here you define how fast you
want it to scroll
Background1.y = Background1.y + 4 -- please note the in order for
this to work flawlessly
Background2.x = Background2.x - 4 -- you have to set the speed to a
multiple of 272(height of image)
Background2.y = Background2.y + 4 -- i'll give you the examples i
used (.5, 1, 2, 4, 8, 16) but you can
Background3.x = Background3.x - 4 -- keep going to get a faster
speed!!!
Background3.y = Background3.y + 4
Background4.x = Background4.x - 4
Background4.y = Background4.y + 4 -- just substitute all 4's with
another multiple of 272!!!
if Background1.y >= 272 then
Background1.y = -272
Background1.x = Background3.x
end
if Background2.x + backgroundWidth <= 0 then
Background1.x = Background2.x + backgroundWidth
Background3.x = Background4.x + backgroundWidth
end
if Background2.y >= 272 then
Background2.y = -272
Background2.x = Background4.x
end
if Background2.x + backgroundWidth <= 0 then
Background2.x = Background1.x + backgroundWidth
Background4.x = Background3.x + backgroundWidth
end
if Background4.y >= 272 then
Background4.y = -272
Background4.x = Background2.x
end
if Background4.x + backgroundWidth <= 0 then
Background2.x = Background1.x + backgroundWidth
Background4.x = Background3.x + backgroundWidth
end
if Background3.y >= 272 then
Background3.y = -272
Background3.x = Background1.x
end
if Background3.x + backgroundWidth <= 0 then
Background1.x = Background2.x + backgroundWidth
Background3.x = Background4.x + backgroundWidth
end
end
while true do
backgroundMoving() -- here you call the function that makes that
images scroll
screen:blit(Background1.x, Background1.y, background1A) -- here,
obviously, you put the on the screen screen:blit(Background2.x,
Background2.y, background1B) screen:blit(Background3.x,
Background3.y, background1C) screen:blit(Background4.x,
Background4.y, background1D)
screen.waitVblankStart()
screen.flip()
end
-------------------
--and that's it!!!
Back to CodeBase
|