Created
August 5, 2017 05:50
-
-
Save Noofbiz/aea29d23b8bc5b1f1375a6e7c960f22c to your computer and use it in GitHub Desktop.
Engo Font Issue test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image/color" | |
"log" | |
"engo.io/ecs" | |
"engo.io/engo" | |
"engo.io/engo/common" | |
) | |
var ( | |
osSemiB22pt *common.Font | |
robotoR22pt *common.Font | |
) | |
type MyLabel struct { | |
ecs.BasicEntity | |
common.RenderComponent | |
common.SpaceComponent | |
} | |
type DefaultScene struct{} | |
func (*DefaultScene) Preload() { | |
err := engo.Files.Load("Oswald-SemiBold.ttf", "Roboto-Regular.ttf") | |
if err != nil { | |
log.Println(err) | |
} | |
} | |
func (*DefaultScene) Setup(w *ecs.World) { | |
common.SetBackground(color.White) | |
w.AddSystem(&common.RenderSystem{}) | |
//Oswald-SemiBold font 22 pt Setup | |
osSemiB22pt = &common.Font{ | |
URL: "Oswald-SemiBold.ttf", | |
FG: color.Black, | |
Size: 22, | |
} | |
err := osSemiB22pt.CreatePreloaded() | |
if err != nil { | |
panic(err) | |
} | |
//Label | |
oswLabel := MyLabel{BasicEntity: ecs.NewBasic()} | |
oswLabel.RenderComponent.Drawable = common.Text{ | |
Font: osSemiB22pt, | |
Text: "Oswald", | |
} | |
oswLabel.Position.Set(50, 100) | |
// Add it to appropriate systems | |
for _, system := range w.Systems() { | |
switch sys := system.(type) { | |
case *common.RenderSystem: | |
sys.Add(&oswLabel.BasicEntity, &oswLabel.RenderComponent, &oswLabel.SpaceComponent) | |
} | |
} | |
//Oswald-SemiBold font 22 pt Setup | |
robotoR22pt = &common.Font{ | |
URL: "Roboto-Regular.ttf", | |
FG: color.Black, | |
Size: 22, | |
} | |
err = robotoR22pt.CreatePreloaded() | |
if err != nil { | |
panic(err) | |
} | |
//Label | |
robLabel := MyLabel{BasicEntity: ecs.NewBasic()} | |
robLabel.RenderComponent.Drawable = common.Text{ | |
Font: robotoR22pt, | |
Text: "Roboto", | |
} | |
robLabel.Position.Set(50, 200) | |
// Add it to appropriate systems | |
for _, system := range w.Systems() { | |
switch sys := system.(type) { | |
case *common.RenderSystem: | |
sys.Add(&robLabel.BasicEntity, &robLabel.RenderComponent, &robLabel.SpaceComponent) | |
} | |
} | |
} | |
func (*DefaultScene) Type() string { return "GameWorld" } | |
func main() { | |
opts := engo.RunOptions{ | |
Title: "Font Issue", | |
Width: 480, | |
Height: 320, | |
} | |
engo.Run(opts, &DefaultScene{}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment