Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 174 forks source link

help --> project works with "old" syntax, not with new one... #1246

Closed Lykdraft closed 4 years ago

Lykdraft commented 4 years ago

So I got a little problem here. With both variants the project compiles. With both variants the rect is drawn. But the text is not and the image is not. I have no idea why that is. Any help here?

With this Main (the old way):

class Main {

 public static function main(){

    System.init({title:"Project", width: 1024, height: 768},
    function(){
        Assets.loadEverything(function(){
            var Project = new Project();
            Scheduler.addTimeTask(Project.update,0,1/60);
            System.notifyOnRender(Project.render);
        });
    });
 } 
}

This works:


import kha.Framebuffer;
import kha.Image; 
import kha.Assets;
import kha.Font;
import kha.Color;

using kha.graphics2.GraphicsExtension; 

class Project {

    public var rect:Rect;
    public var image:Image;
    public var font:Font;

    public function new (){
        rect = new Rect();
        image = Assets.images.Vechta;
        font = Assets.fonts.AndaleMono;
    }

    public function update():Void{
    }

    public function render (framebuffer:Framebuffer):Void{

        var graphics = framebuffer.g2;
        graphics.begin();
        graphics.color = Color.Blue;
        graphics.drawRect(40,40,40,40,6);
        graphics.font = font;
        graphics.fontSize = 98;
        graphics.drawString("Dodomann!!", 300,450);
        graphics.end();
    }
}

But not with this Main:

 class Main {
    public static function main() : Void {
        System.start({title:"Project", width:1024, height:768}, initialized);
    }

    private static function initialized(window : Window) : Void {
        var game = new Project();
        System.notifyOnFrames(
            function(fbs : Array<Framebuffer>) {
                game.render(fbs[0]);
            }
        );
        Scheduler.addTimeTask(game.update, 0, 1 / 60);
    }
}
RobDangerous commented 4 years ago

Did the issue template not show up or did you avoid it on purpose?

Lykdraft commented 4 years ago

Man, I am stupid. Sorry. I forgot to include:

import kha.Assets;
Assets.loadEverything

in the new main. I'll have to check it out, but I think that this was it... Sorry for that...:)

Lykdraft commented 4 years ago

I am just not sure about where to place it now. Can you tell me this?

RobDangerous commented 4 years ago

If it's just a question like here it should actually go to the forum. I'm still confused though. There's no image drawing. And didn't you get an error for the font?

Lykdraft commented 4 years ago

No, no error. In Debug I get: undefined SystemImpl.hx:60 though.

RobDangerous commented 4 years ago

That's the error I was looking for. But the error message is admittedly confusing, improved that now.

Lykdraft commented 4 years ago

Alright, thank you.
In the future I will use the forum for this. I thought this was a bigger problem that that, sorry again.

RobDangerous commented 4 years ago

If you think it's a problem in Kha, please use the bug template in the future.