godotjs / javascript

Javascript binding for godotengine
https://godotjs.github.io/
MIT License
980 stars 82 forks source link

Code not fully executed #112

Closed ghost closed 2 years ago

ghost commented 2 years ago

This code isn't fully executed with latest editor build (v3.2.3). Debugger has no errors.

import RecoyxLogo from 'res://res/img/company-logo/recoyx.png';

export default class PresentsState extends godot.Node2D {
    constructor() {
        super();
    }

    async _ready() {
        await godot.yield(this.get_tree(), 'idle_frame');
        // logs "[StreamTexture...]"
        console.log(RecoyxLogo);
        let recoyxLogo = new RecoyxLogo;
        recoyxLogo.position = new godot.Vector2(0, 0);
        this.add_child(recoyxLogo);
        // does not log "Here"
        console.log('Here');
        console.log(recoyxLogo);
    }

    _process(delta) {
    }
}
Devilsparta commented 2 years ago

try not new RecoyxLogo, use RecoyxLogo.instance() instead? I still wonder if there is a chance to instance an image.

Geequlim commented 2 years ago

you should get an instance of the image when you import it

ghost commented 2 years ago

@Geequlim I tried:

await godot.yield(this.get_tree(), 'idle_frame');
console.log('a');
let recoyxLogo = RecoyxLogo;
console.log('b');
recoyxLogo.position = new godot.Vector2(0, 0);
console.log('c');
this.add_child(recoyxLogo);
console.log('d');

Did not log 'd' and did not show the image on the scene.

I also tried RecoyxLogo.instance() as @Devilsparta said. When I use RecoyxLogo.instance(), it doesn't log 'b'.

ghost commented 2 years ago

Finally I also tried let recoyxLogo = await import('res://img/company-logo/recoyx.png');. It doesn't log 'c' nor show the image.