mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-17 21:15:21 +01:00
Center title text with even spacing between words
This commit is contained in:
parent
fbecf256a2
commit
f10c0260c9
1 changed files with 16 additions and 12 deletions
|
@ -238,32 +238,36 @@ class TitleScreen @JvmOverloads constructor(
|
|||
// Remove tetrominos that fell off the screen
|
||||
tetrominos.removeAll(tetrominosToRemove)
|
||||
|
||||
// Draw title with "Mint" in mint color
|
||||
// Draw title with "mint" in mint color
|
||||
val titleY = height * 0.4f
|
||||
val fullTitle = "pixel mint drop"
|
||||
val pixelWidth = titlePaint.measureText("pixel ")
|
||||
|
||||
// Measure each word without spaces
|
||||
val pixelWidth = titlePaint.measureText("pixel")
|
||||
val mintWidth = titlePaint.measureText("mint")
|
||||
val dropWidth = titlePaint.measureText(" drop")
|
||||
val dropWidth = titlePaint.measureText("drop")
|
||||
|
||||
// Calculate total width
|
||||
val totalWidth = pixelWidth + mintWidth + dropWidth
|
||||
// Define even space between words
|
||||
val wordSpacing = 40f // Consistent spacing between words
|
||||
|
||||
// Start position for "pixel"
|
||||
// Calculate total width including spacing
|
||||
val totalWidth = pixelWidth + mintWidth + dropWidth + (wordSpacing * 2)
|
||||
|
||||
// Start position for first word to center the entire title
|
||||
val startX = width / 2f - totalWidth / 2
|
||||
|
||||
// Draw "pixel" in theme color
|
||||
canvas.drawText("pixel ", startX, titleY, titlePaint)
|
||||
canvas.drawText("pixel", startX, titleY, titlePaint)
|
||||
|
||||
// Save the original color
|
||||
val originalColor = titlePaint.color
|
||||
|
||||
// Draw "mint" in mint color (#3EB489)
|
||||
// Draw "mint" in mint color (#3EB489) with consistent spacing
|
||||
titlePaint.color = Color.parseColor("#3EB489")
|
||||
canvas.drawText("mint", startX + pixelWidth, titleY, titlePaint)
|
||||
canvas.drawText("mint", startX + pixelWidth + wordSpacing, titleY, titlePaint)
|
||||
|
||||
// Restore the original color and draw "drop"
|
||||
// Restore the original color and draw "drop" with consistent spacing
|
||||
titlePaint.color = originalColor
|
||||
canvas.drawText(" drop", startX + pixelWidth + mintWidth, titleY, titlePaint)
|
||||
canvas.drawText("drop", startX + pixelWidth + mintWidth + (wordSpacing * 2), titleY, titlePaint)
|
||||
|
||||
// Draw high scores using pre-allocated manager
|
||||
val highScores: List<HighScore> = highScoreManager.getHighScores()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue