(u engo.Updater)
| 28 | } |
| 29 | |
| 30 | func (*DefaultScene) Setup(u engo.Updater) { |
| 31 | w, _ := u.(*ecs.World) |
| 32 | |
| 33 | common.SetBackground(color.White) |
| 34 | |
| 35 | w.AddSystem(&common.RenderSystem{}) |
| 36 | w.AddSystem(&ScaleSystem{}) |
| 37 | |
| 38 | // Retrieve a texture |
| 39 | texture, err := common.LoadedSprite("icon.png") |
| 40 | if err != nil { |
| 41 | log.Println(err) |
| 42 | } |
| 43 | |
| 44 | // Create an entity |
| 45 | guy := Guy{BasicEntity: ecs.NewBasic()} |
| 46 | |
| 47 | // Initialize the components, set scale to 8x |
| 48 | guy.RenderComponent = common.RenderComponent{ |
| 49 | Drawable: texture, |
| 50 | Scale: engo.Point{8, 8}, |
| 51 | } |
| 52 | guy.SpaceComponent = common.SpaceComponent{ |
| 53 | Position: engo.Point{0, 0}, |
| 54 | Width: texture.Width() * guy.RenderComponent.Scale.X, |
| 55 | Height: texture.Height() * guy.RenderComponent.Scale.Y, |
| 56 | } |
| 57 | |
| 58 | // Add it to appropriate systems |
| 59 | for _, system := range w.Systems() { |
| 60 | switch sys := system.(type) { |
| 61 | case *common.RenderSystem: |
| 62 | sys.Add(&guy.BasicEntity, &guy.RenderComponent, &guy.SpaceComponent) |
| 63 | case *ScaleSystem: |
| 64 | sys.Add(&guy.BasicEntity, &guy.RenderComponent) |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func (*DefaultScene) Type() string { return "GameWorld" } |
| 70 |
nothing calls this directly
no test coverage detected