Skip to content

Commit ad53279

Browse files
author
Marcel Kaufmann
committed
Text scale
1 parent afc975a commit ad53279

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

CatcherTutorial.pde

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Startscreen startscreen;
1414
Game game;
1515
Highscore highscore;
1616

17-
PFont font;
17+
PFont normalFont;
18+
PFont bigFont;
1819

1920
float playerPosX;
2021
float playerPosY;
@@ -34,9 +35,10 @@ void setup() {
3435
//scale = 3;
3536
//On Android
3637
scale = displayDensity;
37-
font = createFont("SansSerif", 60 * scale);
3838
textWidth = 22;
3939
textWidthBig = 100;
40+
normalFont = createFont("SansSerif", textWidth * scale);
41+
bigFont = createFont("SansSerif", textWidthBig * scale);
4042
gameWidth = width;
4143
gameHeight = height;
4244
startscreen = new Startscreen();

Highscore.pde

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class Highscore{
3838
}else{
3939
shape(restartButton, gameWidth/2, gameHeight-(gameHeight/5));
4040
textAlign(CENTER);
41-
textFont(font, textWidth * scale);
41+
textFont(normalFont);
4242
fill(50);
4343
text(restart, gameWidth/2, gameHeight-(gameHeight/5)+(textAscent()/2));
44-
textFont(font, textWidthBig * scale);
44+
textFont(bigFont);
4545
fill(yellow);
4646
text(score, gameWidth/2, gameHeight/2);
4747
}

Startscreen.pde

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class Startscreen{
1313
float buttonXRight;
1414
float buttonYTop;
1515
float buttonYBottom;
16-
16+
1717
public Startscreen( ) {
1818
rectMode(CENTER);
1919
init();
2020
}
2121

2222
void init( ) {
23-
textFont(font, textWidth * scale);
23+
textFont(normalFont);
2424
start = "START";
2525
startButtonWidth = textWidth(start)*3;
2626
startButtonHeight = textAscent()*3.5;

StatsPrinter.pde

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ Helper class printing the current game state on screen
44
*/
55
class StatsPrinter {
66

7+
float dynamicTextHeight;
78
float offset;
89
String scoreText;
910
String livesText;
10-
11-
public StatsPrinter(){
12-
textFont(font, textWidth * scale);
13-
offset = textAscent();
11+
12+
public StatsPrinter() {
13+
textFont(normalFont);
14+
dynamicTextHeight = textAscent();
15+
offset = 5 * scale;
1416
}
15-
17+
1618
void print(int lives, int score) {
1719
scoreText= "Score: "+score;
1820
livesText = "Lives: "+lives;
1921
fill(255);
2022
textAlign(LEFT);
21-
text(scoreText, 0+offset, textWidth+offset);
23+
text(scoreText, offset, dynamicTextHeight+offset);
2224
textAlign(RIGHT);
23-
text(livesText, gameWidth-offset, textWidth+offset);
25+
text(livesText, gameWidth - offset, dynamicTextHeight+offset);
2426
}
2527
}

0 commit comments

Comments
 (0)