About Monkey 2 › Forums › Monkey 2 Programming Help › Monkey2 conversion
Tagged: Conversion Monkey2
This topic contains 19 replies, has 3 voices, and was last updated by
PhatPeter 1 year, 4 months ago.
-
AuthorPosts
-
November 22, 2017 at 3:14 am #11907
Yes I did managed it by myself such victory !!
November 22, 2017 at 3:20 am #11908For anyone who wanna try it !
still to do is adding input etc, but the skeleton is working in Monkey2. It need a clean up of course.I noticed userinputs makes the window or screen a bit wobbly at times so I might check that out what you can do about that.
Feel free to use this as a banana if you find it useful.
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115[crayon-5cba8453a2216319269799 inline="true" ]Namespace Myapp#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"#Import "assets/"Using std..Using mojo..Const w:=1920, h:=1080Class Myapp Extends WindowField canvas:CanvasField icanvas:CanvasField scanvas:CanvasField image:ImageField sourceImage:ImageField targetImage:ImageField size:Int=8 ' try 8 16 32 64Field cx:IntField wx:IntField wy:IntField tilemap := New Int[512*512]Field s:Int = 4Method New()Super.New("Myapp", w, h, WindowFlags.Resizable)For Local y:=0 To 511For Local x:=0 To 511tilemap[x + y * 512] = Int(Rnd(127))NextNextsourceImage=Image.Load("asset::32x32sheet.png") ' 0,0,0 in Mx ! PixelFormat.RGBA8,TextureFlags.Dynamic)targetImage=New Image(sourceImage.Width,sourceImage.Height) ' ,,,0) 'MAYBE SAME AS BELOWimage=New Image(512,512,PixelFormat.RGBA8,TextureFlags.Dynamic) ' image=New Image(512,512,0,0,0) & Image.SetFlagsMask(Image.Managed)icanvas=New Canvas(image)scanvas=New Canvas(targetImage)' canvas=New Canvas() NOT NEEDED IN MONKEY2 ' image.Texture.Flags &=~ TextureFlags.FilterMipmapEnd' ---------------------------------------------------------------------------------------Method OnRender( canvas:Canvas ) OverrideApp.RequestRender()wx=wx +1 ' resize and handlers'wx=wx-s*KeyDown(KEY_LEFT)+s*KeyDown(KEY_RIGHT)'wy=wy-s*KeyDown(KEY_UP)+s*KeyDown(KEY_DOWN)'wx=Max(0,Min(10000,wx)) ' Limit wx to 0 through 10000'wy=Max(0,Min(10000,wy)) ' Limit wyx to 0 through 10000' canvas.Alpha=1.0scanvas.Clear(Color.Black) ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.DrawImage(sourceImage,0,0) ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.Flush() ' INSTEAD OF SHADER (just copies sourceImage to targetImage)' Init canvas & image'canvas.Viewport(0,0,w,h)'canvas.Scissor(0,0,w,h)'canvas.Projection2d(0,w,0,h)canvas.Clear(Color.Black)'icanvas.Viewport(0,0,w,h)'icanvas.Scissor(0,0,w,h)'icanvas.Projection2d(0,w,0,h)icanvas.Clear(Color.Black)' Draw to image' Scroll (by drawing onto itself)icanvas.Clear(Color.Black)icanvas.DrawImage(sourceImage,0,0)icanvas.DrawImage(targetImage,256,256)cx=(cx+2) Mod 512For Local temp:=0 To 127icanvas.DrawRect(64+temp,0,1,64,targetImage,0+temp+cx,0,1,64)Next' Plots something in the tiles (shows how to draw something to an image *after* shader have been applied)For Local temp:=1 To 16If Int(Rnd(1)) Then icanvas.Color = Color.Black Else icanvas.Color = Color.WhiteLocal xx:= Int(Rnd(7))Local yy:= Int(Rnd(7))icanvas.DrawRect(xx*4,yy*4,2*4,2*4)Nexticanvas.Flush() ' Finished drawing' Draw to canvas' Cookiecut 32x32 tiles from a 512x512 tilesheet and draw as tiles of any sizeLocal scrx:=wx Mod sizeLocal scry:=wy Mod sizeLocal mapx:=wx / sizeLocal mapy:=wy / sizeLocal cnty:= -scryFor Local y:=mapy To mapy+((h/size)+1)Local cntx:=-scrxFor Local x:=mapx To mapx+((w/size)+1)Local char:= tilemap[x + y * 512]Local tilex:= char & 15Local tiley:= char Shr 4canvas.DrawRect(cntx,cnty,size,size,image,tilex Shl 5,tiley Shl 5,32,32)cntx=cntx+sizeNextcnty=cnty+sizeNextcanvas.Flush() ' Finished drawingIf Keyboard.KeyReleased(Key.Escape) Then App.Terminate()End MethodEndFunction Main()New AppInstanceNew MyappApp.Run()End FunctionNovember 22, 2017 at 3:27 am #11909Monkey2 suddenly became a very attractive productivity tool. I’ll get a heart in 3 months.
But please check into if there is some bug under the hood or not even if this seem to work.
At least now there’s an easy way to compare the two, just add additional layers and see who drops first.November 22, 2017 at 3:33 am #11910Ops I didn’t notice the post before mine. Thanks I’ll use that instead.
November 22, 2017 at 6:05 am #11911For those who are interested it runs perfectly on Lenovo Yoga2 with Android Lollipop. This is too cute, getting 1920×1200 64×64 @ 60 fps. If shaders comes equally cheap on Monkey2 then I will dare to throw MonkeyX away for good.
I’m curious to see the quality of HTML5 compiling but installing it is a real bitch so I’m giving up on that one for now.
-
AuthorPosts
You must be logged in to reply to this topic.