New is called when FPSSystem is added to the world
(w *ecs.World)
| 27 | |
| 28 | // New is called when FPSSystem is added to the world |
| 29 | func (f *FPSSystem) New(w *ecs.World) { |
| 30 | if f.Display { |
| 31 | if f.Font == nil { |
| 32 | if err := engo.Files.LoadReaderData("gomonobold_fps.ttf", bytes.NewReader(gomonobold.TTF)); err != nil { |
| 33 | panic("unable to load gomonobold.ttf for the fps system! Error was: " + err.Error()) |
| 34 | } |
| 35 | |
| 36 | f.Font = &Font{ |
| 37 | URL: "gomonobold_fps.ttf", |
| 38 | FG: color.White, |
| 39 | BG: color.Black, |
| 40 | Size: 32, |
| 41 | } |
| 42 | |
| 43 | if err := f.Font.CreatePreloaded(); err != nil { |
| 44 | panic("unable to create gomonobold.ttf for the fps system! Error was: " + err.Error()) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | txt := Text{ |
| 49 | Font: f.Font, |
| 50 | Text: f.DisplayString(), |
| 51 | } |
| 52 | b := ecs.NewBasic() |
| 53 | f.entity.BasicEntity = &b |
| 54 | f.entity.RenderComponent = &RenderComponent{ |
| 55 | Drawable: txt, |
| 56 | } |
| 57 | f.entity.RenderComponent.SetShader(HUDShader) |
| 58 | f.entity.RenderComponent.SetZIndex(1000) |
| 59 | f.entity.SpaceComponent = &SpaceComponent{} |
| 60 | for _, system := range w.Systems() { |
| 61 | switch sys := system.(type) { |
| 62 | case *RenderSystem: |
| 63 | sys.Add(f.entity.BasicEntity, f.entity.RenderComponent, f.entity.SpaceComponent) |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Add doesn't do anything since New creates the only entity used |
| 70 | func (*FPSSystem) Add() {} |