當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Surface.FillRect方法代碼示例

本文整理匯總了Golang中github.com/banthar/Go-SDL/sdl.Surface.FillRect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Surface.FillRect方法的具體用法?Golang Surface.FillRect怎麽用?Golang Surface.FillRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/banthar/Go-SDL/sdl.Surface的用法示例。


在下文中一共展示了Surface.FillRect方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: gameloop

func gameloop(screen *sdl.Surface) {
	gc := &GameContext{screen, 320, 16}

	for {
		e := sdl.WaitEvent()

		screen.FillRect(nil, 0x0)

		gc.drawFloor()
		gc.drawPlayer()
		gc.drawObjects()

		switch re := e.(type) {
		case *sdl.QuitEvent:
			return

		case *sdl.MouseMotionEvent:

			screen.FillRect(&sdl.Rect{
				int16(re.X),
				int16(re.Y),
				50, 50}, 0xffffff)

			screen.Blit(&sdl.Rect{
				int16(re.X),
				int16(re.Y),
				0, 0}, playerTexture, nil)

			fmt.Println(re.X, re.Y)

		case *sdl.KeyboardEvent:
			if re.Type == sdl.KEYDOWN {
				keyname := sdl.GetKeyName(sdl.Key(re.Keysym.Sym))
				fmt.Println("pressed:", keyname)

				switch keyname {
				case "right":
					gc.moveRight()
				case "left":
					gc.moveLeft()
				case "q":
					return
				}
			} else if re.Type == sdl.KEYUP {
				gc.resetPlayerSpeed()
			}
		default:
			//fmt.Println("What the heck?!")
		}

		gc.Dump()

		screen.Flip()
	}
}
開發者ID:githubnemo,項目名稱:Jinx,代碼行數:55,代碼來源:main.go

示例2: Draw

func (o *Object) Draw(surface *sdl.Surface, gc *GameContext) {
	windowStartX := int16(gc.PlayerPosition - 320)

	// "move" the object according to the window
	drawRect := &sdl.Rect{
		X: o.Rect.X - windowStartX,
		Y: o.Rect.Y,
		W: o.Rect.W,
		H: o.Rect.H,
	}

	surface.FillRect(drawRect, o.Color)
}
開發者ID:githubnemo,項目名稱:Jinx,代碼行數:13,代碼來源:level.go

示例3: initFillBox

func initFillBox(screen *sdl.Surface) {
	/*{{{*/
	for i := range paint_chan {
		if i.f.T == i.c {
			continue
		}

		i.f.T = i.c
		screen.FillRect(i.f.toRect(), uint32(i.c))
		// Do updates of screen in the main loop.
		//screen.UpdateRect(i.f.ToFourTuple());
	}
	/*}}}*/
}
開發者ID:kse,項目名稱:aStar-demo,代碼行數:14,代碼來源:drawing.go

示例4: drawGrid

/*
 * Draw a grid on the display and return info about the Tile
 */
func drawGrid(screen *sdl.Surface) {
	/*{{{*/
	vid := sdl.GetVideoInfo()

	// First the vertical
	for i := 0; i < int(vid.Current_w); i += SIZE {
		screen.FillRect(
			&sdl.Rect{int16(i), int16(0), 1, uint16(vid.Current_h)},
			0x000000)
		screen.UpdateRect(int32(i), 0, 1, uint32(vid.Current_h))
	}

	// Then the horizontal
	for i := 0; i < int(vid.Current_h); i += SIZE {
		screen.FillRect(
			&sdl.Rect{0, int16(i), uint16(vid.Current_w), 1},
			0x000000)
		screen.UpdateRect(0, int32(i), uint32(vid.Current_w), 1)
	}

	return
	/*}}}*/
}
開發者ID:kse,項目名稱:aStar-demo,代碼行數:26,代碼來源:drawing.go


注:本文中的github.com/banthar/Go-SDL/sdl.Surface.FillRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。