func (a *arrangerFunc) Arrange(e s.Engine, n *s.Node, t clock.Time) { sprite, _ := a.eng.sprites[n] frameTime := float32(t - a.eng.lastUpdate) updatePosition(sprite, frameTime) screenWidthScaler, screenHeightScaler := a.eng.GetScreenScalers() actualScaleX := screenWidthScaler * sprite.ScaleX actualScaleY := screenHeightScaler * sprite.ScaleY actualPositionX := screenWidthScaler * sprite.X actualPositionY := screenHeightScaler * sprite.Y e.SetSubTex(n, *sprite.GetCurrentFrame().Texture) r := sprite.Rotation * math.Pi / 180 matrix := f32.Affine{ {1, 0, 0}, {0, 1, 0}, } matrix.Translate(&matrix, actualPositionX, actualPositionY) //matrix.Translate(&matrix, sprite.X, sprite.Y) matrix.Rotate(&matrix, r) matrix.Scale(&matrix, actualScaleX, actualScaleY) e.SetTransform(n, matrix) a.eng.lastUpdate = t }
func (g *Game) Scene(eng sprite.Engine) *sprite.Node { texs := loadTextures(eng) scene := &sprite.Node{} eng.Register(scene) eng.SetTransform(scene, f32.Affine{ {1, 0, 0}, {0, 1, 0}, }) newNode := func(fn arrangerFunc) { n := &sprite.Node{Arranger: arrangerFunc(fn)} eng.Register(n) scene.AppendChild(n) } // The gopher. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texGopher]) eng.SetTransform(n, f32.Affine{ {tileWidth, 0, 0}, {0, tileHeight, 0}, }) }) return scene }
func loadScene(eng sprite.Engine, ts map[string]sprite.SubTex) *sprite.Node { root := &sprite.Node{} eng.Register(root) eng.SetTransform(root, f32.Affine{ {1, 0, 0}, {0, 1, 0}, }) n := &sprite.Node{} eng.Register(n) root.AppendChild(n) eng.SetTransform(n, f32.Affine{ {200, 0, 0}, {0, 200, 0}, }) n.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { s := fmt.Sprintf("%02d", int(t)) eng.SetSubTex(n, ts[s[0:1]]) }) return root }
func (g *Game) Scene(eng sprite.Engine) *sprite.Node { texs := loadTextures(eng) scene = &sprite.Node{} // sceneのルートノードを生成 eng.Register(scene) // Engineオブジェクトにルートノードを登録 // ルートの初期位置やスケールを設定する eng.SetTransform(scene, f32.Affine{ {1, 0, 0}, {0, 1, 0}, }) newNode := func(fn arrangerFunc) { n := &sprite.Node{Arranger: arrangerFunc(fn)} eng.Register(n) scene.AppendChild(n) } // The ground. // 地面を描画するメソッド for i := range g.groundY { i := i // 地表の描画 newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texGround]) //texGroundのテクスチャを使う eng.SetTransform(n, f32.Affine{ {tileWidth, 0, float32(i)*tileWidth - g.scroll.x}, {0, tileHeight, g.groundY[i]}, //地面を描画する }) }) // 地中の描画 newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texEarth]) eng.SetTransform(n, f32.Affine{ {tileWidth, 0, float32(i) * tileWidth}, {0, tileHeight * tilesY, g.groundY[i] + tileHeight}, }) }) } // The gopher. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texGopher]) eng.SetTransform(n, f32.Affine{ {tileWidth, 0, tileWidth * gopherTile}, {0, tileHeight, g.gopher.y}, }) }) return scene }
// Shows the back of c func (c *Card) SetBackDisplay(eng sprite.Engine) { eng.SetSubTex(c.node, c.back) }
// Shows the front of c func (c *Card) SetFrontDisplay(eng sprite.Engine) { eng.SetSubTex(c.node, c.image) }
// Scene creates and returns a new app scene. func (a *App) Scene(eng sprite.Engine, sz size.Event) *sprite.Node { texs := loadTextures(eng) scene := &sprite.Node{} eng.Register(scene) eng.SetTransform(scene, f32.Affine{ {1, 0, 0}, {0, 1, 0}, }) newNode := func(fn arrangerFunc) { n := &sprite.Node{Arranger: arrangerFunc(fn)} eng.Register(n) scene.AppendChild(n) } // Controller boundaries. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texCtrl]) eng.SetTransform(n, f32.Affine{ {ctrlSize, 0, a.ctrl.x}, {0, ctrlSize, a.ctrl.y}, }) }) // Controller stick. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texStick]) eng.SetTransform(n, f32.Affine{ {ctrlStickSize, 0, a.stick.x}, {0, ctrlStickSize, a.stick.y}, }) }) // Bot. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texBot]) eng.SetTransform(n, f32.Affine{ {botSize, 0, a.bot.x}, {0, botSize, a.bot.y}, }) }) // Proximity small. const ( smSizeW = 15 smSizeH = 5 ) newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texProxSmGrey+a.bot.front.sm]) eng.SetTransform(n, f32.Affine{ {smSizeW, 0, a.bot.x + botSize/2 - smSizeW/2}, {0, smSizeH, a.bot.y - 2*smSizeH}, }) }) newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texProxSmGrey+a.bot.rear.sm]) eng.SetTransform(n, f32.Affine{ {smSizeW, 0, a.bot.x + botSize/2 - smSizeW/2}, {0, -smSizeH, a.bot.y + botSize + 2*smSizeH}, }) }) // Proximity medium. const ( mdSizeW = 25 mdSizeH = 7 ) newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texProxMdGrey+a.bot.front.md]) eng.SetTransform(n, f32.Affine{ {mdSizeW, 0, a.bot.x + botSize/2 - mdSizeW/2}, {0, mdSizeH, a.bot.y - 3*mdSizeH}, }) }) newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texProxMdGrey+a.bot.rear.md]) eng.SetTransform(n, f32.Affine{ {mdSizeW, 0, a.bot.x + botSize/2 - mdSizeW/2}, {0, -mdSizeH, a.bot.y + botSize + 3*mdSizeH}, }) }) // Proximity large const ( lgSizeW = 35 lgSizeH = 10 ) newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texProxLgGrey+a.bot.front.lg]) eng.SetTransform(n, f32.Affine{ {lgSizeW, 0, a.bot.x + botSize/2 - lgSizeW/2}, {0, lgSizeH, a.bot.y - 3.2*lgSizeH}, }) }) newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texProxLgGrey+a.bot.rear.lg]) eng.SetTransform(n, f32.Affine{ {lgSizeW, 0, a.bot.x + botSize/2 - lgSizeW/2}, {0, -lgSizeH, a.bot.y + botSize + 3.2*lgSizeH}, }) }) return scene }
func (g *Game) Scene(eng sprite.Engine) *sprite.Node { texs := loadTextures(eng) scene := &sprite.Node{} eng.Register(scene) eng.SetTransform(scene, f32.Affine{ {1, 0, 0}, {0, 1, 0}, }) newNode := func(fn arrangerFunc) { n := &sprite.Node{Arranger: arrangerFunc(fn)} eng.Register(n) scene.AppendChild(n) } // The ground. for i := range g.groundY { i := i // The top of the ground. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[g.groundTex[i]]) eng.SetTransform(n, f32.Affine{ {tileWidth, 0, float32(i)*tileWidth - g.scroll.x}, {0, tileHeight, g.groundY[i]}, }) }) // The earth beneath. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { eng.SetSubTex(n, texs[texEarth]) eng.SetTransform(n, f32.Affine{ {tileWidth, 0, float32(i)*tileWidth - g.scroll.x}, {0, tileHeight * tilesY, g.groundY[i] + tileHeight}, }) }) } // The gopher. newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { a := f32.Affine{ {tileWidth * 2, 0, tileWidth*(gopherTile-1) + tileWidth/8}, {0, tileHeight * 2, g.gopher.y - tileHeight + tileHeight/4}, } var x int switch { case g.gopher.dead: x = frame(t, 16, texGopherDead1, texGopherDead2) animateDeadGopher(&a, t-g.gopher.deadTime) case g.gopher.v < 0: x = frame(t, 4, texGopherFlap1, texGopherFlap2) case g.gopher.atRest: x = frame(t, 4, texGopherRun1, texGopherRun2) default: x = frame(t, 8, texGopherRun1, texGopherRun2) } eng.SetSubTex(n, texs[x]) eng.SetTransform(n, a) }) return scene }