mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
examples/text: adjust the rendering position
text/v2's Draw uses the given position as the upper-left position of the bounds by default, while text (v1) uses the given position as the origin position. In order to approximate the same result of the original text version, adjust the Y values. Updates #2454
This commit is contained in:
parent
9735687d3e
commit
56faf34932
@ -96,7 +96,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
gray := color.RGBA{0x80, 0x80, 0x80, 0xff}
|
||||
|
||||
{
|
||||
const x, y = 20, 40
|
||||
const x, y = 20, 20
|
||||
w, h := text.Measure(sampleText, mplusNormalFace, mplusNormalFace.Metrics().Height)
|
||||
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
|
||||
op := &text.DrawOptions{}
|
||||
@ -105,7 +105,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
text.Draw(screen, sampleText, mplusNormalFace, op)
|
||||
}
|
||||
{
|
||||
const x, y = 20, 140
|
||||
const x, y = 20, 120
|
||||
w, h := text.Measure(sampleText, mplusBigFace, mplusBigFace.Metrics().Height)
|
||||
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
|
||||
op := &text.DrawOptions{}
|
||||
@ -114,7 +114,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
text.Draw(screen, sampleText, mplusBigFace, op)
|
||||
}
|
||||
{
|
||||
const x, y = 20, 240
|
||||
const x, y = 20, 220
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Rotate(math.Pi / 4)
|
||||
op.GeoM.Translate(x, y)
|
||||
@ -123,7 +123,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
text.Draw(screen, sampleText, mplusNormalFace, op)
|
||||
}
|
||||
{
|
||||
const x, y = 160, 240
|
||||
const x, y = 160, 220
|
||||
const lineHeight = 80
|
||||
w, h := text.Measure(sampleText, mplusBigFace, lineHeight)
|
||||
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
|
||||
@ -133,7 +133,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
text.Draw(screen, sampleText, mplusBigFace, op)
|
||||
}
|
||||
{
|
||||
const x, y = 240, 400
|
||||
const x, y = 240, 380
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
// g.glyphs is initialized by text.AppendGlyphs.
|
||||
// You can customize how to render each glyph.
|
||||
|
Loading…
Reference in New Issue
Block a user