apply isoprojection in Sprite

This commit is contained in:
Josh Deprez 2021-09-03 10:24:16 +10:00
parent 88ded18d50
commit 5699d70be6
2 changed files with 8 additions and 6 deletions

View file

@ -21,8 +21,8 @@ func init() {
// Sprite combines an Actor with the ability to Draw from a single spritesheet.
type Sprite struct {
Actor Actor
FrameOffset image.Point
Actor Actor
DrawOffset image.Point
Hidden
Sheet Sheet
@ -56,9 +56,11 @@ func (s *Sprite) SetAnim(a *Anim) {
s.anim = a
}
// Transform returns a translation by the FrameOffset.
// Transform returns a translation by the DrawOffset and the iso-projected Pos.
func (s *Sprite) Transform(pt Transform) (tf Transform) {
tf.Opts.GeoM.Translate(cfloat(s.Actor.Pos.XY().Add(s.FrameOffset)))
tf.Opts.GeoM.Translate(cfloat(
s.Actor.Pos.IsoProject(pt.IsoProjection).Add(s.DrawOffset),
))
return tf.Concat(pt)
}

View file

@ -197,10 +197,10 @@ func level1() *engine.Scene {
Sprite: engine.Sprite{
Actor: engine.Actor{
CollisionDomain: "level_1",
Pos: engine.Pt3(100, 100, 9),
Pos: engine.Pt3(100, 100, 0),
Size: engine.Pt3(8, 16, 8),
},
FrameOffset: image.Pt(-1, 0),
DrawOffset: image.Pt(-1, 0),
Sheet: engine.Sheet{
AnimDefs: map[string]*engine.AnimDef{
"idle_left": {Steps: []engine.AnimStep{