fastjengine / FastJ

An open-source, Java-based 2D game engine.
https://fastj.tech
MIT License
82 stars 22 forks source link

[Bug] Broken button positioning #63

Closed lines-of-codes closed 3 years ago

lines-of-codes commented 3 years ago

Platform Info

Place an x in the box(es) [x] that the issue occurs on (or that you've found the issue on)

Describe the Bug

A clear and concise description of what the bug is. The button position is set, But the button is still placed at the top left corner.

Expected Behavior

A clear and concise description of what you expected to happen. The button supposed to Position properly.

How to Reproduce the Bug

Steps to reproduce the behavior:

  1. Create a New button (in Scenes)
  2. Position it somewhere that is not in the Top left corner.
  3. Run the game
  4. See that the Button is still placed on the Top left corner

Media Aid

If applicable, add screenshots/GIFs/videos to help explain your problem.

Additional context

Additional context not provided above. The FastJ version I was using was FastJ 1.5.0 (Snapshot) You have to use the Scenes workflow to reproduce it. (Because Buttons only supports scenes at the moment)

lucasstarsz commented 3 years ago

First off, I'll make sure to allow Buttons to be created and work with SimpleManager. Thanks for pointing that out!

lucasstarsz commented 3 years ago

Now that that is out of the way... can you provide the code that you used to produce this issue? I'm having trouble reproducing this bug with the following code:

public class ButtonTest extends SimpleManager {
    @Override
    public void init(Display display) {
        Button button = new Button(this, new Pointf(50f), Button.DefaultSize);
        drawableManager.addUIElement(button);
    }

    @Override
    public void update(Display display) {
    }

    public static void main(String[] args) {
        FastJEngine.init("bs", new ButtonTest());
        FastJEngine.run();
    }
}

as well as with this code:

public class ButtonSceneTest extends SceneManager {
    @Override
    public void init(Display display) {
        ButtonScene buttonScene = new ButtonScene();
        addScene(buttonScene);
        setCurrentScene(buttonScene);
        loadCurrentScene();
    }

    public static void main(String[] args) {
        FastJEngine.init("bs", new ButtonSceneTest());
        FastJEngine.run();
    }
}

public class ButtonScene extends Scene {
    protected ButtonScene() {
        super("test");
    }

    @Override
    public void load(Display display) {
        Button button = new Button(this, new Pointf(50f), Button.DefaultSize);
        drawableManager.addUIElement(button);
    }

    @Override
    public void unload(Display display) {
    }

    @Override
    public void update(Display display) {
    }
}

In both instances, the produced result is this: image

lucasstarsz commented 3 years ago

Upon inspecting the code base a bit more, I realized that the Button class never uses the transforms that are given to it. Assuming you were using translate or some other method to try and move the button, the button wouldn't have moved simply because there was nothing telling it to move. Please in the future, provide all the relevant code so that an issue like this can be solved faster. Regardless, thank you for letting me know. I'll get to work on it as soon as I have time -- life has been very busy on my side, so I haven't had much time for these projects. Thank you!

lines-of-codes commented 3 years ago

Upon inspecting the code base a bit more, I realized that the Button class never uses the transforms that are given to it. Assuming you were using translate or some other method to try and move the button, the button wouldn't have moved simply because there was nothing telling it to move.

Sorry for the late reply, But I use setTranslation to move the button.

new Button(this)
    .setFont(mainFont)
    .setText("Next")
    .setTranslation(new Pointf(displayRes.x - 125, displayRes.y - 75));
lucasstarsz commented 3 years ago

Apologies for not responding for so long -- I've been very busy and haven't had much time to do anything more than a few sparse minutes on the project as of late. In the time that I had, I've been able to add the missing code and likely fix issues you may have been receiving.

Thanks to the latest few commits (and a few discoveries I've made along the way) I've also been able to set up the latest commits to be used as needed to test features as they're added. To test out these fixes for your code, change the dependency content to this:

repositories.maven {
    url('https://jitpack.io')
}

dependencies.implementation('com.github.fastjengine:FastJ:1.5.0-SNAPSHOT-2')

1.5.0-SNAPSHOT-2 is the latest snapshot with the issue fixed -- once a new stable release of the game engine comes out, be sure to move on to a more concrete version.

Please let me know if you have any further issues, and thank you for letting me know about this one!

lucasstarsz commented 3 years ago

Now that1.5.0 snapshot 2 has been released, I've gone and updated the comment above with the preferred version for you to use.

lines-of-codes commented 3 years ago

Hi, I've tried the latest snapshot (1.5.0 Snapshot 2), The button now being placed in the correct position.