// Setup is called before the main loop is started func (*DefaultScene) Setup(w *ecs.World) { engo.SetBackground(color.White) w.AddSystem(&engo.RenderSystem{}) // The most important line in this whole demo: w.AddSystem(engo.NewKeyboardScroller(scrollSpeed, engo.DefaultHorizontalAxis, engo.DefaultVerticalAxis)) // Create the background; this way we'll see when we actually scroll demoutils.NewBackground(w, worldWidth, worldHeight, color.RGBA{102, 153, 0, 255}, color.RGBA{102, 173, 0, 255}) }
func (*DefaultScene) Setup(w *ecs.World) { engo.SetBackground(color.White) w.AddSystem(&engo.MouseSystem{}) w.AddSystem(&engo.RenderSystem{}) w.AddSystem(&ControlSystem{}) // These are not required, but allow you to move / rotate and still see that it works w.AddSystem(&engo.MouseZoomer{-0.125}) w.AddSystem(engo.NewKeyboardScroller(500, engo.DefaultHorizontalAxis, engo.DefaultVerticalAxis)) w.AddSystem(&engo.MouseRotator{RotationSpeed: 0.125}) // Retrieve a texture texture := engo.Files.Image("icon.png") // Create an entity guy := Guy{BasicEntity: ecs.NewBasic()} // Initialize the components, set scale to 8x guy.RenderComponent = engo.RenderComponent{ Drawable: texture, Scale: engo.Point{8, 8}, } guy.SpaceComponent = engo.SpaceComponent{ Position: engo.Point{200, 200}, Width: texture.Width() * guy.RenderComponent.Scale.X, Height: texture.Height() * guy.RenderComponent.Scale.Y, Rotation: 90, } // guy.MouseComponent doesn't have to be set, because its default values will do // Add our guy to appropriate systems for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&guy.BasicEntity, &guy.RenderComponent, &guy.SpaceComponent) case *engo.MouseSystem: sys.Add(&guy.BasicEntity, &guy.MouseComponent, &guy.SpaceComponent, &guy.RenderComponent) case *ControlSystem: sys.Add(&guy.BasicEntity, &guy.MouseComponent) } } }
// Setup is called before the main loop is started func (*DefaultScene) Setup(w *ecs.World) { engo.SetBackground(color.White) w.AddSystem(&engo.RenderSystem{}) // Adding KeyboardScroller so we can actually see the difference between background and HUD when scrolling w.AddSystem(engo.NewKeyboardScroller(scrollSpeed, engo.DefaultHorizontalAxis, engo.DefaultVerticalAxis)) w.AddSystem(&engo.MouseZoomer{zoomSpeed}) // Create background, so we can see difference between this and HUD demoutils.NewBackground(w, worldWidth, worldHeight, color.RGBA{102, 153, 0, 255}, color.RGBA{102, 173, 0, 255}) // Define parameters for the hud hudWidth := 200 // Can be anything you want hudHeight := int(engo.WindowHeight()) // Can be anything you want // Generate something that uses the PriorityLevel HUDGround or up. We're giving the same color twice, // so it'll create one solid color. hudBg := demoutils.NewBackground(w, hudWidth, hudHeight, color.RGBA{255, 0, 255, 180}, color.RGBA{255, 0, 255, 180}) // These adjustments are needed to transform it into a HUD: hudBg.RenderComponent.SetZIndex(1) // something bigger than default (0), so it'll be on top of the regular background hudBg.RenderComponent.SetShader(engo.HUDShader) }
// Setup is called before the main loop is started func (*DefaultScene) Setup(w *ecs.World) { engo.SetBackground(color.RGBA{55, 55, 55, 255}) w.AddSystem(&engo.RenderSystem{}) // Adding camera controllers so we can verify it doesn't break when we move w.AddSystem(engo.NewKeyboardScroller(scrollSpeed, engo.DefaultHorizontalAxis, engo.DefaultVerticalAxis)) w.AddSystem(&engo.MouseZoomer{zoomSpeed}) w.AddSystem(&engo.MouseRotator{RotationSpeed: 0.125}) triangle1 := MyShape{BasicEntity: ecs.NewBasic()} triangle1.SpaceComponent = engo.SpaceComponent{Width: 100, Height: 100} triangle1.RenderComponent = engo.RenderComponent{Drawable: engo.Triangle{}, Color: color.RGBA{255, 0, 0, 255}} triangle1.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&triangle1.BasicEntity, &triangle1.RenderComponent, &triangle1.SpaceComponent) } } rectangle1 := MyShape{BasicEntity: ecs.NewBasic()} rectangle1.SpaceComponent = engo.SpaceComponent{Position: engo.Point{100, 100}, Width: 100, Height: 100} rectangle1.RenderComponent = engo.RenderComponent{Drawable: engo.Rectangle{}, Color: color.RGBA{0, 255, 0, 255}} rectangle1.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&rectangle1.BasicEntity, &rectangle1.RenderComponent, &rectangle1.SpaceComponent) } } circle1 := MyShape{BasicEntity: ecs.NewBasic()} circle1.SpaceComponent = engo.SpaceComponent{Position: engo.Point{200, 200}, Width: 100, Height: 100} circle1.RenderComponent = engo.RenderComponent{Drawable: engo.Circle{}, Color: color.RGBA{0, 0, 255, 255}} circle1.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&circle1.BasicEntity, &circle1.RenderComponent, &circle1.SpaceComponent) } } triangle2 := MyShape{BasicEntity: ecs.NewBasic()} triangle2.SpaceComponent = engo.SpaceComponent{Position: engo.Point{300, 300}, Width: 100, Height: 100} triangle2.RenderComponent = engo.RenderComponent{Drawable: engo.Triangle{TriangleType: engo.TriangleRight}, Color: color.RGBA{255, 255, 0, 255}} triangle2.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&triangle2.BasicEntity, &triangle2.RenderComponent, &triangle2.SpaceComponent) } } line1 := MyShape{BasicEntity: ecs.NewBasic()} line1.SpaceComponent = engo.SpaceComponent{Position: engo.Point{400, 400}, Width: 1, Height: 100} line1.RenderComponent = engo.RenderComponent{Drawable: engo.Rectangle{}, Color: color.RGBA{0, 255, 255, 255}} line1.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&line1.BasicEntity, &line1.RenderComponent, &line1.SpaceComponent) } } complexTriangle1 := MyShape{BasicEntity: ecs.NewBasic()} complexTriangle1.SpaceComponent = engo.SpaceComponent{Position: engo.Point{500, 500}, Width: 100, Height: 100} complexTriangle1.RenderComponent = engo.RenderComponent{Drawable: engo.ComplexTriangles{ Points: []engo.Point{ {0.0, 0.0}, {1.0, 0.25}, {0.5, 0.5}, {0.5, 0.5}, {1.0, 0.75}, {0.0, 1.0}, {0.0, 0.0}, {0.5, 0.50}, {0.0, 1.0}, }}, Color: color.RGBA{255, 0, 255, 255}} complexTriangle1.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&complexTriangle1.BasicEntity, &complexTriangle1.RenderComponent, &complexTriangle1.SpaceComponent) } } triangle3 := MyShape{BasicEntity: ecs.NewBasic()} triangle3.SpaceComponent = engo.SpaceComponent{Position: engo.Point{23, 123}, Width: 50, Height: 50} triangle3.RenderComponent = engo.RenderComponent{Drawable: engo.Triangle{BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{255, 0, 0, 255}} triangle3.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&triangle3.BasicEntity, &triangle3.RenderComponent, &triangle3.SpaceComponent) } } rectangle2 := MyShape{BasicEntity: ecs.NewBasic()} rectangle2.SpaceComponent = engo.SpaceComponent{Position: engo.Point{123, 223}, Width: 50, Height: 50} rectangle2.RenderComponent = engo.RenderComponent{Drawable: engo.Rectangle{BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{0, 255, 0, 255}} rectangle2.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&rectangle2.BasicEntity, &rectangle2.RenderComponent, &rectangle2.SpaceComponent) } } circle2 := MyShape{BasicEntity: ecs.NewBasic()} circle2.SpaceComponent = engo.SpaceComponent{Position: engo.Point{223, 323}, Width: 50, Height: 50} circle2.RenderComponent = engo.RenderComponent{Drawable: engo.Circle{BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{0, 0, 255, 255}} circle2.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&circle2.BasicEntity, &circle2.RenderComponent, &circle2.SpaceComponent) } } triangle4 := MyShape{BasicEntity: ecs.NewBasic()} triangle4.SpaceComponent = engo.SpaceComponent{Position: engo.Point{323, 423}, Width: 50, Height: 50} triangle4.RenderComponent = engo.RenderComponent{Drawable: engo.Triangle{TriangleType: engo.TriangleRight, BorderWidth: 1, BorderColor: color.White}, Color: color.RGBA{255, 255, 0, 255}} triangle4.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&triangle4.BasicEntity, &triangle4.RenderComponent, &triangle4.SpaceComponent) } } complexTriangle2 := MyShape{BasicEntity: ecs.NewBasic()} complexTriangle2.SpaceComponent = engo.SpaceComponent{Position: engo.Point{523, 623}, Width: 50, Height: 50} complexTriangle2.RenderComponent = engo.RenderComponent{Drawable: engo.ComplexTriangles{ BorderWidth: 1, BorderColor: color.White, Points: []engo.Point{ {0.0, 0.0}, {1.0, 0.25}, {0.5, 0.5}, {0.5, 0.5}, {1.0, 0.75}, {0.0, 1.0}, {0.0, 0.0}, {0.5, 0.50}, {0.0, 1.0}, }}, Color: color.RGBA{255, 0, 255, 255}} complexTriangle2.RenderComponent.SetShader(engo.LegacyShader) for _, system := range w.Systems() { switch sys := system.(type) { case *engo.RenderSystem: sys.Add(&complexTriangle2.BasicEntity, &complexTriangle2.RenderComponent, &complexTriangle2.SpaceComponent) } } }