Skip to content

Commit

Permalink
Add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Oct 27, 2024
1 parent fd30d0e commit d789285
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
5 changes: 5 additions & 0 deletions examples/bitmaptext/lineheight.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set main=./examples/bitmaptext/lineheight.js
cd ..
cd ..
npm run dev
51 changes: 51 additions & 0 deletions examples/bitmaptext/lineheight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import phaser from '../../../phaser/src/phaser.js';

class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}

preload() {
this.load.bitmapFont('gothic', 'assets/fonts/gothic.png', 'assets/fonts/gothic.xml');
}

create() {
var lines = [];
for (var i = 0; i < 5; i++) {
lines.push(i)
}
var s = lines.join('\n')
var txt = this.add.bitmapText(0, 0, 'gothic', s).setFontSize(30).setLineSpacing(20)

var textSize = txt.getTextBounds()
console.log(textSize)

var lineHeight = (textSize.lines.height + txt.lineSpacing) * textSize.scale;
console.log(textSize.lines.height, txt.lineSpacing, textSize.scale, lineHeight)
var graph = this.add.graphics()
.lineStyle(3, 0xff0000)

for (var i = 1; i < 6; i++) {
graph.lineBetween(0, i * lineHeight, 100, i * lineHeight);
}
}

update(time) {
}
}

var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
scene: Demo
};

var game = new Phaser.Game(config);
5 changes: 3 additions & 2 deletions examples/ui-textarea/bitmaptext-snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ class Demo extends Phaser.Scene {
}

create() {
var lineHeight = 75
var textArea = this.rexUI.add.textArea({
x: 400,
y: 300,
width: 220,
height: 260,
height: lineHeight*6,

background: this.rexUI.add.roundRectangle(0, 0, 2, 2, 0, COLOR_MAIN),

Expand All @@ -32,7 +33,7 @@ class Demo extends Phaser.Scene {
track: this.rexUI.add.roundRectangle(0, 0, 20, 10, 10, COLOR_DARK),
thumb: this.rexUI.add.roundRectangle(0, 0, 0, 0, 13, COLOR_LIGHT),

gapLength: 75
gapLength: lineHeight
},

content: CreateContent(1000),
Expand Down

0 comments on commit d789285

Please sign in to comment.