Advertisement
Guest User

Untitled

a guest
May 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.65 KB | None | 0 0
  1. package;
  2.  
  3. import kha.Framebuffer;
  4. import kha.Color;
  5. import kha.Image;
  6. import kha.Scaler;
  7. import kha.System;
  8. import kha.Scheduler;
  9. import kha.Assets;
  10.  
  11. class Project {
  12.     public static inline var screenWidth = 800;
  13.     public static inline var screenHeight = 600;
  14.     private static var bgColor = Color.fromValue(0x000000);
  15.     private var backBuffer:Image;
  16.     private var initialized:Bool = false;
  17.     private var frames:Int;
  18.     private var x:Float;
  19.     private var not:Bool;
  20.    
  21.     public function new()
  22.     {
  23.        
  24.         System.notifyOnRender(render);
  25.         Scheduler.addTimeTask(update, 0, 1 / 24);
  26.        
  27.         Assets.loadEverything(function()
  28.         {
  29.             initialized = true;
  30.             //font = Assets.fonts.Inconsolata_Regular;
  31.             //trace(font.height(24));
  32.  
  33.            
  34.  
  35.         });
  36.    
  37.  
  38.         backBuffer = Image.createRenderTarget(screenWidth, screenHeight);
  39.        
  40.     }
  41.  
  42.     public function update():Void
  43.     {
  44.         if(not)
  45.         {
  46.             x = not ? screenWidth / 2 : -screenWidth / 2;
  47.             not = !not;
  48.         }
  49.     }
  50.  
  51.     public function render(framebuffer:Framebuffer): Void
  52.     {
  53.         /*if (!initialized)
  54.         {
  55.             trace("Initializing...?");
  56.             return;
  57.         }*/
  58.  
  59.         trace("Initializing...?");
  60.  
  61.         frames += 1;
  62.  
  63.         // clear our backbuffer using graphics2
  64.         var g = framebuffer.g2;
  65.         g.begin();
  66.         g.clear(bgColor);
  67.  
  68.         //g.font = font;
  69.         //g.fontSize = 24;
  70.         g.color = Color.fromValue(0xFF0000); // red text
  71.  
  72.         //sg.drawString("Hello, world!", 50, 20); // Draw "Hello, World!" at (50, 20)
  73.        
  74.         g.drawRect(10,200, 100, 20);
  75.         g.drawLine(10,10,200,100);
  76.        
  77.  
  78.         g.end();
  79.  
  80. /*
  81.         framebuffer.g2.begin();
  82.         Scaler.scale(backBuffer, framebuffer, System.screenRotation);
  83.         framebuffer.g2.end();
  84.         */
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement