how do you change screens like if you were making a zelda rip0-off (which im not) how do you change the screen from one room to the next?
like if you were to walk through the door, how do you load the next room?
how do you change screens
Moderators: Shine, Insert_witty_name
Well, one technic would be to have one offscreen image for each room. Now when your character is in room one just blit the first image on screen.
If you want to go to room two then slide/scroll both images, say from right to left. When the slide effect ends room one is off screen (no need to blit it) and room two becomes your new current room....
hope it helps :)
If you want to go to room two then slide/scroll both images, say from right to left. When the slide effect ends room one is off screen (no need to blit it) and room two becomes your new current room....
hope it helps :)
Code: Select all
function main()
local Rooms = {};
local SlideX = 0;
local SlideXSpeed = -1;
Rooms[1] = Image.load("Room1.png"); -- 480x272
Rooms[2] = Image.load("Room2.png"); -- 480x272
while (false == Controls.read():start()) do
SlideX = SlideX + SlideXSpeed;
if (((-1 == SlideXSpeed) and (-480 == SlideX))
or ((1 == SlideXSpeed) and (480 == SlideX))) then
SlideXSpeed = -SlideXSpeed;
end
screen:clear();
screen:blit(SlideX, 0, Rooms[1], 0, 0, 480, 272, false);
screen:blit(SlideX + 480, 0, Rooms[2], 0, 0, 480, 272, false);
screen.waitVblankStart()
screen.flip()
end
end
main();
First, two images are loaded, one for room one and the second for room two. Then, until start is pressed, both images are scrolled from rigth to left then from left to right.
Again, the code is very basic and a better blit strategy should/must be used. Now it's up to you to test and tweak this piece of code to better understand how it works :)