Yeah the aspect ratio coult possibly change.

But thanks again Robert, Scaler.transformXDirectly and Scaler.transformYDirectly did the job.

posted in Kha read more

Hi all,

I have problems with backbuffer, screen resize and mouse position.

I create a backbuffer for rendering everything in the size 800/600 and then scale it to the framebuffer like in the kha shmup tutorial or in Lewis Leptons Kha Tutorial #23


everything works great!

I am also using the full-page canvas from the wiki (

Now i want to add a rectangle under the mousecursor on click.
To calculate the mouse coordinates to the backbuffer coordinates i do

    var normalizeX:Float = x / System.windowWidth() * Game.backbuffer.width;
    var normalizeY:Float = y / System.windowHeight() * Game.backbuffer.height;

everything works fine if the backbuffer size = window size.
if change the windowsize it's acting wrong. What am I missing?

Here is a Kodegarden example
just run it and change the size of the browser window.

or here is a example of my work with the full-page canvas

Thanks for the tips and help! :)

posted in Kha read more

Thanks Robert! That helped! :)

I should have ask earlier... before i put hours in possible workarounds! :D

posted in Kha read more

I'm using the Method and everything works fine in HTML5. When I run the same code with windows target, it doesn't work. The method returns 0.

That's okay, that's what the code is doing on Windows target. Is there any plan to integrate this in teh future for windows targets. Or is there another possibility to get the Pixel information from a Image/Asset?

Thanks for the help! :-)

posted in Kha read more

Ah you fixed Kodegarden. So here is my example:

In my opinion i should see a blue screen.

posted in Kha read more

I tried Kodegarden, but it stopped working for me. Neither in Chrome, Firefox or Edge I can see anything im writing. And if I download the Project nothing has happend. It's still the code from the beginning. Lubos Lencos Tutorials doesn't work too...

so here is my short Codeexample:

  import kha.Color;
  import kha.Framebuffer;
  import kha.System;
  import kha.Scheduler;
  import kha.Image;
  class Main {

static var image:Image;

public static function main() {
    System.init({title: "Kode Project", width: 800, height: 600}, function() {
        // Avoid passing update/render directly so replacing
        // them via code injection works
        Scheduler.addTimeTask(function () { update(); }, 0, 1 / 60);
        System.notifyOnRender(function (framebuffer) { render(framebuffer); });

        image = Image.createRenderTarget(800,600);
        var g1 = image.g1;
        for(x in 0 ... 800)
            for(y in 0 ... 600)


static function update(): Void {


static function render(framebuffer: Framebuffer): Void {
    var graphics = framebuffer.g2;
    graphics.color = Color.Blue;


I would have expected a Bluescreen because I'm drawing an transparent Image on a blue rectangle. All I get is a black screen.

posted in Kha read more

Hm my 2D array had an error. I fixed it and now my Image gets drawn.

Now I have a new problem.
Transparent pixel are black and not tranparent is this an issue or is it my fault?

posted in Kha read more

I got a 2D Array for x and y with colorvalues and want to use Graphics1.setPixel() to create a new Image,
I want to draw this image in my rendermethod.

This is the Code to load the Image:

    img1 = Image.createRenderTarget(image.width,image.height);
    var graphics1 = img1.g1;
    for(x in 0 ... image.width)
        for(y in 0 ... image.height)
            var color:Color = pixels[x][y];

And my renderMethod looks like this:

  public function render(graphics:Graphics)

The graphics in the rendermethod is a graphics2 object.

my Problem is: Nothing happens. In the debugger the Image of img1 is null.
Isn't it possible to draw a image with the pixelcolorvalues in Graphics2?

posted in Kha read more