What's wrong with this basic code?
Monkey Forums/Monkey Programming/What's wrong with this basic code?
| ||
Hi all, maybe someone could help me out checking this piece of basic code and point me where the problem coulb be. Basically, the image i'm loading doesn't appear on the screen.. Thanks a lot ;) Import mojo Class MainGame Extends App Field x,y Field image1: Image Method OnCreate() SetUpdateRate 60 x=100 y=100 image1 = LoadImage ("fi1.png") End Method Method OnUpdate() x=x+3 End Method Method OnRender() Local r Cls 0,0,0 SetColor 255,255,255 DrawLine 100,x-100,200,200 'For r = 1 To 100 DrawImage image1,20,20 'Rnd(1,200),Rnd(1,200) 'Next End Method End Function Main () New MainGame End |
| ||
Works here. Is the image in the filename.data directory? |
| ||
Quickly tested... works for me. What version of Monkey are you using? What is your folder structure? What is the image called in your folder? It is case-sensitive... |
| ||
Shouldn't that be self.image1 = LoadImage?? Not sure but without Strict mode, wouldn't your code 'as is' create a local object called image1 within OnCreate()? |
| ||
Nope - Monkey requires you to declare your variables before you use them with or without Strict. |
| ||
Thanks all! I didn't know it is a must to save all the gfx assets in the folder myappname.data, and it is not created automatically or whatever.. :) I've created the folder, copies the image and it works! Thanks so much everybody. BTW, could you please let me know when it's writen other rules of this kind in the monkey docs? |
| ||
This particular fact is in docs/gettingstarted.html in the Mojo quick tips section. You can also look at the structure of the bananas code samples |
| ||
thank you very much matt ;) |