Announcement

Collapse
No announcement yet.

Android - Graphics (Canvas)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Android - Graphics (Canvas)

    This example shows transparency and rotation. Of course real moon doesnt rotate like that, it was just to show rotation.

    Although the source code for the upcoming OpenGL implementation is almost identical, this source code is for working with
    Canvas and direct bitmaps.

    Canvas is not as fast as OpenGL (which only changes the CANVAS keyword to OPENGL), but it has functionality not present for OpenGL.

    Canvas graphics are very useful for generating sprites on the fly and then load them as an OpenGL shader for use as sprite.


    Code:
    [FONT=Courier New][B]
    [COLOR=Blue]#COMPILE[/COLOR] [COLOR=Blue]APK[/COLOR]
    [COLOR=Blue]#DIM[/COLOR] [COLOR=Blue]ALL[/COLOR]
    [COLOR=Blue]#REPORT[/COLOR] [COLOR=Blue]NONE[/COLOR]
    [COLOR=Blue]#ENCODE[/COLOR] [COLOR=Black]NO[/COLOR]
    [COLOR=Blue]#PROJECT[/COLOR] [COLOR=DarkGreen]"generic"[/COLOR]
    [COLOR=Blue]#VERSION[/COLOR] [COLOR=Blue]AUTO[/COLOR]
    [COLOR=Blue]#OPTIONS[/COLOR] [COLOR=Black]LANDSCAPE[/COLOR][COLOR=Black],[/COLOR] [COLOR=Blue]FULLSCREEN[/COLOR][COLOR=Black],[/COLOR] [COLOR=Blue]NONAVIGATION[/COLOR] 
    
    [COLOR=Blue]#SPRITE[/COLOR] [COLOR=Black]Moon[/COLOR][COLOR=Black],[/COLOR]  [COLOR=DarkGreen]"moon.png"[/COLOR][COLOR=Black],[/COLOR]   [COLOR=Black]392[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]392[/COLOR]
    [COLOR=Blue]#SPRITE[/COLOR] [COLOR=Black]Cloud[/COLOR][COLOR=Black],[/COLOR] [COLOR=DarkGreen]"clouds.png"[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]596[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]267[/COLOR]
    
    
    [COLOR=Blue]CALLBACK[/COLOR] [COLOR=Blue]FUNCTION[/COLOR] [COLOR=Black]MoonCicle[/COLOR][COLOR=Black]([/COLOR][COLOR=Black])[/COLOR] [COLOR=Blue]AS[/COLOR] [COLOR=Blue]LONG[/COLOR]
    
    [COLOR=Blue]SELECT[/COLOR] [COLOR=Blue]CASE[/COLOR] [COLOR=Black]cb.msg[/COLOR]
        [COLOR=Blue]CASE[/COLOR] [COLOR=Red]%WM_PREPARE[/COLOR]
            [COLOR=Blue]INITSPRITES[/COLOR]        
            [COLOR=Blue]CANVAS[/COLOR] [COLOR=Blue]SET[/COLOR] [COLOR=Blue]FRAMERATE[/COLOR] [COLOR=Black]cb.hwnd[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]30[/COLOR]
            [COLOR=Blue]CANVAS[/COLOR] [COLOR=Blue]SET[/COLOR] [COLOR=Blue]COLOR[/COLOR]     [COLOR=Black]cb.hwnd[/COLOR][COLOR=Black],[/COLOR] [COLOR=Blue]RGB[/COLOR][COLOR=Black]([/COLOR][COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black])[/COLOR][COLOR=Black],[/COLOR] [COLOR=Blue]RGB[/COLOR][COLOR=Black]([/COLOR][COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black])[/COLOR]
           
            [COLOR=Black]Moon.X[/COLOR] [COLOR=Black]=[/COLOR] [COLOR=Black]10[/COLOR]                            
            [COLOR=Black]Moon.Y[/COLOR] [COLOR=Black]=[/COLOR] [COLOR=Black]10[/COLOR]
            [COLOR=Black]Cloud.X[/COLOR] [COLOR=Black]=[/COLOR] [COLOR=Black]-[/COLOR][COLOR=Black]596[/COLOR]
            [COLOR=Black]Cloud.Y[/COLOR] [COLOR=Black]=[/COLOR] [COLOR=Black]160[/COLOR]
                    
        [COLOR=Blue]CASE[/COLOR] [COLOR=Red]%WM_PAINT[/COLOR]    
            [COLOR=Blue]CANVAS[/COLOR] [COLOR=Blue]DRAW[/COLOR] [COLOR=Blue]RECTANGLE[/COLOR] [COLOR=Black]Cb.hwnd[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]1500[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]1200[/COLOR]
                    
            [COLOR=Blue]INCR[/COLOR] [COLOR=Black]Moon.angle[/COLOR] [COLOR=Blue]BY[/COLOR] [COLOR=Black]0.1[/COLOR]
            [COLOR=Blue]INCR[/COLOR] [COLOR=Black]Cloud.X[/COLOR] [COLOR=Blue]BY[/COLOR] [COLOR=Black]1[/COLOR]
            [COLOR=Blue]IF[/COLOR] [COLOR=Black]Cloud.X[/COLOR] [COLOR=Black]>[/COLOR] [COLOR=Black]1200[/COLOR] [COLOR=Blue]THEN[/COLOR] [COLOR=Black]Cloud.X[/COLOR] [COLOR=Black]=[/COLOR] [COLOR=Black]-[/COLOR][COLOR=Black]596[/COLOR] [COLOR=Black]:[/COLOR] [COLOR=Black]Cloud.Y[/COLOR] [COLOR=Black]=[/COLOR] [COLOR=Blue]RND[/COLOR][COLOR=Black]([/COLOR][COLOR=Black]120[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]200[/COLOR][COLOR=Black])[/COLOR]
                               
            [COLOR=Blue]CANVAS[/COLOR] [COLOR=Blue]DRAW[/COLOR] [COLOR=Blue]SPRITE[/COLOR] [COLOR=Black]cb.hwnd[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]Moon[/COLOR]
            [COLOR=Blue]CANVAS[/COLOR] [COLOR=Blue]DRAW[/COLOR] [COLOR=Blue]SPRITE[/COLOR] [COLOR=Black]cb.hwnd[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]Cloud[/COLOR]
            
            
    [COLOR=Blue]END[/COLOR] [COLOR=Blue]SELECT[/COLOR]
    
    [COLOR=Blue]END[/COLOR] [COLOR=Blue]FUNCTION[/COLOR]
    
    
    [COLOR=Blue]FUNCTION[/COLOR] [COLOR=Black]PBMAIN[/COLOR][COLOR=Black]([/COLOR][COLOR=Black])[/COLOR] [COLOR=Blue]AS[/COLOR] [COLOR=Blue]LONG[/COLOR]
    
    [COLOR=Blue]LOCAL[/COLOR] [COLOR=Black]hDlg[/COLOR] [COLOR=Blue]AS[/COLOR] [COLOR=Blue]LONG[/COLOR]
    
    [COLOR=Blue]DIALOG[/COLOR] [COLOR=Blue]NEW[/COLOR] [COLOR=Blue]GAME[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=DarkGreen]"Moon Examle"[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR][COLOR=Black],[/COLOR] [COLOR=Black]0[/COLOR] [COLOR=Blue]TO[/COLOR] [COLOR=Black]hDlg[/COLOR]
    [COLOR=Blue]DIALOG[/COLOR] [COLOR=Blue]SHOW[/COLOR] [COLOR=Blue]MODAL[/COLOR] [COLOR=Black]hDlg[/COLOR] [COLOR=Blue]CALL[/COLOR] [COLOR=Black]MoonCicle[/COLOR][COLOR=Black]([/COLOR][COLOR=Black])[/COLOR]           
    
    [COLOR=Blue]END[/COLOR] [COLOR=Blue]FUNCTION[/COLOR][/B][/FONT]

    www.patreon.com/pluribasic
Working...
X