Image on Screen?

Community Forums/Monkey2 Talk/Image on Screen?

Hotshot(Posted 2016) [#1]
Am I doing it right?

Import mojo2

Class MyApp Extends App

	Field canvas:Canvas
	
	Field image:Image
	Field icanvas:Canvas
	
	Method OnCreate()
		canvas=New Canvas

	         LoadStuff()
		
		SetUpdateRate 0
	End
	
	Method LoadStuff()
		If image image.Discard
	          image=Image.Load( "Picture.png" )
	End
	
	Method OnRender()
		
		'render to main canvas...
		canvas.Clear
		canvas.SetColor .5,.5,.5
		canvas.DrawText " Here the Picture ",320,240,.5,.5
		canvas.DrawImage image,50,50
		canvas.Flush
		
	End
End

Function Main()
	New MyApp
End



therevills(Posted 2016) [#2]
I'm not a mojo2 expert... it looks okayish.... but that is a MonkeyX 1 code and this is the MonkeyX 2 forum... Mojo2 <> Monkey2.


Hotshot(Posted 2016) [#3]
I am trying to learn Monkey 2. What would Monkey 2 source code look like if trying display image on screen?


dawlane(Posted 2016) [#4]
See the examples in the monkey2/modules/mojo/bananas directory. Monkey2 is totally different to MonkeyX.

And here's an example of a game.


therevills(Posted 2016) [#5]
@Hotshot - it'll be something like this:
Namespace supergame

#Import "<std>"
#Import "<mojo>"

#Import "assets/spaceship_32.png"

Using std..
Using mojo..

Class MyWindow Extends Window
	Field image:Image

	Method New(title:String, width:Int,height:Int)
		Super.New(title, width, height, WindowFlags.Resizable)
		ClearColor = Color.Black
		SwapInterval=1
		LoadStuff()
	End
	
	Method LoadStuff()
		image = Image.Load( "asset::spaceship_32.png" )
		image.Handle=New Vec2f( .5,.5 )		
	End
	
	Method OnRender(canvas:Canvas) Override
		App.RequestRender()
		canvas.Color = New Color(.5, .5, .5)
		canvas.DrawText("Hello World!", 320, 240, .5, .5)
		canvas.Color = New Color(1, 1, 1)
		canvas.DrawImage(image, 100, 100)
	End
End

Function Main()
	New AppInstance
	New MyWindow("Super Game!", App.DesktopSize.x / 2, App.DesktopSize.y / 2)
	App.Run()
End


And the "spaceship_32.png" file is in the assets folder.


Hotshot(Posted 2016) [#6]
I have got assets of spaceship image in that folder but when I run the program.

It say "Unrecongnized pre-processor directive import"

How can I get it working?


therevills(Posted 2016) [#7]
What does your code look like?

Here is a link to the above code and file asset:
https://dl.dropboxusercontent.com/u/35103024/mx/supergame.zip


Hotshot(Posted 2016) [#8]
Same source code as you but I get the same error. Why that?


therevills(Posted 2016) [#9]
Are you using Monkey2? If so, what version?


Hotshot(Posted 2016) [#10]
Are you using Monkey2? I am not sure. It is TED Editors

If so, what version? Monkey Pro 85E (Windows)


therevills(Posted 2016) [#11]
You can use TED with Monkey2 but you need to follow the instructions on the GitHub page:

https://github.com/blitz-research/monkey2/blob/master/README.TXT

Sounds like you are trying to run MX2 code with MX1 ;)