Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug about Font #1396

Open
lazyfish-zcw opened this issue Jan 16, 2025 · 3 comments
Open

A bug about Font #1396

lazyfish-zcw opened this issue Jan 16, 2025 · 3 comments

Comments

@lazyfish-zcw
Copy link

Hello, AlmasB,In my code, when I press F to have a Chinese conversation and press W to quickly move my game player, a string of white dots will be left under the screen and disappear soon. However, when I use English lines, the white dots disappear. Is this a bug?

import com.almasb.fxgl.animation.AnimatedStringIncreasing;
import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.SpawnData;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.util.Duration;

import static com.almasb.fxgl.dsl.FXGL.*;

public class MyGameApp02 extends GameApplication {

    private Entity player;

    @Override
    protected void initSettings(GameSettings settings) {
        settings.setTitle("GameApp1");
        settings.setVersion("0.1");
    }

    @Override
    protected void initGame() {

        FXGL.getGameScene().setBackgroundColor(Color.rgb(33,33,33));

        Text playerNameText = new Text("玩家姓名");
        playerNameText.setFill(Color.WHITE);
        playerNameText.setFont(Font.font("KaiTi", FontWeight.BOLD, FontPosture.REGULAR, 13));


        player= FXGL.entityBuilder()
                .type(GameType.PLAYER)
                .at(100, 100)
                .view(playerNameText)
                .viewWithBBox(new Rectangle(20, 30, Color.web("#efc883")))
                .collidable()
                .buildAndAttach();
        playerNameText.setLayoutX(player.getWidth() - 30);
        playerNameText.setLayoutY(player.getHeight() + 18);


        // npc姓名
        Text npcNameText = new Text("NPC");
        npcNameText.setFill(Color.WHITE);
        npcNameText.setFont(Font.font("KaiTi", FontWeight.BOLD, FontPosture.REGULAR, 13));
        // 生成一个NPC
        Entity npc = FXGL.entityBuilder()
                .type(GameType.NPC)
                .at(600, 500)
                .view(npcNameText)
                .viewWithBBox(new Rectangle(20, 30, Color.web("#fc5531")))
                .collidable()
                .buildAndAttach();
        npcNameText.setLayoutX(npc.getWidth() - 30);
        npcNameText.setLayoutY(npc.getHeight() + 18);

    }

    @Override
    protected void initPhysics() {
//        FXGL.onCollision(GameType.PLAYER, GameType.NPC, (player, npc) -> {
//            System.out.println("player和npc发生了碰撞");
//        });
    }

    @Override
    protected void initInput() {
        FXGL.onKey(KeyCode.W, ()-> player.translateY(-3));
        FXGL.onKey(KeyCode.S, ()-> player.translateY(3));
        FXGL.onKey(KeyCode.A, ()-> player.translateX(-3));
        FXGL.onKey(KeyCode.D, ()-> player.translateX(3));

        // 按下F触发对话
        FXGL.onKeyDown(KeyCode.F, ()-> {
            System.out.println("按下F");
            // 对话框
            Text dialogArrea = new Text("");
            dialogArrea.setWrappingWidth(250);
            dialogArrea.setFill(Color.WHITE);
            dialogArrea.setFont(Font.font("KaiTi", FontWeight.BOLD, FontPosture.REGULAR, 14));



            Entity dialogEntity = entityBuilder()
                    .view(dialogArrea)
                    .buildAndAttach();

            dialogEntity.xProperty().bind(player.xProperty().add(-50));
            dialogEntity.yProperty().bind(player.yProperty().add(-10));

            animationBuilder()
                    .onFinished(() -> {
                        runOnce(() -> {
                            dialogEntity.removeFromWorld();
                        }, Duration.seconds(2));
                    })
                    .duration(Duration.seconds(1.5))
                    .animate(new AnimatedStringIncreasing("你好,请问附近有什么旅店吗?"))
//                    .animate(new AnimatedStringIncreasing("Hello, may I ask if there are any hotels nearby?"))
                    .onProgress(s -> dialogArrea.setText(s))
                    .buildAndPlay();

        });
    }

    private Entity setNameForEntity(Entity entity, String name) {
        SpawnData spawnData = new SpawnData();
        spawnData.put("name", name);
        spawnData.put("entity", entity);
        return spawn("name", spawnData);
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Image

@lazyfish-zcw
Copy link
Author

Hello, Almas, This seems to be a bug about commas, you know, commas are different in Chinese and English. When I use commas with Chinese symbols, this bug appears. When I use commas with English symbols, this bug disappears, regardless of whether other words are in Chinese or English.

@lazyfish-zcw
Copy link
Author

Hi, Almas, after my further testing, it actually has something to do with the font, when I change the font of my lines to another font, This bug disappears in both Chinese and English, and KaiTi is a very common font in Chinese.

@lazyfish-zcw lazyfish-zcw changed the title A bug about AnimatedStringIncreasing, ui node residue A bug about Font Jan 16, 2025
@AlmasB
Copy link
Owner

AlmasB commented Jan 17, 2025

Hi @lazyfish-zcw

For UI rendering, FXGL uses JavaFX. So the issue may go deeper than FXGL. Could you produce a minimal JavaFX app with just a single Text object showing the issue? As an alternative, you can also try using an external ttf file for the font and see if it has the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants