简体   繁体   中英

Text gets overlapped in Pixi.js

I am using PIXI.js, i want to increment a counter and display it on the screen. 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. 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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