本文整理汇总了Golang中github.com/jackyb/go-sdl2/sdl.Renderer类的典型用法代码示例。如果您正苦于以下问题:Golang Renderer类的具体用法?Golang Renderer怎么用?Golang Renderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Renderer类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: drawObstacles
func drawObstacles(r *sdl.Renderer) {
r.SetDrawColor(255, 128, 100, 255)
for _, o := range obstacles {
rect := sdl.Rect{int32(o.X - o.Size), int32(o.Y - o.Size), int32(o.Size * 2), int32(o.Size * 2)}
r.DrawRect(&rect)
}
}
开发者ID:jostly,项目名称:arcadegame,代码行数:7,代码来源:arcadegame.go
示例2: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var event sdl.Event
var running bool
window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight, sdl.WINDOW_SHOWN)
if window == nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
os.Exit(1)
}
renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if renderer == nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(2)
}
var peepArray []sdl.Event = make([]sdl.Event, 5)
running = true
for running {
sdl.PumpEvents()
numEventsRetrieved := sdl.PeepEvents(peepArray, sdl.PEEKEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
if numEventsRetrieved < 0 {
fmt.Printf("PeepEvents error: %s\n", sdl.GetError())
} else {
for i := 0; i < numEventsRetrieved; i++ {
fmt.Printf("Event Peeked Value: %v\n", peepArray[i]) // primitive printing of event
}
}
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyUpEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
}
}
sdl.Delay(1000 / 30)
}
renderer.Destroy()
window.Destroy()
}
开发者ID:hybridgroup,项目名称:go-sdl2,代码行数:57,代码来源:PeepEvents_peek.go
示例3: CreateText
func CreateText(renderer *sdl.Renderer, font *ttf.Font, message string, color sdl.Color) *sdl.Texture {
surf := font.RenderText_Blended(message, color)
if surf == nil {
log.Println("Error when rendering text")
return nil
}
defer surf.Free()
return renderer.CreateTextureFromSurface(surf)
}
开发者ID:jostly,项目名称:arcadegame,代码行数:10,代码来源:text.go
示例4: drawShip
func drawShip(r *sdl.Renderer) {
ship := make([]sdl.Point, 4)
for i := 0; i < 4; i++ {
p := shipPoints[i%3]
ship[i] = sdl.Point{p.X + int32(x), p.Y + int32(y)}
}
r.SetDrawColor(255, 255, 255, 255)
err := r.DrawLines(ship)
if err != 0 {
error("Draw error")
}
}
开发者ID:jostly,项目名称:arcadegame,代码行数:13,代码来源:arcadegame.go
示例5: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var event sdl.Event
var running bool
window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight, sdl.WINDOW_SHOWN)
if window == nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
os.Exit(1)
}
renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if renderer == nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(2)
}
running = true
for running {
event = sdl.WaitEventTimeout(1000) // wait here until an event is in the event queue
if event == nil {
fmt.Println("WaitEventTimeout timed out")
continue
}
switch t := event.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyUpEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
}
}
renderer.Destroy()
window.Destroy()
}
开发者ID:hybridgroup,项目名称:go-sdl2,代码行数:48,代码来源:WaitEventTimeout.go
示例6: MainLoop
func MainLoop(renderer *sdl.Renderer, font *ttf.Font) {
lastTick := sdl.GetTicks()
lastSecond := lastTick
frames := 0
fpsText := gfx.CreateText(renderer, font, "FPS: ... "+StatusCallback(), sdl.Color{255, 255, 255, 255})
framesPerSecond := 0
for running {
tick := sdl.GetTicks()
if tick < lastTick+10 {
sdl.Delay(1)
continue
}
delta := float64(tick-lastTick) / 1000.0
lastTick = tick
fpsText.Destroy()
fpsText = gfx.CreateText(renderer, font, fmt.Sprintf("FPS: %3d ", framesPerSecond)+StatusCallback(), sdl.Color{255, 255, 255, 255})
if tick > (lastSecond + 1000) {
lastSecond = tick
framesPerSecond = frames
frames = 0
} else {
frames++
}
handleEvents()
UpdateCallback(delta)
renderer.SetDrawColor(0, 0, 0, 0)
renderer.Clear()
RenderCallback(renderer)
gfx.RenderTexture(renderer, fpsText, 0, 0)
renderer.Present()
}
fpsText.Destroy()
}
开发者ID:jostly,项目名称:arcadegame,代码行数:46,代码来源:loop.go
示例7: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var image *sdl.Surface
var texture *sdl.Texture
var src, dst sdl.Rect
window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight, sdl.WINDOW_SHOWN)
if window == nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
os.Exit(1)
}
renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if renderer == nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(2)
}
image = sdl.LoadBMP(imageName)
if image == nil {
fmt.Fprintf(os.Stderr, "Failed to load BMP: %s", sdl.GetError())
os.Exit(3)
}
texture = renderer.CreateTextureFromSurface(image)
if texture == nil {
fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", sdl.GetError())
os.Exit(4)
}
src = sdl.Rect{0, 0, 512, 512}
dst = sdl.Rect{100, 50, 512, 512}
renderer.Clear()
renderer.Copy(texture, &src, &dst)
renderer.Present()
sdl.Delay(2000)
image.Free()
texture.Destroy()
renderer.Destroy()
window.Destroy()
}
开发者ID:hybridgroup,项目名称:go-sdl2,代码行数:46,代码来源:texture.go
示例8: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var points []sdl.Point
var rect sdl.Rect
var rects []sdl.Rect
window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight, sdl.WINDOW_SHOWN)
if window == nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
os.Exit(1)
}
renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if renderer == nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(2)
}
renderer.SetDrawColor(255, 255, 255, 255)
renderer.DrawPoint(150, 300)
renderer.SetDrawColor(0, 0, 255, 255)
renderer.DrawLine(0, 0, 200, 200)
points = []sdl.Point{{0, 0}, {100, 300}, {100, 300}, {200, 0}}
renderer.SetDrawColor(255, 255, 0, 255)
renderer.DrawLines(&points, 4)
rect = sdl.Rect{300, 0, 200, 200}
renderer.SetDrawColor(255, 0, 0, 255)
renderer.DrawRect(&rect)
rects = []sdl.Rect{{400, 400, 100, 100}, {550, 350, 200, 200}}
renderer.SetDrawColor(0, 255, 255, 255)
renderer.DrawRects(&rects, 2)
rect = sdl.Rect{250, 250, 200, 200}
renderer.SetDrawColor(0, 255, 0, 255)
renderer.FillRect(&rect)
rects = []sdl.Rect{{500, 300, 100, 100}, {200, 300, 200, 200}}
renderer.SetDrawColor(255, 0, 255, 255)
renderer.FillRects(&rects, 2)
renderer.Present()
sdl.Delay(2000)
renderer.Destroy()
window.Destroy()
}
开发者ID:kyleconroy,项目名称:golds,代码行数:53,代码来源:render.go
示例9: drawMissiles
func drawMissiles(r *sdl.Renderer) {
for _, p := range missiles {
r.DrawPoint(int(p.X), int(p.Y))
}
}
开发者ID:jostly,项目名称:arcadegame,代码行数:5,代码来源:arcadegame.go
示例10: RenderTexture
func RenderTexture(renderer *sdl.Renderer, texture *sdl.Texture, x, y int) {
var w, h int
sdl.QueryTexture(texture, nil, nil, &w, &h)
dst := sdl.Rect{int32(x), int32(y), int32(w), int32(h)}
renderer.Copy(texture, nil, &dst)
}
开发者ID:jostly,项目名称:arcadegame,代码行数:6,代码来源:texture.go
示例11: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var event sdl.Event
var running bool
window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight, sdl.WINDOW_SHOWN)
if window == nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
os.Exit(1)
}
renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if renderer == nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(2)
}
running = true
lastPushTime := sdl.GetTicks()
for running {
// Push a UserEvent every second
if lastPushTime+pushTime < sdl.GetTicks() {
lastPushTime = sdl.GetTicks()
pEvent := &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 1331, nil, nil}
retVal := sdl.PushEvent(pEvent) // Here's where the event is actually pushed
switch retVal {
case 1:
fmt.Println("PushEvent returned success")
case 0:
fmt.Println("PushEvent returned filtered")
case -1:
fmt.Printf("PushEvent returned error: %s\n", sdl.GetError)
}
}
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyUpEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
case *sdl.UserEvent:
fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code)
}
}
sdl.Delay(1000 / 30)
}
renderer.Destroy()
window.Destroy()
}
开发者ID:hybridgroup,项目名称:go-sdl2,代码行数:66,代码来源:PushEvent.go
示例12: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
var event sdl.Event
var running bool
window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight, sdl.WINDOW_SHOWN)
if window == nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
os.Exit(1)
}
renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if renderer == nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
os.Exit(2)
}
var peepArray []sdl.Event = make([]sdl.Event, 2)
peepArray[0] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 1331, nil, nil}
peepArray[1] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 10101, nil, nil}
running = true
lastPushTime := sdl.GetTicks()
for running {
if lastPushTime+pushTime < sdl.GetTicks() {
lastPushTime = sdl.GetTicks()
sdl.PumpEvents()
numEventsHandled := sdl.PeepEvents(peepArray, sdl.ADDEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
if numEventsHandled < 0 {
fmt.Printf("PeepEvents error: %s\n", sdl.GetError())
} else {
fmt.Printf("Successful push of %d events\n", numEventsHandled)
}
}
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyUpEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
case *sdl.UserEvent:
fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code)
}
}
sdl.Delay(1000 / 30)
}
renderer.Destroy()
window.Destroy()
}
开发者ID:hybridgroup,项目名称:go-sdl2,代码行数:63,代码来源:PeepEvents_add.go
注:本文中的github.com/jackyb/go-sdl2/sdl.Renderer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论