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


Golang sdl.Rect类代码示例

本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Rect的典型用法代码示例。如果您正苦于以下问题:Golang Rect类的具体用法?Golang Rect怎么用?Golang Rect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CreateMenus

func CreateMenus(window *sdl.Window, surface *sdl.Surface, renderer *sdl.Renderer, controlManager *inputManager.ControlManager) inputManager.Update {
	progress := float64(0)
	mutex := sync.Mutex{}
	dx := 4 * surface.W / 8
	startRect := sdl.Rect{surface.W / 4, 4 * surface.H / 7, 0, 2 * surface.H / 7}
	midBackgroundRect := sdl.Rect{surface.W / 4, 4 * surface.H / 7, dx, 2 * surface.H / 7}
	backgroundRect := sdl.Rect{surface.W/4 - 5, 4*surface.H/7 - 5, dx + 10, 2*surface.H/7 + 10}
	var mainMenu *Menu
	go asyncMenuCreator(renderer, &mutex, &progress, &mainMenu, surface.W, surface.H, window, controlManager)
	return func(state int) int {
		if controlManager.Player1.BF || controlManager.Player2.BF {
			controlManager.Running = false
			return -1
		}
		mutex.Lock()
		startRect.W = int32(float64(dx) * progress)
		surface.FillRect(&backgroundRect, 0xffff0000)
		surface.FillRect(&midBackgroundRect, 0xff000000)
		surface.FillRect(&startRect, 0xffff0000)
		window.UpdateSurface()
		if progress == 1 {
			menuInfo := MenuInfo{0, controlManager, renderer, &sdl.Rect{0, 0, surface.W, surface.H}}
			inputManager.UpdateFunctions = append(inputManager.UpdateFunctions, mainMenu.Open(0, &menuInfo))
			return -1
		}
		mutex.Unlock()
		return 0
	}
}
开发者ID:ITR13,项目名称:campusFighterI,代码行数:29,代码来源:CreateMenus.go

示例2: RenderGraphic

// RenderGraphic draws the Graphic, g, on the screen at postion (x,y).
// 'width' and 'height' specifiy the width and height of the Graphic, g.
//
// RenderGraphic will panic if:
// 1. The Graphic, g, does not contain a Graphic type.
//
// 2. The toolbox has not been initialised.
//
// 3. Any one of x, y, width or height are negative
func RenderGraphic(g Graphic, x, y, 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)
	}
	if x < 0 || y < 0 || width < 0 || height < 0 {
		panic("One of x, y, width or height is negative.")
	}
	var src, dst sdl.Rect

	src.X = 0
	src.Y = 0
	src.W = int32(width)
	src.H = int32(height)

	dst.X = int32(x)
	dst.Y = int32(y)
	dst.W = int32(width)
	dst.H = int32(height)

	renderer.Copy(g, &src, &dst)
}
开发者ID:gophercoders,项目名称:toolbox,代码行数:34,代码来源:toolbox.go

示例3: renderGameOver

func renderGameOver() {
	var src, dst sdl.Rect

	src.X = 0
	src.Y = 0
	src.W = int32(gameOverW)
	src.H = int32(gameOverH)

	dst.X = int32(gameOverX)
	dst.Y = int32(gameOverY)
	dst.W = int32(gameOverW)
	dst.H = int32(gameOverH)

	renderer.Copy(gameOverGfx, &src, &dst)
}
开发者ID:gophercoders,项目名称:pong,代码行数:15,代码来源:pong.go

示例4: renderComputersScore

func renderComputersScore() {
	var src, dst sdl.Rect

	src.X = 0
	src.Y = 0
	src.W = int32(scoreW)
	src.H = int32(scoreH)

	dst.X = int32(computersScoreX)
	dst.Y = int32(computersScoreY)
	dst.W = int32(scoreW)
	dst.H = int32(scoreH)

	renderer.Copy(scoresGfx[computersScore], &src, &dst)
}
开发者ID:gophercoders,项目名称:pong,代码行数:15,代码来源:pong.go

示例5: DrawText

// DrawText is
func (T *TextWidget) DrawText(text string, rect *sdl.Rect, colorName string, fontName string) {
	if strings.TrimSpace(text) == "" {
		return
	}
	// log.Println("DRAW:", text, colorName, fontName)
	font, ok := T.Fonts[fontName]
	if !ok {
		font = T.Fonts["default"]
	}
	color, ok := T.Colors[colorName]
	if !ok {
		colorHex, err := hex.DecodeString(colorName[1:])
		if err != nil || len(colorHex) < 3 {
			color = T.Colors["foreground"]
		} else {
			T.AddColor(colorName, colorHex[0], colorHex[1], colorHex[2])
			color = T.Colors[colorName]
		}
	}
	message, err := font.RenderUTF8_Blended(text, color)
	if err != nil {
		log.Fatal(err)
	}
	defer message.Free()
	srcRect := sdl.Rect{}
	message.GetClipRect(&srcRect)
	if fontName != "default" {
		_, h, _ := T.Fonts["default"].SizeUTF8("A")
		_, h2, _ := font.SizeUTF8("A")
		rect.Y -= int32((h2 - h) / 2)
	}
	message.Blit(&srcRect, T.Surface, rect)
}
开发者ID:averrin,项目名称:shadow-go,代码行数:34,代码来源:widget.go

示例6: renderBall

func renderBall() {

	var src, dst sdl.Rect

	src.X = 0
	src.Y = 0
	src.W = int32(ballW)
	src.H = int32(ballH)

	dst.X = int32(ballX)
	dst.Y = int32(ballY)
	dst.W = int32(ballW)
	dst.H = int32(ballH)

	renderer.Copy(ball, &src, &dst)

}
开发者ID:gophercoders,项目名称:pong,代码行数:17,代码来源:pong.go

示例7: renderComputersBat

func renderComputersBat() {

	var src, dst sdl.Rect

	src.X = 0
	src.Y = 0
	src.W = int32(computersBatW)
	src.H = int32(computersBatH)

	dst.X = int32(computersBatX)
	dst.Y = int32(computersBatY)
	dst.W = int32(computersBatW)
	dst.H = int32(computersBatH)

	renderer.Copy(computersBat, &src, &dst)

}
开发者ID:gophercoders,项目名称:pong,代码行数:17,代码来源:pong.go


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