本文整理匯總了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
}