FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • How to align text dynamically inside a rectangle with Phaser JSAna DEV
    I am just starting to learn the Phaser JS framework with my first game. I did not managed to find a way how i can align text inside a rectangle element dynamically without specific coordinates. Here is what i have pointH11L1 = game.add.text(0, 0, '20'); pointH11L1.stroke = "#000"; pointH11L1.strokeThickness = 4; pointH11L1.font = 'oswaldbold'; pointH11L1.fontSize = 22; pointH11L1.fill = '#999999'; //pointH11L1.alignIn(graphicsRectH12L2, Phaser.CENTER); graphicsRectH12L2.addChild(pointH11L1);
     

How to align text dynamically inside a rectangle with Phaser JS

I am just starting to learn the Phaser JS framework with my first game. I did not managed to find a way how i can align text inside a rectangle element dynamically without specific coordinates. Here is what i have

pointH11L1 = game.add.text(0, 0, '20'); 
pointH11L1.stroke = "#000";
pointH11L1.strokeThickness = 4;
pointH11L1.font = 'oswaldbold';
pointH11L1.fontSize = 22;
pointH11L1.fill = '#999999';
//pointH11L1.alignIn(graphicsRectH12L2, Phaser.CENTER);
graphicsRectH12L2.addChild(pointH11L1);
pointH11L1.x = pointH11L1.width / 2 - 6; 
pointH11L1.y = -2.5;

//graphicsRectH12L2 is the rectangle inside which i need to align.

var graphicsRectH12L2 = this.game.add.graphics(950, 405); 
    graphicsRectH12L2.beginFill(0xffcd00, 1);
    graphicsRectH12L2.drawRect(0, 0, 44, 29);
    graphicsRectH12L2.endFill(0xffcd00, 1);
    group.add(graphicsRectH12L2);
❌
❌