简体   繁体   English

文字在Pixi.js中重叠

[英]Text gets overlapped in Pixi.js

I am using PIXI.js, i want to increment a counter and display it on the screen. 我正在使用PIXI.js,我想增加一个计数器并将其显示在屏幕上。 However, the text overlaps. 但是,文本重叠。

var count=0;
count++;


var text = new PIXI.Text(count, {font:"50px Arial", fill:"red"});
    text.x = stageWidth / 2 - text.width / 2;
    text.y = stageHeight / 2;

    stage.addChild(text);

How can i prevent this from happening. 我如何防止这种情况的发生。

Make sure you only create one PIXI.Text instance and then update the count. 确保仅创建一个PIXI.Text实例,然后更新计数。 That way the old text will be replaced with the new value and you'll save a lot on performance by creating less instances: 这样,旧文本将被新值替换,并且通过减少实例数量,您将在性能上节省很多:

var count = 0;

var text = new PIXI.Text(count, {font:"50px Arial", fill:"red"});
    text.x = stageWidth / 2 - text.width / 2;
    text.y = stageHeight / 2;

    stage.addChild(text);

function incrementCount() {
    count++;
    text.setText(count);
}

incrementCount();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM