How to load an png/jpg picture?
Community Forums/Monkey Talk/How to load an png/jpg picture?
| ||
I cannot get the pdf help program to load and move an png/jpg picture. The code is below. Any suggestions on what is missing? Here is the code for the boing example in the pdf. It does paste and build but the result does not run? It doesn't load the png picture. Import mojo Function Main () New Game End Class Game Extends App Field player:Image Field x:Float Field y:Float Method OnCreate () player = LoadImage ("boing.png") SetUpdateRate 60 End Method OnUpdate () If KeyDown (KEY_LEFT) Then x = x - 4 If KeyDown (KEY_RIGHT) Then x = x + 4 If KeyDown (KEY_UP) Then y = y - 4 If KeyDown (KEY_DOWN) Then y = y + 4 End Method OnRender () Cls 64, 96, 128 DrawImage player, x, y End End I cannot recognize what code is missing here. Help loading image, Gerald |
| ||
Does the image file "boing.png" actually exist? Is it in the appropriate .data folder so the program can find it? |
| ||
Just make sure your directory is similar to this:[ProjectFolder] [boing] boing.monkey [boing.data] boing.png |
| ||
However, in the case of subfolders it would be more like this for example:[ProjectFolder] [boing] boing.monkey [boing.data] [graphics] boing.png [Audio] boing.wav [leveldata] level1.dat level2.dat etc, etc... |
| ||
Taking Steve's latest example for the folder structure... load an image then like this:player = LoadImage ("graphics/boing.png") And be aware that some platforms are case sensitive regarding file names. |
| ||
I forgot about the case-sensitive thing, thanks for pointing that out Michael. ;-) |
| ||
Hi, [ProjectFolder] [boing] boing.monkey [boing.data] boing.png What do the parenthesis here mean? I put a folder game.monkey and a folder game.data , with the 256X256 png) picture in it. These are both in the project (game) folder. It never opens up. I would like the example properly coded for me with any picture. I think my folders are correct. I am at a real loss as to what to do. The program is called monkey pixers. Does it really load pictures (jpg/png)? Gerald |
| ||
There are dozens of example programs included with Monkey in the \bananas folder. Each is in its own folder. Look at the structure ( folder contains yourprogram.monkey and a subfolder yourprogram.data ) and imitate that. |
| ||
well Gerald, Your game code has a name. As I read in your posts it looks like the name is "game.monkey"? If you now edit this code and save it or start it a file will be created on your harddisk with the same name "game.monkey". Did you already find this file? in which folder is it? You wrote you created a folder with the name "game.monkey". That is wrong, not necessary". Next to the file "game.monkey" on your harddisk you have to create a folder named "game.data". Put your image "boing.png" into this file. With this precondition this code should work: Strict Import mojo Class Game Extends App Field player:Image Field x:Float Field y:Float Method OnCreate%() player = LoadImage ("boing.png") If player=NULL then error "no png found" SetUpdateRate 60 Return 0 End Method OnUpdate%() If KeyDown (KEY_LEFT) Then x = x - 4 If KeyDown (KEY_RIGHT) Then x = x + 4 If KeyDown (KEY_UP) Then y = y - 4 If KeyDown (KEY_DOWN) Then y = y + 4 If KeyHit(KEY_ESCAPE) OnBack() Return 0 End Method OnRender%() DrawImage player, x, y DrawText Millisecs(),30,130 Return 0 End Method OnBack%() EndApp() Return 0 End End Function Main%() New Game Return 0 End Please report what happened, when you used this code. |