back to previous way of doing camera
This commit is contained in:
parent
840847b25b
commit
8f495888d9
6 changed files with 13 additions and 32 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
var _ interface {
|
var _ interface {
|
||||||
Identifier
|
Identifier
|
||||||
Prepper
|
Prepper
|
||||||
|
Scanner
|
||||||
Transformer
|
Transformer
|
||||||
} = &Camera{}
|
} = &Camera{}
|
||||||
|
|
||||||
|
@ -18,11 +19,10 @@ func init() {
|
||||||
gob.Register(&Camera{})
|
gob.Register(&Camera{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera models a camera that is viewing a scene. (Camera is a child of the
|
// Camera models a camera that is viewing something.
|
||||||
// scene it is viewing, for various reasons.) Changes to the fields take effect
|
|
||||||
// immediately.
|
|
||||||
type Camera struct {
|
type Camera struct {
|
||||||
ID
|
ID
|
||||||
|
Child interface{}
|
||||||
|
|
||||||
// Camera controls
|
// Camera controls
|
||||||
Centre image.Point // world coordinates
|
Centre image.Point // world coordinates
|
||||||
|
@ -39,6 +39,9 @@ func (c *Camera) Prepare(game *Game) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan returns s.Child.
|
||||||
|
func (c *Camera) Scan() []interface{} { return []interface{}{c.Child} }
|
||||||
|
|
||||||
// Transform returns the camera transform.
|
// Transform returns the camera transform.
|
||||||
func (c *Camera) Transform() (opts ebiten.DrawImageOptions) {
|
func (c *Camera) Transform() (opts ebiten.DrawImageOptions) {
|
||||||
opts.GeoM.Translate(float2(c.Centre.Mul(-1)))
|
opts.GeoM.Translate(float2(c.Centre.Mul(-1)))
|
||||||
|
|
|
@ -146,7 +146,6 @@ type Scener interface {
|
||||||
Hider
|
Hider
|
||||||
Identifier
|
Identifier
|
||||||
Scanner
|
Scanner
|
||||||
Transformer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Saver components can be saved to disk.
|
// Saver components can be saved to disk.
|
||||||
|
|
|
@ -2,8 +2,6 @@ package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure Scene satisfies Scener.
|
// Ensure Scene satisfies Scener.
|
||||||
|
@ -17,7 +15,6 @@ func init() {
|
||||||
type Scene struct {
|
type Scene struct {
|
||||||
ID
|
ID
|
||||||
Bounds // world coordinates
|
Bounds // world coordinates
|
||||||
Camera *Camera // optional; applies a bunch of transforms to draw calls
|
|
||||||
Components []interface{}
|
Components []interface{}
|
||||||
Disabled
|
Disabled
|
||||||
Hidden
|
Hidden
|
||||||
|
@ -105,18 +102,5 @@ func (s *Scene) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Transform returns the camera transform
|
|
||||||
func (s *Scene) Transform() ebiten.DrawImageOptions {
|
|
||||||
if s.Camera == nil {
|
|
||||||
return ebiten.DrawImageOptions{}
|
|
||||||
}
|
|
||||||
return s.Camera.Transform()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan returns all immediate subcomponents (including the camera, if not nil).
|
// Scan returns all immediate subcomponents (including the camera, if not nil).
|
||||||
func (s *Scene) Scan() []interface{} {
|
func (s *Scene) Scan() []interface{} { return s.Components }
|
||||||
if s.Camera != nil {
|
|
||||||
return append(s.Components, s.Camera)
|
|
||||||
}
|
|
||||||
return s.Components
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"image"
|
"image"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure SceneRef satisfies interfaces.
|
// Ensure SceneRef satisfies interfaces.
|
||||||
|
@ -76,6 +74,3 @@ func (r SceneRef) Ident() string { return r.scene.Ident() }
|
||||||
|
|
||||||
// Scan returns the components in the scene.
|
// Scan returns the components in the scene.
|
||||||
func (r SceneRef) Scan() []interface{} { return r.scene.Scan() }
|
func (r SceneRef) Scan() []interface{} { return r.scene.Scan() }
|
||||||
|
|
||||||
// Transform returns the value of Transform from the scene.
|
|
||||||
func (r SceneRef) Transform() ebiten.DrawImageOptions { return r.scene.Transform() }
|
|
||||||
|
|
Binary file not shown.
10
main.go
10
main.go
|
@ -33,7 +33,7 @@ func main() {
|
||||||
ebiten.SetWindowTitle("TODO")
|
ebiten.SetWindowTitle("TODO")
|
||||||
|
|
||||||
// Change to true to rewrite level1.gobz
|
// Change to true to rewrite level1.gobz
|
||||||
if true && runtime.GOOS != "js" {
|
if false && runtime.GOOS != "js" {
|
||||||
writeLevel1()
|
writeLevel1()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,10 @@ func main() {
|
||||||
Root: &engine.Scene{
|
Root: &engine.Scene{
|
||||||
ID: "root",
|
ID: "root",
|
||||||
Components: []interface{}{
|
Components: []interface{}{
|
||||||
&engine.SceneRef{Path: "assets/level1.gobz"},
|
&engine.Camera{
|
||||||
|
ID: "game_camera",
|
||||||
|
Child: &engine.SceneRef{Path: "assets/level1.gobz"},
|
||||||
|
},
|
||||||
&engine.DebugToast{ID: "toast", Pos: image.Pt(0, 15)},
|
&engine.DebugToast{ID: "toast", Pos: image.Pt(0, 15)},
|
||||||
engine.PerfDisplay{},
|
engine.PerfDisplay{},
|
||||||
},
|
},
|
||||||
|
@ -107,9 +110,6 @@ func writeLevel1() {
|
||||||
level1 := &engine.Scene{
|
level1 := &engine.Scene{
|
||||||
ID: "level_1",
|
ID: "level_1",
|
||||||
Bounds: engine.Bounds(image.Rect(-32, -32, 320+32, 240+32)),
|
Bounds: engine.Bounds(image.Rect(-32, -32, 320+32, 240+32)),
|
||||||
Camera: &engine.Camera{
|
|
||||||
ID: "game_camera",
|
|
||||||
},
|
|
||||||
Components: []interface{}{
|
Components: []interface{}{
|
||||||
&engine.Fill{
|
&engine.Fill{
|
||||||
ID: "bg_fill",
|
ID: "bg_fill",
|
||||||
|
|
Loading…
Reference in a new issue