Esempio n. 1
0
func (e *WritableEngine) updateNode(n *sprite.Node) {
	if n.Arranger != nil {
		if _, ok := n.Arranger.(*arranger); !ok {
			n.Arranger = &arranger{e, n.Arranger}
		}
	}
	e.n[n].Parent = e.n[n.Parent]
	e.n[n].FirstChild = e.n[n.FirstChild]
	e.n[n].LastChild = e.n[n.LastChild]
	e.n[n].PrevSibling = e.n[n.PrevSibling]
	e.n[n].NextSibling = e.n[n.NextSibling]
}
Esempio n. 2
0
func loadScene() {
	texs := loadTextures()
	scene = &sprite.Node{}
	eng.Register(scene)
	eng.SetTransform(scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	var n *sprite.Node

	n = newNode()
	eng.SetSubTex(n, texs[texBooks])
	eng.SetTransform(n, f32.Affine{
		{36, 0, 0},
		{0, 36, 0},
	})

	n = newNode()
	eng.SetSubTex(n, texs[texFire])
	eng.SetTransform(n, f32.Affine{
		{72, 0, 144},
		{0, 72, 144},
	})

	n = newNode()
	n.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		// TODO: use a tweening library instead of manually arranging.
		t0 := uint32(t) % 120
		if t0 < 60 {
			eng.SetSubTex(n, texs[texGopherR])
		} else {
			eng.SetSubTex(n, texs[texGopherL])
		}

		u := float32(t0) / 120
		u = (1 - f32.Cos(u*2*math.Pi)) / 2

		tx := 18 + u*48
		ty := 36 + u*108
		sx := 36 + u*36
		sy := 36 + u*36
		eng.SetTransform(n, f32.Affine{
			{sx, 0, tx},
			{0, sy, ty},
		})
	})
}