GeoMDef
This commit is contained in:
parent
64d44d9caf
commit
92ed1f1a89
3 changed files with 24 additions and 4 deletions
|
@ -1,5 +1,11 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
// ID implements Identifier directly (as a string value).
|
||||
type ID string
|
||||
|
||||
|
@ -11,3 +17,16 @@ type ZPos float64
|
|||
|
||||
// Z returns z as a float64.
|
||||
func (z ZPos) Z() float64 { return float64(z) }
|
||||
|
||||
// GeoMDef is a serialisable form of GeoM.
|
||||
type GeoMDef [6]float64 // Assumption: this has identical memory layout to GeoM
|
||||
|
||||
// ToGeoMDef translates a GeoM to a GeoMDef using unsafe.Pointer.
|
||||
func ToGeoMDef(m *ebiten.GeoM) *GeoMDef {
|
||||
return (*GeoMDef)(unsafe.Pointer(m))
|
||||
}
|
||||
|
||||
// GeoM translates a GeoMDef to a GeoM using unsafe.Pointer.
|
||||
func (d *GeoMDef) GeoM() *ebiten.GeoM {
|
||||
return (*ebiten.GeoM)(unsafe.Pointer(d))
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ type Scene struct {
|
|||
Components []interface{}
|
||||
Hidden bool
|
||||
ID
|
||||
Transform ebiten.GeoM
|
||||
Transform GeoMDef
|
||||
ZPos
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,8 @@ func (s *Scene) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
|
|||
if s.Hidden {
|
||||
return
|
||||
}
|
||||
geom.Concat(s.Transform)
|
||||
geom.Concat(*s.Transform.GeoM())
|
||||
|
||||
for _, i := range s.Components {
|
||||
if d, ok := i.(Drawer); ok {
|
||||
d.Draw(screen, geom)
|
||||
|
|
|
@ -20,7 +20,7 @@ type Tilemap struct {
|
|||
Map [][]Tile
|
||||
Src ImageRef // must be a horizontal tile set
|
||||
TileSize int
|
||||
Transform ebiten.GeoM
|
||||
Transform GeoMDef
|
||||
ZPos
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ func (t *Tilemap) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
|
|||
if t.Hidden {
|
||||
return
|
||||
}
|
||||
geom.Concat(t.Transform)
|
||||
geom.Concat(*t.Transform.GeoM())
|
||||
for j, row := range t.Map {
|
||||
for i, tile := range row {
|
||||
var op ebiten.DrawImageOptions
|
||||
|
|
Loading…
Reference in a new issue