MCPcopy
hub / github.com/EngoEngine/engo / Setup

Method Setup

demos/scale/scale.go:30–67  ·  view source on GitHub ↗
(u engo.Updater)

Source from the content-addressed store, hash-verified

28}
29
30func (*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
69func (*DefaultScene) Type() string { return "GameWorld" }
70

Callers

nothing calls this directly

Calls 5

SetBackgroundFunction · 0.92
LoadedSpriteFunction · 0.92
WidthMethod · 0.65
HeightMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected