当前位置: 首页>>代码示例>>Golang>>正文


Golang Engine.Register方法代码示例

本文整理汇总了Golang中golang.org/x/mobile/exp/sprite.Engine.Register方法的典型用法代码示例。如果您正苦于以下问题:Golang Engine.Register方法的具体用法?Golang Engine.Register怎么用?Golang Engine.Register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在golang.org/x/mobile/exp/sprite.Engine的用法示例。


在下文中一共展示了Engine.Register方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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 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
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:26,代码来源:game.go

示例2: Scene

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
}
开发者ID:toohsk,项目名称:gomobile-study,代码行数:50,代码来源:game.go

示例3: loadScene

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
}
开发者ID:golang-samples,项目名称:gomobile,代码行数:22,代码来源:main.go

示例4: Scene

// 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},
//.........这里部分代码省略.........
开发者ID:viru,项目名称:berrybot,代码行数:101,代码来源:bbot.go

示例5: 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
}
开发者ID:tayamahotate,项目名称:game,代码行数:61,代码来源:game.go


注:本文中的golang.org/x/mobile/exp/sprite.Engine.Register方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。