DrawImage issue ...

Monkey Forums/Monkey Programming/DrawImage issue ...

necky(Posted 2013) [#1]
Hi!

I've just invested in Monkey and am loving it so far :) I have a slightly embarrassing issue that I can't figure out at the moment. I'm trying to load in a display an image. From what I can tell this piece of code I've written is correct but it just complains when I try to run it. I've tested this on my Mac and PC with the same problem, so it's seems I'm messing up somewhere. The error I get is this:

Monkey Runtime Error : TypeError: bb_graphics_device is null
/Users/<username>/MonkeyCoder/modules/mojo/graphics.monkey<238>

If anyone could shed any light on this for me that would be excellent :)

Thanks

Mike

Here's my code:

Import mojo
Import mojo.app
Import mojo.graphics

Class MyApp Extends App

Global Picture:Image = LoadImage ("TestImage.png")

Method OnCreate:Int()
SetUpdateRate 60
End

Method OnUpdate()
End

Method OnRender()
DrawImage (Picture,MouseX,MouseY)
End
End

Function Main()
New MyApp
End


caffeinekid(Posted 2013) [#2]
You have to load your image in the OnCreate, you can't do it when you set your variable there?


Volker(Posted 2013) [#3]
Hi Mike, welcome aboard!

In your code the image is loaded before the App object is initialized.
You can't do any graphics stuff before.
So caffeinekid is right, it belongs in OnCreate.


Markus(Posted 2013) [#4]
the image should be a Field in Class not Global


necky(Posted 2013) [#5]
Hi again! Thanks everyone for your help! :D

all the best!
Mike :)


Raz(Posted 2013) [#6]
the image should be a Field in Class not Global

Not necessarily. I use global images within classes all the time.