Jump to content

How to update BitmapText's text correct way?


0xfd3495
 Share

Recommended Posts

Hello,

I'm new in game progremming. I was read better than as performance BitmapText instead of Normal font on PixiJS. That's way I prefered BitmapText. I couldn't found detail. both any google searching and that in api documentation for update text as BitmapText.

My way solve that's like is; remove object, create object as updated with new text, object add to child.

 

import { Application, Graphics, BitmapText } from 'pixi.js'
import {GlowFilter} from '@pixi/filter-glow';

function emit(name:string, payload:any = true, ms=10) {
	setTimeout(function(){
		gameEvents.dispatchEvent(new CustomEvent(name, { detail: payload }));
	}, ms);
  }

const gameEvents = document.createElement('div');

// ....

let playerCoord: BitmapText;

app.loader.add('desyrel', 'desyrel.xml')
	.load(function(){
		updateCoord(0, 0);
		emit("LOADED_DESYREL_BMAP_FONT");
	});


function updateCoord(x=0, y=0) {
	app.stage.removeChild(playerCoord);
	playerCoord = new BitmapText(`X: ${x}, Y: ${y}`, {
		fontName: 'Desyrel', 
		fontSize: 24, 
		align: 'left'
	});
	playerCoord.x = 10;
    playerCoord.y = 10;
	app.stage.addChild(playerCoord);
}

function movement(gameObjet: any, stateKeys: any, speed: number = 4) {
	// ....
	updateCoord(gameObjet.position.x, gameObjet.position.y);
}

// ....

function playerGameLoop(){
	movement(player, stateKeys);	
}

gameEvents.addEventListener("LOADED_DESYREL_BMAP_FONT", function(){
	app.ticker.add(playerGameLoop);
});

 

Above code woking correctly.

 

But I wanted to learn real game programming architecture with performance. Therefore I want to ask you.

 

Thank you for interest.

Good works.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...