var picture;
picture = loadImage("smile.png");
Will load the file "smile.png" from the same folder as the program and place it in the variable named pictureYou may also use full url paths.
var logo;
logo = loadImage("http://www.google.com/images/logos/ps_logo2.png");
Will load the Google logo from google.com and place it in the variable named logo.You may optionally specify framesWide and framesHigh values if you have a multiple frame animation in a single image. These are called SpriteSheets.
var runner;
runner = loadImage("http://www.thebest3d.com/pda/tutorials/array2animation/walksequence_spritesheet.png",5,5);
This code will download a 25 frame animation of a runner stored as a set of images evenly spaced 5 across and 5 down.
The simplest form is:
drawImage(picture,10,20);In addition to the simple form you may also choose a frame from an animation
drawImage(runner,200,300,5);Animation frames are numbered from zero so the 25 frame runner animation uses frame numbers 0-24;
You may also rotate the image
drawImage(logo,400,200,0,9.5);This will draw the logo at 400,200 rotated by 9.5; Since the logo is not an animation, it only has a frame 0;
The following example reduces y by 1.5 if the up key is being held down.
if ( keyIsDown(38) ) {
y=y-1.5;
}
It is possible to have keyIsDown() return false and keyWentDown() return true if someone pressed and released a key extremely quickly.