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


Golang sprite.Engine类代码示例

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


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

示例1: loadTextures

func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("placeholder-sprites.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close() // 処理が終わったらCloseする

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}

	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	return []sprite.SubTex{
		texGopher: sprite.SubTex{t, image.Rect(1+0, 0, n-1, n)},     //splite画像の一番左の青色のテクスチャを切り出す
		texGround: sprite.SubTex{t, image.Rect(1+n*2, 0, n*3-1, n)}, //splite画像の左からn-1番目のテクスチャを切り出す
		texEarth:  sprite.SubTex{t, image.Rect(1+n*5, 0, n*6-1, n)}, //splite画像の左からn-1番目のテクスチャを切り出す
	}

}
开发者ID:toohsk,项目名称:gomobile-study,代码行数:25,代码来源:game.go

示例2: 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

示例3: loadTextures

func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("sprite.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	return []sprite.SubTex{
		texGopherRun1:  sprite.SubTex{t, image.Rect(n*0, 0, n*1, n)},
		texGopherRun2:  sprite.SubTex{t, image.Rect(n*1, 0, n*2, n)},
		texGopherFlap1: sprite.SubTex{t, image.Rect(n*2, 0, n*3, n)},
		texGopherFlap2: sprite.SubTex{t, image.Rect(n*3, 0, n*4, n)},
		texGopherDead1: sprite.SubTex{t, image.Rect(n*4, 0, n*5, n)},
		texGopherDead2: sprite.SubTex{t, image.Rect(n*5, 0, n*6-1, n)},
		texGround1:     sprite.SubTex{t, image.Rect(n*6+1, 0, n*7-1, n)},
		texGround2:     sprite.SubTex{t, image.Rect(n*7+1, 0, n*8-1, n)},
		texGround3:     sprite.SubTex{t, image.Rect(n*8+1, 0, n*9-1, n)},
		texGround4:     sprite.SubTex{t, image.Rect(n*9+1, 0, n*10-1, n)},
		texEarth:       sprite.SubTex{t, image.Rect(n*10+1, 0, n*11-1, n)},
	}
}
开发者ID:tayamahotate,项目名称:game,代码行数:31,代码来源:game.go

示例4: newTextTexture

func (l *Label) newTextTexture(eng sprite.Engine) sprite.SubTex {

	fg, bg := image.Black, image.White
	draw.Draw(l.rgba, l.rgba.Bounds(), bg, image.ZP, draw.Src)
	d := &sfont.Drawer{
		Dst: l.rgba,
		Src: fg,
		Face: truetype.NewFace(l.font, truetype.Options{
			Size:    l.fontSize,
			DPI:     72,
			Hinting: sfont.HintingFull,
		}),
	}

	spacing := 1.5
	dy := int(math.Ceil(l.fontSize * spacing))
	for i, s := range strings.Split(l.Text, "\n") {
		d.Dot = fixed.P(0, int(l.fontSize*0.8)+dy*i)
		d.DrawString(s)
	}

	t, err := eng.LoadTexture(l.rgba)
	if err != nil {
		log.Fatal(err)
	}

	return sprite.SubTex{t, l.rgba.Bounds()}
}
开发者ID:tenntenn,项目名称:gomoxy,代码行数:28,代码来源:label.go

示例5: loadTextures

func loadTextures(eng sprite.Engine) map[string]sprite.SubTex {
	a, err := asset.Open("tx_letters.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	img, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(img)
	if err != nil {
		log.Fatal(err)
	}

	return map[string]sprite.SubTex{
		":":     sprite.SubTex{t, image.Rect(0, 0, 200, 200)},
		"0":     sprite.SubTex{t, image.Rect(200, 0, 400, 200)},
		"1":     sprite.SubTex{t, image.Rect(400, 0, 600, 200)},
		"2":     sprite.SubTex{t, image.Rect(0, 200, 200, 400)},
		"3":     sprite.SubTex{t, image.Rect(200, 200, 400, 400)},
		"4":     sprite.SubTex{t, image.Rect(400, 200, 600, 400)},
		"5":     sprite.SubTex{t, image.Rect(0, 400, 200, 600)},
		"6":     sprite.SubTex{t, image.Rect(200, 400, 400, 600)},
		"7":     sprite.SubTex{t, image.Rect(400, 400, 600, 600)},
		"8":     sprite.SubTex{t, image.Rect(0, 600, 200, 800)},
		"9":     sprite.SubTex{t, image.Rect(200, 600, 400, 800)},
		"GO":    sprite.SubTex{t, image.Rect(0, 800, 600, 1000)},
		"gooon": sprite.SubTex{t, image.Rect(0, 1000, 600, 1200)},
	}
}
开发者ID:golang-samples,项目名称:gomobile,代码行数:32,代码来源:main.go

示例6: loadTextures

func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("sprite.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	// The +1's and -1's in the rectangles below are to prevent colors from
	// adjacent textures leaking into a given texture.
	// See: http://stackoverflow.com/questions/19611745/opengl-black-lines-in-between-tiles
	return []sprite.SubTex{
		texGopherRun1:  sprite.SubTex{t, image.Rect(n*0+1, 0, n*1-1, n)},
		texGopherRun2:  sprite.SubTex{t, image.Rect(n*1+1, 0, n*2-1, n)},
		texGopherFlap1: sprite.SubTex{t, image.Rect(n*2+1, 0, n*3-1, n)},
		texGopherFlap2: sprite.SubTex{t, image.Rect(n*3+1, 0, n*4-1, n)},
		texGopherDead1: sprite.SubTex{t, image.Rect(n*4+1, 0, n*5-1, n)},
		texGopherDead2: sprite.SubTex{t, image.Rect(n*5+1, 0, n*6-1, n)},
		texGround1:     sprite.SubTex{t, image.Rect(n*6+1, 0, n*7-1, n)},
		texGround2:     sprite.SubTex{t, image.Rect(n*7+1, 0, n*8-1, n)},
		texGround3:     sprite.SubTex{t, image.Rect(n*8+1, 0, n*9-1, n)},
		texGround4:     sprite.SubTex{t, image.Rect(n*9+1, 0, n*10-1, n)},
		texEarth:       sprite.SubTex{t, image.Rect(n*10+1, 0, n*11-1, n)},
	}
}
开发者ID:2722,项目名称:lantern,代码行数:34,代码来源:game.go

示例7: Arrange

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
}
开发者ID:mccordnate,项目名称:gogam,代码行数:27,代码来源:engine.go

示例8: loadTextures

func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("assets.png")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}
	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	const n = 128
	// The +1's and -1's in the rectangles below are to prevent colors from
	// adjacent textures leaking into a given texture.
	// See: http://stackoverflow.com/questions/19611745/opengl-black-lines-in-between-tiles
	return []sprite.SubTex{
		texCtrl:         {T: t, R: image.Rect(0, 0, 320, 320)},
		texStick:        {T: t, R: image.Rect(320, 0, 440, 120)},
		texBot:          {T: t, R: image.Rect(0, 320, 300, 610)},
		texProxSmGrey:   {T: t, R: image.Rect(300, 320, 300+50, 320+15)},
		texProxSmGreen:  {T: t, R: image.Rect(300, 320+15, 300+50, 320+30)},
		texProxSmOrange: {T: t, R: image.Rect(300, 320+30, 300+50, 320+45)},
		texProxSmRed:    {T: t, R: image.Rect(300, 320+45, 300+50, 320+60)},
		texProxMdGrey:   {T: t, R: image.Rect(300, 320+60, 300+78, 320+80)},
		texProxMdOrange: {T: t, R: image.Rect(300, 320+80, 300+78, 320+100)},
		texProxMdRed:    {T: t, R: image.Rect(300, 320+100, 300+78, 320+120)},
		texProxLgGrey:   {T: t, R: image.Rect(300, 320+120, 300+110, 320+147)},
		texProxLgRed:    {T: t, R: image.Rect(300, 320+147, 300+110, 320+174)},
	}
}
开发者ID:viru,项目名称:berrybot,代码行数:35,代码来源:bbot.go

示例9: Move

// Moves s to a new position and size
func (s *StaticImg) Move(newXY, newDimensions *coords.Vec, eng sprite.Engine) {
	eng.SetTransform(s.node, f32.Affine{
		{newDimensions.X, 0, newXY.X},
		{0, newDimensions.Y, newXY.Y},
	})
	s.current = newXY
	s.dimensions = newDimensions
}
开发者ID:vanadium,项目名称:croupier,代码行数:9,代码来源:staticimg.go

示例10: Move

// Moves c to a new position and size
func (c *Card) Move(newXY, newDimensions *coords.Vec, eng sprite.Engine) {
	eng.SetTransform(c.node, f32.Affine{
		{newDimensions.X, 0, newXY.X},
		{0, newDimensions.Y, newXY.Y},
	})
	c.current = newXY
	c.dimensions = newDimensions
}
开发者ID:vanadium,项目名称:croupier,代码行数:9,代码来源:card.go

示例11: Move

func (c *Card) Move(eng sprite.Engine, newX float32, newY float32) {
	eng.SetTransform(c.node, f32.Affine{
		{c.width, 0, newX},
		{0, c.height, newY},
	})
	c.x = newX
	c.y = newY
}
开发者ID:vanadium,项目名称:croupier,代码行数:8,代码来源:card.go

示例12: Create

func (t *TextTexture) Create(eng sprite.Engine, text string) (sprite.SubTex, error) {
	draw.Draw(t.rgba, t.rgba.Bounds(), t.bg, image.ZP, draw.Src)
	d := &sfont.Drawer{
		Dst:  t.rgba,
		Src:  t.fg,
		Face: t.Face,
	}

	dy := int(math.Ceil(t.Face.Size * t.Spacing))
	for i, s := range strings.Split(text, "\n") {
		d.Dot = fixed.P(0, int(t.Face.Size*0.8)+dy*i)
		d.DrawString(s)
	}

	tex, err := eng.LoadTexture(t.rgba)
	if err != nil {
		return sprite.SubTex{}, err
	}

	return sprite.SubTex{tex, t.rgba.Bounds()}, nil
}
开发者ID:tenntenn,项目名称:gomui,代码行数:21,代码来源:text.go

示例13: 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

示例14: loadTextures

func loadTextures(eng sprite.Engine) []sprite.SubTex {
	a, err := asset.Open("koha1.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

	m, _, err := image.Decode(a)
	if err != nil {
		log.Fatal(err)
	}

	t, err := eng.LoadTexture(m)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("%#v", m.Bounds())

	x, y := t.Bounds()
	return []sprite.SubTex{
		texGopher: sprite.SubTex{t, image.Rect(0, 0, x, y)},
	}
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:24,代码来源:game.go

示例15: 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


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