Created
November 3, 2018 16:14
-
-
Save nanjizal/40a7f42a4243263bb261f80b984586f6 to your computer and use it in GitHub Desktop.
RectPack2D demo test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import kha.Framebuffer; | |
import kha.System; | |
import kha.Image; | |
import kha.Color; | |
import kha.Assets; | |
import kha.Scaler; | |
import kha.Color; | |
import kha.Font; | |
import kha.Assets; | |
import kha.Scheduler; | |
import kha.graphics2.Graphics; | |
import kha.graphics4.DepthStencilFormat; | |
import kha.input.Keyboard; | |
import kha.input.Mouse; | |
import kha.input.KeyCode; | |
import kha.math.FastMatrix3; | |
import kha.WindowOptions; | |
import kha.WindowMode; | |
import kha.Window; | |
class Main { | |
var font:Font; | |
public static | |
function main() { | |
System.start( { title: "RectPack2D demo" | |
, width: 4096, height: 4096 | |
, window: { windowFeatures: FeatureResizable } | |
, framebuffer: { samplesPerPixel: 4 } } | |
, function( window: Window ){ | |
new Main(); | |
} ); | |
} | |
public function new(){ Assets.loadEverything( loadAll ); } | |
public function loadAll(){ | |
trace( 'loadAll' ); | |
font = Assets.fonts.Arimo_Bold; | |
startRendering(); | |
initInputs(); | |
} | |
function startRendering(){ | |
System.notifyOnFrames( function ( framebuffer ) { render( framebuffer[0] ); } ); | |
Scheduler.addTimeTask(update, 0, 1 / 60); | |
} | |
inline | |
function render( framebuffer: Framebuffer ){ | |
var g: Graphics = framebuffer.g2; | |
g.begin( true, 0xFFFFFFFF ); | |
g.font = font; | |
g.fontSize = 24; | |
g.color = Color.Black; | |
g.drawString( "Hello, world!", 50, 20 ); | |
g.end(); | |
} | |
inline | |
function update(): Void { | |
} | |
function initInputs() { | |
if (Mouse.get() != null) Mouse.get().notify( mouseDown, mouseUp, mouseMove, mouseWheel ); | |
if( Keyboard.get() != null ) Keyboard.get().notify( keyDown, keyUp, null ); | |
} | |
function keyDown( keyCode: Int ): Void { | |
trace('keydown ' + keyCode ); | |
} | |
function keyUp( keyCode: Int ): Void { | |
trace('keyup ' + keyCode ); | |
} | |
function mouseDown( button: Int, x: Int, y: Int ): Void { | |
trace('down'); | |
} | |
function mouseUp( button: Int, x: Int, y: Int ): Void { | |
trace('up'); | |
} | |
function mouseMove( x: Int, y: Int, movementX: Int, movementY: Int ): Void { | |
trace('Move'); | |
} | |
function mouseWheel( delta: Int ): Void { | |
trace('Wheel'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment