Lesson 4: draw images
Ok so lets learn to load paste and load images and create new blank images. Ok first i will load you up with the scripts then show you how to use them. Ok
-load images
nameOfImage = Image.load("imageDir")
First where i wrote nameOfImage that is the name of the image in the game... and where i wrote imageDir is the loading Directory of the image.-paste image
screen:blit(x,y,nameOfImage)
This is saying paste the image nameOfImage to x, y.and to create a blank image and color it we type-draw image
nameOfImage =Image.createEmpty(32,32)nameOfImage:clear(red)
Ok so we are drawing a blank image that is 32 pixels by 32 pixels. then we take the nameOfImage that is clear and change it to redSo now lets incorporate this and are tables to make a game that has a moving guy.The link to the guy i want to move is at the bottom, go ahead and download him.OK!! lets start!!Lets load a color for the background and load are images...
blue = Color.new(0,0,255)
background = Image.createEmpty(480,272)
guy = Image.load("guy.png")
OK so thats all easy now lets create a table to store are x, y coordinates.
Player = {}
Player[1].x = 100
Player[1].y = 100
Again you should recognize this from earlier.so lets create a loop.
while true do
screen:blit(0,0,background)
screen:blit(Player[1].x,Player[1].y,guy)
pad = Controls.read()
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 3
end
Ok so I just through a lot of new stuff at you.pad = Controls.read() is saying read the button input. if pad:left is saying if you press left. I then added a second if statement, Player[1].x > 0this is saying if my character is against the side of the screen then make him stop!ok so lets add one of these for up, down, and right
if pad:right() and Player[1].x + 32 < 480 then
Player[1].x = Player[1].x + 3
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 3
endif pad:down() and Player[1].y + 32 < then
Player[1].y = Player[1].y + 3
end
Ok so now finish the loop
screen.flip()
screen.waitVblankStart()
end
So there you go you now have made a game that you can move in!if i had any errors in this script let me know and i will fix it.
The next tutorial will be coming soon!!!speaking of which, what do u guys want the next tutorial to be on?tell me in the suggestions blog!
back
-load images
nameOfImage = Image.load("imageDir")
First where i wrote nameOfImage that is the name of the image in the game... and where i wrote imageDir is the loading Directory of the image.-paste image
screen:blit(x,y,nameOfImage)
This is saying paste the image nameOfImage to x, y.and to create a blank image and color it we type-draw image
nameOfImage =Image.createEmpty(32,32)nameOfImage:clear(red)
Ok so we are drawing a blank image that is 32 pixels by 32 pixels. then we take the nameOfImage that is clear and change it to redSo now lets incorporate this and are tables to make a game that has a moving guy.The link to the guy i want to move is at the bottom, go ahead and download him.OK!! lets start!!Lets load a color for the background and load are images...
blue = Color.new(0,0,255)
background = Image.createEmpty(480,272)
guy = Image.load("guy.png")
OK so thats all easy now lets create a table to store are x, y coordinates.
Player = {}
Player[1].x = 100
Player[1].y = 100
Again you should recognize this from earlier.so lets create a loop.
while true do
screen:blit(0,0,background)
screen:blit(Player[1].x,Player[1].y,guy)
pad = Controls.read()
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 3
end
Ok so I just through a lot of new stuff at you.pad = Controls.read() is saying read the button input. if pad:left is saying if you press left. I then added a second if statement, Player[1].x > 0this is saying if my character is against the side of the screen then make him stop!ok so lets add one of these for up, down, and right
if pad:right() and Player[1].x + 32 < 480 then
Player[1].x = Player[1].x + 3
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 3
endif pad:down() and Player[1].y + 32 < then
Player[1].y = Player[1].y + 3
end
Ok so now finish the loop
screen.flip()
screen.waitVblankStart()
end
So there you go you now have made a game that you can move in!if i had any errors in this script let me know and i will fix it.
The next tutorial will be coming soon!!!speaking of which, what do u guys want the next tutorial to be on?tell me in the suggestions blog!
back
guy.png | |
File Size: | 0 kb |
File Type: | png |