From 6cd2b8186cd5f7614f76c91cb237d34c9a048ee1 Mon Sep 17 00:00:00 2001 From: dbenavid Date: Tue, 5 Sep 2023 07:54:59 -0400 Subject: [PATCH] Managed to incorporate a frame based position offset which is cyclic for moving objects, called in function RepositionTest() --- examples/splashmenu/scenes/parallax.go | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/examples/splashmenu/scenes/parallax.go b/examples/splashmenu/scenes/parallax.go index 4c89761..fab5406 100644 --- a/examples/splashmenu/scenes/parallax.go +++ b/examples/splashmenu/scenes/parallax.go @@ -10,6 +10,7 @@ import ( "math/rand" "github.com/hajimehoshi/ebiten/v2" + "github.com/hajimehoshi/ebiten/v2/inpututil" "github.com/hajimehoshi/ebiten/v2/vector" _ "embed" @@ -104,6 +105,17 @@ func NewParallax() Parallax { func (p *Parallax) Update() error { p.increment++ + + var keysPressed []ebiten.Key + keysPressed = inpututil.AppendJustPressedKeys(keysPressed[:0]) + + //check for user input to transition scene + if inpututil.IsKeyJustPressed(ebiten.KeyQ) { + if p.events[groovy.COMPLETED] != nil { + p.events[groovy.COMPLETED]() + } + } + return nil } @@ -251,4 +263,27 @@ func (p *Parallax) RepositionTest(screen *ebiten.Image) { vs[i].ColorA = 1 } screen.DrawTriangles(vs, is, whiteSubImage, nil) + + //minX := x0 - xd + maxX := x0 + xd + //minY := y0 - yd + //maxY := y0 + yd + //178x229 + + roX := float64(178 / 4) + roY := float64(229 / 4) + startX := float64(maxX) + roX + startY := float64(y0) + roY/2 + + adjustment := 400.0 + currentX := startX - float64(p.increment) + adjustment*math.Floor(float64(p.increment)/adjustment) + + op := &ebiten.DrawImageOptions{} + op.GeoM.Scale(.5, .5) + op.GeoM.Translate(-roX, -roY) + op.GeoM.Rotate(-float64(p.increment) / (math.Pi * 12.0)) + op.GeoM.Translate(currentX, startY) + + screen.DrawImage(roids[1], op) + }