示例#1
0
func (sprite *Sprite) SetTexture(tex *gfx.Texture) {
	var tw, th float64

	sprite.Quad.Texture = tex

	if tex != nil {
		tw = float64(tex.Width())
		th = float64(tex.Height())
	} else {
		tw, th = 1.0, 1.0
	}

	if tw != sprite.TexW || th != sprite.TexH {
		tx1 := float64(sprite.Quad.V[0].TX) * sprite.TexW
		ty1 := float64(sprite.Quad.V[0].TY) * sprite.TexH
		tx2 := float64(sprite.Quad.V[2].TX) * sprite.TexW
		ty2 := float64(sprite.Quad.V[2].TY) * sprite.TexH

		sprite.TexW, sprite.TexH = tw, th

		tx1 /= tw
		ty1 /= th
		tx2 /= tw
		ty2 /= th

		sprite.Quad.V[0].TX, sprite.Quad.V[0].TY = float32(tx1), float32(ty1)
		sprite.Quad.V[1].TX, sprite.Quad.V[1].TY = float32(tx2), float32(ty1)
		sprite.Quad.V[2].TX, sprite.Quad.V[2].TY = float32(tx2), float32(ty2)
		sprite.Quad.V[3].TX, sprite.Quad.V[3].TY = float32(tx1), float32(ty2)
	}
}
示例#2
0
func New(tex *gfx.Texture, frames int, fps, x, y, w, h float64) Animation {
	var a Animation

	a.Sprite = sprite.New(tex, x, y, w, h)

	a.origWidth = tex.Width(true)

	a.sinceLastFrame = -1.0
	a.speed = 1.0 / fps
	a.frames = frames

	a.mode = FWD | LOOP
	a.delta = 1
	a.SetFrame(0)

	return a
}
示例#3
0
func New(texture *gfx.Texture, texx, texy, w, h float64) Sprite {
	var sprite Sprite

	sprite.TX, sprite.TY = texx, texy
	sprite.W, sprite.H = w, h

	if texture != nil {
		sprite.TexW = float64(texture.Width())
		sprite.TexH = float64(texture.Height())
	} else {
		sprite.TexW = 1.0
		sprite.TexH = 1.0
	}

	sprite.Quad.Texture = texture

	texx1 := texx / sprite.TexW
	texy1 := texy / sprite.TexH
	texx2 := (texx + w) / sprite.TexW
	texy2 := (texy + h) / sprite.TexH

	sprite.Quad.V[0].TX, sprite.Quad.V[0].TY = float32(texx1), float32(texy1)
	sprite.Quad.V[1].TX, sprite.Quad.V[1].TY = float32(texx2), float32(texy1)
	sprite.Quad.V[2].TX, sprite.Quad.V[2].TY = float32(texx2), float32(texy2)
	sprite.Quad.V[3].TX, sprite.Quad.V[3].TY = float32(texx1), float32(texy2)

	sprite.Quad.V[0].Z = 0.5
	sprite.Quad.V[1].Z = 0.5
	sprite.Quad.V[2].Z = 0.5
	sprite.Quad.V[3].Z = 0.5

	sprite.Quad.V[0].Color = 0xffffffff
	sprite.Quad.V[1].Color = 0xffffffff
	sprite.Quad.V[2].Color = 0xffffffff
	sprite.Quad.V[3].Color = 0xffffffff

	sprite.Quad.Blend = gfx.BLEND_DEFAULT

	return sprite
}
示例#4
0
func (a *Animation) SetTexture(tex *gfx.Texture) {
	a.Sprite.SetTexture(tex)
	a.origWidth = tex.Width(true)
}
示例#5
0
func (h *HGE) Texture_Unlock(tex gfx.Texture) {
	tex.Unlock()
}
示例#6
0
func (h *HGE) Texture_Lock(tex gfx.Texture, a ...interface{}) *hge.Dword {
	return tex.Lock(a...)
}
示例#7
0
func (h *HGE) Texture_GetHeight(tex gfx.Texture, a ...interface{}) int {
	return tex.Height(a...)
}
示例#8
0
func (h *HGE) Texture_GetWidth(tex gfx.Texture, a ...interface{}) int {
	return tex.Width(a...)
}
示例#9
0
func (h *HGE) Texture_Free(tex *gfx.Texture) {
	tex.Free()
}