Forum Replies Created
-
AuthorPosts
-
Monkey 2 is not in the same category.
It’s a pure code tool (can i say that ?)
It doesn’t promise you to create a game in a week.
It’s a place for long term users who like coding without limit.
Our community is competent.
You can also try Lua-Love2D, Monogame, HaxeFlixel, Defold.Exactly what i needed.
I will try to inject your KeyEvent handler in my project.
Many thanks for explanations.Ok,
I see a little difference after monkey 1.06
Keyboard.KeyPressed() , and Keyboard.KeyReleased() have a little buffer.
Run this code, with monkey 1.06 and later. Follow the instructions on screen.
It just moves a cursor, if the mouse is in a zone and a cursor keys is pressed.
see Method ProceedInput()Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133Namespace keyboardtest#Import "<std>"#Import "<mojo>"Using std..Using mojo..' -----------------------------------------------Class ZoneField x0:Int,y0:Int ' Zone positionField x1:Int,y1:IntField width:Int, height:Int ' Zone dimField backcolor:ColorField cursX:Int,cursY:Int ' Cursors positionMethod New( lx:Int, ly:Int, lw:Int, lh:Int, lco:Color )Self.x0 = lxSelf.y0 = lySelf.width = lwSelf.height= lhSelf.x1 = Self.x0 + Self.width - 1Self.y1 = Self.y0 + Self.height - 1Self.backcolor = lcoSelf.cursX = 150Self.cursY = 100EndMethod Draw( lcanvas : Canvas )' draws backgroundlcanvas.Color = backcolorlcanvas.DrawRect( x0, y0, width, height )' draws the cursorlcanvas.Color = Color.Whitelcanvas.DrawRect( x0+cursX-8 ,y0+cursY-8 ,16 ,16 )EndMethod ProceedInput()If MouseHere()If Keyboard.KeyPressed( Key.Up )Self.cursY = Self.cursY - 8Elseif Keyboard.KeyPressed( Key.Down )Self.cursY = Self.cursY + 8Elseif Keyboard.KeyPressed( Key.Right )Self.cursX = Self.cursX + 8Elseif Keyboard.KeyPressed( Key.Left )Self.cursX = Self.cursX - 8Endif' limits the cursors positioncursX = Clamp( cursX,8,width-8 )cursY = Clamp( cursY,8,height-8 )EndifEndMethod MouseHere:Bool()'return true if mouse is in the ZoneLocal lreturn:Bool = FalseIf (Mouse.X>=x0) And (Mouse.X<x1)If (Mouse.Y>=y0) And (Mouse.Y<y1)lreturn = TrueEndifEndifReturn lreturnEndEnd' ------------------------------------------------Class MyWindow Extends WindowField oZone:= New Zone[4]Method New( title:String="Test Fichiers",width:Int=1280,height:Int=768,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,flags )' create zonesoZone[1] = New Zone( 10,10,300,200,Color.Blue)oZone[2] = New Zone(320,10,300,200,Color.DarkGrey)oZone[3] = New Zone(640,10,300,200,Color.Brown)EndMethod OnRender( canvas:Canvas ) OverrideLocal i:IntApp.RequestRender()' Proceed Keyboard inputs in each zoneFor i=1 To 3oZone[i].ProceedInput()Next' redraws the zonesFor i=1 To 3oZone[i].Draw( canvas )Nextcanvas.DrawText("put the mouse outside the rectangles ", 0 , 360)canvas.DrawText("use cursor key before entering coloured zones ", 0 , 380)canvas.DrawText("Move the mouse inside the one rectangle ", 0 , 400)canvas.DrawText("Keyboard.Keypressed is tested if mouse is in a zone ", 0 , 420)canvas.DrawText("and white square moves ", 0 , 440)canvas.DrawText("Try it in Monkey 1.06 --> no buffer", 0 , 460)canvas.DrawText("in later versions --> little buffer ", 0 , 480)canvas.DrawText("idem with Keyboard.KeyReleased" ,0, 500)canvas.DrawText("obviously no pb with KeyDown",0,520)EndEnd' ------------------------------------------------Function Main()New AppInstanceNew MyWindowApp.Run()EndThanks Mark,
Got it, i didn’t draw into the Pixmap.Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293' ---------------------------------------' getpixel.monkey2' ---------------------------------------Namespace getpixel#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField pxm:PixmapField img:ImageField imgcanvas:CanvasMethod New()Super.New( "GetPixel test",512, 512,WindowFlags.Resizable | WindowFlags.HighDPI )' Creates a pixmap, image, and canvaspxm = New Pixmap( 300,300,PixelFormat.RGBA8)' Draws a pink square before linking image and pixmapFor Local y:Int=0 To 50For Local x:Int=0 To 50pxm.SetPixel(x,y,Color.HotPink)NextNext' Copy pixmap data into imageimg = New Image( pxm,TextureFlags.None,Null )' Here pxm.SetPixel() draws into the pixmap but not' Try to draw a red squareFor Local y:Int=0 To 50For Local x:Int=50 To 100pxm.SetPixel(x,y,Color.Red)NextNextpxm.PremultiplyAlpha()imgcanvas = New Canvas( img )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()' Draws your Screen background herecanvas.Clear(Color.Black)' draws a blue rectangle in the pixmapFor Local y:Int=0 To 50For Local x:Int=100 To 150pxm.SetPixel(x,y,Color.Green)NextNextpxm.PremultiplyAlpha()' draws the image on the screencanvas.Color = New Color( 1, 1, 1, 1 )canvas.Alpha = 1canvas.DrawImage( img,0,0 )canvas.DrawLine(0,52,150,52)' Shows pixmap colors if mouse is under the pixmapLocal ARGB:UIntLocal Ink:ColorIf (Mouse.X<pxm.Width) And (Mouse.Y<pxm.Height)ARGB = pxm.GetPixelARGB( Mouse.X,Mouse.Y )Ink = pxm.GetPixel( Mouse.X,Mouse.Y )canvas.DrawText( "image color ARGB $" + Hex(ARGB),0,Height-100 )canvas.DrawText( "Alpha " + Ink.A,0,Height-20 )canvas.DrawText( "Red " + Ink.R,0,Height-80 )canvas.DrawText( "Green " + Ink.G,0,Height-60 )canvas.DrawText( "Blue " + Ink.B,0,Height-40 )canvas.DrawText( "Alpha " + Ink.A,0,Height-20 )Endifcanvas.DrawText("Move the mouse from 0,0 to 150,49",0,Height-140)canvas.DrawText("Mouse "+Mouse.X+"-"+Mouse.Y,0,Height-160)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndNow the question : How can i get the color of a pixel in the image ?
For Keyboard events, i must experiment, (2900 lines of code in my prog), to see if my code is faulty.
I saw some of his videos. He’s a pro game dev, and knows the job.
Good, he mentions Monkey 2 in France.
There are francophone users here. One more.
Bienvenue à bord.For creating Hud , I start with erased image, canvas.Clear(Color.None) and draw with BlendMode.Alpha
and adjust the Alpha component of the drawing color.
In the main loop , I draw this image on the screen. But it’s always the same.Try this , using A, D, M, O, and Up/Down Keys.
See the Color’s info under the mouse, blendmode will make sense.
Transparency is where you see the red balls.
Coded with Monkey2 1.1.06Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105' ---------------------------------------' alphatest2.monkey2' ---------------------------------------Namespace alphatest2#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField pxm:PixmapField img:ImageField imgcanvas:CanvasField opacity:FloatField blmode : BlendModeField blmodename : StringMethod New()Super.New( "test",512, 512,WindowFlags.Resizable | WindowFlags.HighDPI )pxm = New Pixmap( 300,300,PixelFormat.RGBA32 )img = New Image( pxm,TextureFlags.None,Null )imgcanvas = New Canvas(img)opacity = 0.5blmode = BlendMode.Opaqueblmodename = "Opaque"EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()' Draw your Screen background here (Red Circles)canvas.Clear(Color.Black)For Local lc:Int = 1 To 8For Local li:Int = 1 To 6canvas.Color = Color.Redcanvas.DrawCircle( lc*55,li*55,25 )NextNext' Adjust Opacity and BlendModeIf Keyboard.KeyPressed(Key.Up)opacity = Clamp( opacity+0.1,0.0,1.0 )Elseif Keyboard.KeyPressed( Key.Down )opacity = Clamp( opacity-0.1,0.0,1.0 )Elseif Keyboard.KeyPressed( Key.A)blmode = BlendMode.Alphablmodename = "Alpha"Elseif Keyboard.KeyPressed( Key.O)blmode = BlendMode.Opaqueblmodename = "Opaque"Elseif Keyboard.KeyPressed( Key.M)blmode = BlendMode.Multiplyblmodename = "Multiply"Elseif Keyboard.KeyPressed( Key.D)blmode = BlendMode.Additiveblmodename = "Additive"Endif' Draw orange squares into image according to params (opacity and BlendMode)' These 9 next lines dont have to be in you main loopimgcanvas.Clear(Color.None) ' Clear the image And Alpha = 0.0imgcanvas.Color = Color.Blue' And paint bottom half in blue and Alpha = 1.0imgcanvas.DrawRect(0,0,pxm.Width,pxm.Height/2)imgcanvas.Color = New Color( 0.9, 0.4, 0.0, opacity )imgcanvas.BlendMode=blmodeimgcanvas.DrawRect( 50, 50, 100, 100 )imgcanvas.DrawRect( 75, 75, 100, 100 )imgcanvas.DrawRect( 100, 100, 100, 100 )imgcanvas.Flush()' Try the results without cheatingcanvas.Color = New Color( 1, 1, 1, 1 )canvas.Alpha = 1canvas.DrawImage( img,0,0 )' Show Pixels dataLocal ARGB:UIntIf (Mouse.X<pxm.Width) And (Mouse.Y<pxm.Height)ARGB = pxm.GetPixelARGB(Mouse.X,Mouse.Y)canvas.DrawText( "image color ARGB $" + Hex(ARGB),0,Height-40 )Endifcanvas.DrawText( "Move the mouse pointer",0,Height-70 )canvas.DrawText( "See alpha component (left 2 bytes) of the",0,Height-56 )' opacity and BlendModecanvas.DrawText("Opacity " +opacity,Width-150,Height-70 )canvas.DrawText(blmodename,Width-150,Height-40)canvas.DrawText( "Up Down keys",Width-150,Height-56 )canvas.DrawText( "A D M O keys",Width-150,Height-28 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndHello,
Assuming you read your file line by line in the txt$ variable.
Tested in BlitzPlus, should work in Blitz3D too1234567891011121314151617181920212223242526txt$ = "320 x 200"c = 1width$ = ""height$ = ""colDepth$ = ""; ---- decode WidthWhile c<=Len(txt$) And Mid(txt$,c,1)<>"x"width$ = width$ + Mid(txt$,c,1)c = c + 1Wendwidth_screen = Int(width$)c = c + 1; skip the x char; ---- decode HeightWhile c<=Len(txt$) And Mid(txt$,c,1)<>"x"height$ = height$ + Mid(txt$,c,1)c = c + 1Wendheight_screen = Int(height$)Text 0,0,txt$Text 0,12,width_screenText 0,24,height_screenHi,
J’adore cette idée de stimuler les patients avec des images et animations. Tout comme l’appli avec des grimaces.
Monkey 1 (v85.e) exes work on my old PC Window XP SP3 – RAM 1Go.
You need OpenAL32.dll (version 0.9.5.1) in your C:\Windows\System32\ folder
Or you can put it in the same directory as your .exeMonkey 2 exes fail at entry point of strnlen in msvcrt.dll, 64 bit needed ?
-
AuthorPosts