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


Golang asset.Open函数代码示例

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


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

示例1: loadTextures

func loadTextures() []sprite.SubTex {
	a, err := asset.Open("cards.jpeg")
	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)
	}

	a2, err := asset.Open("dropTarget.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a2.Close()

	img2, _, err := image.Decode(a2)
	if err != nil {
		log.Fatal(err)
	}
	t2, err := eng.LoadTexture(img2)
	if err != nil {
		log.Fatal(err)
	}

	a3, err := asset.Open("deck.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a3.Close()

	img3, _, err := image.Decode(a3)
	if err != nil {
		log.Fatal(err)
	}
	t3, err := eng.LoadTexture(img3)
	if err != nil {
		log.Fatal(err)
	}

	return []sprite.SubTex{
		card1:      sprite.SubTex{t, image.Rect(15, 15, 190, 260)},
		card2:      sprite.SubTex{t, image.Rect(195, 60, 370, 305)},
		card3:      sprite.SubTex{t, image.Rect(375, 107, 550, 350)},
		card4:      sprite.SubTex{t, image.Rect(555, 135, 730, 377)},
		dropTarget: sprite.SubTex{t2, image.Rect(0, 0, 766, 620)},
		draw:       sprite.SubTex{t3, image.Rect(0, 0, 1506/2, 1052)},
		discard:    sprite.SubTex{t3, image.Rect(1506/2, 0, 1506, 1052)},
	}
}
开发者ID:vanadium,项目名称:croupier,代码行数:56,代码来源:main.go

示例2: MustOpen

func MustOpen(name string) asset.File {
	f, err := asset.Open(name)
	if err != nil {
		log.Fatal(err)
	}
	return f
}
开发者ID:dskinner,项目名称:material,代码行数:7,代码来源:gl.go

示例3: loadTexture

func loadTexture(glctx gl.Context) {
	a, err := asset.Open("key.jpeg")
	if err != nil {
		log.Fatal(err)
	}
	defer a.Close()

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

	rect := img.Bounds()
	rgba := image.NewRGBA(rect)
	draw.Draw(rgba, rect, img, rect.Min, draw.Src)
	tex := glctx.CreateTexture()

	glctx.ActiveTexture(gl.TEXTURE0)
	glctx.BindTexture(gl.TEXTURE_2D, tex)

	glctx.TexImage2D(gl.TEXTURE_2D, 0, 859, 610, gl.RGBA, gl.UNSIGNED_BYTE, rgba.Pix)

	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)

	glctx.ActiveTexture(gl.TEXTURE0)
	glctx.BindTexture(gl.TEXTURE_2D, tex)
	glctx.TexImage2D(
		gl.TEXTURE_2D, 0,
		rect.Max.X-rect.Min.X, rect.Max.Y-rect.Min.Y,
		gl.RGBA, gl.UNSIGNED_BYTE, rgba.Pix)
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:34,代码来源:main.go

示例4: loadTextures

func loadTextures() 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:eugenechertikhin,项目名称:gofun,代码行数:32,代码来源:main.go

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

示例6: loadAsset

func loadAsset(name string) ([]byte, error) {
	f, err := asset.Open(name)
	if err != nil {
		return nil, err
	}
	return ioutil.ReadAll(f)
}
开发者ID:lomoalbert,项目名称:gomobileapp,代码行数:7,代码来源:main.go

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

示例8: LoadTexture

func LoadTexture(name string) (tex gl.Texture, err error) {
	imgFile, err := asset.Open(name)
	if err != nil {
		return
	}
	img, _, err := image.Decode(imgFile)
	if err != nil {
		return
	}

	rgba := image.NewRGBA(img.Bounds())
	image_draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, image_draw.Src)

	tex = gl.CreateTexture()
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, tex)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	gl.TexImage2D(
		gl.TEXTURE_2D,
		0,
		rgba.Rect.Size().X,
		rgba.Rect.Size().Y,
		gl.RGBA,
		gl.UNSIGNED_BYTE,
		rgba.Pix)

	return
}
开发者ID:lomoalbert,项目名称:gomobileapp,代码行数:31,代码来源:main.go

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

示例10: Load

func Load(filename string) {

	file, _ := asset.Open(filename)

	scanner := bufio.NewReader(file)

	var maxSize int = 300000

	var fileData []byte = make([]byte, maxSize)

	size, _ := scanner.Read(fileData)

	fileData = fileData[:size]

	var buf bytes.Buffer = *bytes.NewBuffer(fileData)

	dec := gob.NewDecoder(&buf)

	err := dec.Decode(&dict)
	if err == nil {
		isLoaded = true
	}
	pos = make(map[int]int)
	end = make(map[int]bool)
	rewind()
}
开发者ID:roypur,项目名称:puntastic-lib,代码行数:26,代码来源:make.go

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

示例12: loadSprite

func loadSprite(fileName string) Sprite {
	a, err := asset.Open(fileName)
	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)
	}

	bounds := img.Bounds()

	imgWidth := bounds.Max.X - bounds.Min.X
	imgHeight := bounds.Max.Y - bounds.Min.Y
	log.Printf("sprite %v size: %vx%v\n", fileName, imgWidth, imgHeight)

	subTex := sprite.SubTex{t, image.Rect(0, 0, imgWidth, imgHeight)}

	return Sprite{
		SubTex: subTex,
		Width:  imgWidth,
		Height: imgHeight,
	}
}
开发者ID:porty,项目名称:experiments,代码行数:30,代码来源:game.go

示例13: onStart

func onStart() {
	rc, err := asset.Open("boing.wav")
	if err != nil {
		log.Fatal(err)
	}
	player, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:tendermint,项目名称:mobile,代码行数:10,代码来源:main.go

示例14: PlaySound

func PlaySound(name string) {
	println("Playing Sound: " + name)
	rc, err := asset.Open("sound/" + name + ".wav")
	if err != nil {
		panic(err)
	}
	soundsPlayer, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		panic(err)
	}
	soundsPlayer.Play()
	// player.Close()
}
开发者ID:pyros2097,项目名称:spike,代码行数:13,代码来源:asset.go

示例15: onStart

func onStart() {
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	rc, err := asset.Open("hello.wav")
	if err != nil {
		log.Fatal(err)
	}
	player, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:geraldstanje,项目名称:slides,代码行数:13,代码来源:main.go


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