本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Texture.Query方法的典型用法代码示例。如果您正苦于以下问题:Golang Texture.Query方法的具体用法?Golang Texture.Query怎么用?Golang Texture.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/veandco/go-sdl2/sdl.Texture
的用法示例。
在下文中一共展示了Texture.Query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: draw_texture
func (t *Text) draw_texture(texture *sdl.Texture, x, y int32, center_x, center_y bool) {
_, _, t.w, t.h, _ = texture.Query()
if center_x {
x = int32(win_size/2 - t.w/2)
}
if center_y {
y = int32(win_size/2 - t.h/2)
}
dst = sdl.Rect{x, y, int32(t.w), int32(t.h)}
renderer.Copy(texture, &src, &dst)
}
示例2: GetSizeOfGraphic
// GetSizeOfGraphic returns the width and heigth of the Graphic, g.
// GetSizeOfGraphic returns two numbers of type int. The first numnber,
// marked as 'width', is the width of the Graphic, g, in pixels. The second number,
// marked as 'height' is the height of the Graphic, g, in pixels.
//
// GetSizeOfGraphic will panic if:
//
// 1. The Graphic, g, does not contain a Graphic type.
//
// 2. The toolbox has not been initialised.
func GetSizeOfGraphic(g Graphic) (width, height int) {
if !initialised {
// this stops execution here, so ne need for an else after the if
panic(notInitialisedMessage)
}
if g == nil {
panic(nilGraphicMessage)
}
var w, h int32
var err error
var t *sdl.Texture
t = g
_, _, w, h, err = t.Query()
if err != nil {
fmt.Print("Failed to query texture: ")
fmt.Println(err)
panic(err)
}
width = int(w)
height = int(h)
// return is implicit - using named return paramaters
return
}