About Monkey 2 › Forums › Monkey 2 Programming Help › Alpha and draw commands(rect/triangle)
This topic contains 2 replies, has 2 voices, and was last updated by
Pakz 2 years, 4 months ago.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
November 21, 2016 at 6:50 am #5289
How does the Alpha commands work with commands like drawrect?
I wanted to draw two sets of triangles on top of each other where the second set was transparent. But I spend a long time looking for and trying but it did not work.
I tried the canvas popmatrix and alpha and new color alpha. No result.
Monkey12345678910111213141516171819202122232425262728293031#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New()End MethodMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender() ' Activate this methodcanvas.Color = Color.Blackcanvas.DrawRect(100,100,100,100)canvas.BlendMode = BlendMode.Alphacanvas.Color = New Color(0.5,0.5,0.5,0.5)canvas.DrawRect(50,50,200,200)' if key escape then quitIf Keyboard.KeyReleased(Key.Escape) Then App.Terminate()End MethodEnd ClassFunction Main()New AppInstanceNew MyWindowApp.Run()End FunctionHelp!
November 21, 2016 at 7:59 am #5299Looks fine here… try adding something in the background so you can see the transparency:
[/crayon]Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455[crayon-5cb9d3076f42a825019410 inline="true" ]#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class BoxField x:Int, y:Int, w:Int, h:IntField color:ColorMethod Draw(canvas:Canvas)canvas.Color = colorcanvas.DrawRect(x, y, w, h)EndEndClass MyWindow Extends WindowField listOfBoxs:List<Box> = New List<Box>Method New()For Local i:Int = 0 To 100Local b:= New Boxb.x = Rnd(0, 640)b.y = Rnd(0, 480)b.w = Rnd(10, 100)b.h = Rnd(10, 100)b.color = New Color(Rnd(.5, 1), Rnd(.5, 1), Rnd(.5, 1), 1)listOfBoxs.AddLast(b)EndEnd MethodMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender() ' Activate this methodFor Local b:Box = Eachin listOfBoxsb.Draw(canvas)Endcanvas.Color = Color.Blackcanvas.DrawRect(100,100,100,100)canvas.BlendMode = BlendMode.Alphacanvas.Color = New Color(0.5, 0.5, 0.5, 0.65)canvas.DrawRect(150,50,200,200)' if key escape then quitIf Keyboard.KeyReleased(Key.Escape) Then App.Terminate()End MethodEnd ClassFunction Main()New AppInstanceNew MyWindowApp.Run()End FunctionNovember 21, 2016 at 12:33 pm #5309thanks:)
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.