godotjs / javascript

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

Problem when instantiating image #113

Closed ghost closed 2 years ago

ghost commented 2 years ago

Problem

I tried importing an image instance in different ways:

None of these ways allow to show the image and, in some cases, code is not fully executed (using console.log()).

Editor version

3.2.3

How to reproduce

Involved code:

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

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

    async _ready() {
        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');
        console.log(recoyxLogo);
    }

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

What is the console.log(RecoyxLogo ) ?

ghost commented 2 years ago

It logs [StreamTexture:1189].

Geequlim commented 2 years ago

You don't need to instantiate the image. Just use it as an instantiated instance.

ghost commented 2 years ago

Yeah, I tried it, as stated on the top of my issue... Nothing is drawn on the screen and some logs don't occur...

Geequlim commented 2 years ago

You'd better learn how to use godot first.

ghost commented 2 years ago

My code is correct, I didn't try to do the same in GDScript, though. It seems like it's an issue with QuickJS.

Geequlim commented 2 years ago

No it is not an issue. [StreamTexture:1189] is a resource not a node.

ghost commented 2 years ago

That makes sense, but why doesn't console.log() occur or why is not an error thrown and logged in the debugger console?

ghost commented 2 years ago

I mean, if the last console.log() doesn't happen, then some error should have been thrown.

ghost commented 2 years ago

Now code fully works, but I still don't understand why it was silent.