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


Golang sdl.Surface類代碼示例

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


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

示例1: Render

func (g *guiLayer) Render(target *sdl.Surface) {
	if g.child != nil {
		g.child.Render(target)
	}

	target.FillRect(
		&sdl.Rect{
			X: 20,
			Y: 300,
			H: uint16(30 + (30 * g.game.NumPlayers)),
			W: 200,
		},
		0xffffff,
	)

	for i := 0; i < g.game.NumPlayers; i++ {
		p := g.game.GetPlayer(i)
		str := fmt.Sprintf("Player %d: %d - %d - %d", i, p.Money.Get(), p.Money.GetIncome(), p.GetLives())

		txt_surface := ttf.RenderText_Solid(g.font, str, sdl.Color{})
		if txt_surface == nil {
			fmt.Printf("RenderText Solid failed: %s", sdl.GetError())
		}

		target.Blit(
			&sdl.Rect{
				X: 50,
				Y: int16(320 + (i * 30)),
			},
			txt_surface,
			nil,
		)
	}
}
開發者ID:nickdavies,項目名稱:line_tower_wars,代碼行數:34,代碼來源:gui.go

示例2: MakeSurface

func MakeSurface(surf *sdl.Surface) *Surface {
	surf.Lock() // Get Lock before creating the surface slice.
	surface := &Surface{surf, nil}
	sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&surface.pixels)))
	sliceHeader.Cap = int(surf.H * surf.W)
	sliceHeader.Len = int(surf.H * surf.W)
	sliceHeader.Data = uintptr(unsafe.Pointer(surf.Pixels))
	surf.Unlock()
	return surface
}
開發者ID:ramsay,項目名稱:ramsay-snippets,代碼行數:10,代碼來源:Liquid.go

示例3: Draw

// Draw directs each layer, starting from the bottom, to draw to the
// screen, and then updates the necessary parts of the screen.
func (stack LayerStack) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{X: 0, Y: 0, W: uint16(screen.W), H: uint16(screen.H)},
		0,
	)
	for i, layer := range stack {
		top := i == len(stack)-1
		layer.Draw(screen, top)
	}
	screen.Flip()
}
開發者ID:bieber,項目名稱:drones,代碼行數:13,代碼來源:layer.go

示例4: wrap

func wrap(cSurface *C.SDL_Surface) *sdl.Surface {
	var s *sdl.Surface

	if cSurface != nil {
		var surface sdl.Surface
		surface.SetCSurface(unsafe.Pointer(cSurface))
		s = &surface
	} else {
		s = nil
	}

	return s
}
開發者ID:neagix,項目名稱:Go-SDL,代碼行數:13,代碼來源:ttf.go

示例5: Render

func (g *stageLayer) Render(target *sdl.Surface) {

	target.Blit(
		&sdl.Rect{
			X: 0,
			Y: 0,
			W: uint16(g.size_x),
			H: uint16(g.size_y),
		},
		g.surface,
		nil,
	)

	if g.child != nil {
		g.child.Render(target)
	}

}
開發者ID:nickdavies,項目名稱:line_tower_wars,代碼行數:18,代碼來源:stage.go

示例6: Render

func (g *buildLayer) Render(target *sdl.Surface) {
	x_off, y_off := g.GetXYOffsets()
	square_x, square_y := util.GetMouse(g.square_size, x_off, y_off, false)

	var build_colour uint32
	if g.controls.GetPlayer().Buildable(square_y/g.square_size, square_x/g.square_size) {
		build_colour = 0x00ff00
	} else {
		build_colour = 0xff0000
	}

	g.buildSurface.FillRect(
		&sdl.Rect{
			X: 0,
			Y: 0,
			H: 128,
			W: 128,
		},
		build_colour,
	)

	g.buildSurface.Blit(
		&sdl.Rect{
			X: 0,
			Y: 0,
		},
		g.texture_map.GetName("turret_basic").Surface,
		nil,
	)

	target.Blit(
		&sdl.Rect{
			X: int16(square_x),
			Y: int16(square_y),
		},
		g.buildSurface,
		nil,
	)

	if g.child != nil {
		g.child.Render(target)
	}

}
開發者ID:nickdavies,項目名稱:line_tower_wars,代碼行數:44,代碼來源:build.go

示例7: Draw

func (m *MainMenu) Draw(screen *sdl.Surface, top bool) {
	w := uint16(m.titleText.W)
	h := uint16(m.titleText.H)
	screen.Blit(
		&sdl.Rect{
			X: int16(screen.W - m.titleText.W - 50),
			Y: 15,
			W: w,
			H: h,
		},
		m.titleText,
		&sdl.Rect{X: 0, Y: 0, W: w, H: h},
	)

	m.menuItemSelected = ""
	y := int16(screen.H - menuItemYOffset)
	for _, label := range m.itemLabels {
		item := m.menuItems[label]
		mx := int16(m.mouseX)
		my := int16(m.mouseY)
		w = uint16(item.W)
		h = uint16(item.H)
		y -= int16(item.H)
		if ui.Overlaps(mx, my, menuItemXOffset, y, w, h) {
			if top {
				item = m.hoverItems[label]
			}
			m.menuItemSelected = label
		}

		screen.Blit(
			&sdl.Rect{
				X: menuItemXOffset,
				Y: int16(y),
				W: w,
				H: h,
			},
			item,
			&sdl.Rect{X: 0, Y: 0, W: w, H: h},
		)
	}
}
開發者ID:bieber,項目名稱:drones,代碼行數:42,代碼來源:mainmenu.go

示例8: Render

func (g *panLayer) Render(target *sdl.Surface) {
	g.child.Render(g.surface)
	g.surface.Flip()

	parent_x, parent_y := g.parent.GetSize()

	target.Blit(
		&sdl.Rect{
			X: 0,
			Y: 0,
			W: parent_x,
			H: parent_y,
		},
		g.surface,
		&sdl.Rect{
			X: int16(g.view_x),
			Y: int16(g.view_y),
			W: parent_x,
			H: parent_y,
		},
	)
}
開發者ID:nickdavies,項目名稱:line_tower_wars,代碼行數:22,代碼來源:pan.go

示例9: Draw

func (t *TextBox) Draw(screen *sdl.Surface) {
	y := t.Y
	lineSpacing := 0
	for _, line := range t.lines {
		if line == nil {
			y += int16(lineSpacing)
			continue
		} else {
			lineSpacing = int(line.H) / 2
		}

		if uint16(y)+uint16(line.H)-uint16(t.Y) > t.H {
			continue
		}

		x := int16(t.X)
		switch t.FontAlignment {
		case Left:
			x += 0
		case Center:
			x += (int16(t.W) - int16(line.W)) / 2
		case Right:
			x += int16(t.W) - int16(line.W)
		}

		screen.Blit(
			&sdl.Rect{
				X: x,
				Y: y,
				W: uint16(line.W),
				H: uint16(line.H),
			},
			line,
			&sdl.Rect{W: uint16(line.W), H: uint16(line.H)},
		)
		y += int16(line.H)
	}
}
開發者ID:bieber,項目名稱:drones,代碼行數:38,代碼來源:textbox.go

示例10: Draw

func (w *Window) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{
			X: w.X,
			Y: w.Y,
			W: w.W,
			H: w.H,
		},
		ui.ColorToInt(w.BorderColor),
	)
	screen.FillRect(
		&sdl.Rect{
			X: w.X + int16(w.BorderWidth),
			Y: w.Y + int16(w.BorderWidth),
			W: w.W - w.BorderWidth*2,
			H: w.H - w.BorderWidth*2,
		},
		ui.ColorToInt(w.BGColor),
	)

	for _, child := range w.children {
		child.Draw(screen)
	}
}
開發者ID:bieber,項目名稱:drones,代碼行數:24,代碼來源:window.go

示例11: Draw

func (b *Button) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{
			X: b.X,
			Y: b.Y,
			W: b.W,
			H: b.H,
		},
		ui.ColorToInt(b.BorderColor),
	)
	var fillColor sdl.Color
	if b.hovered {
		fillColor = b.HoverColor
	} else {
		fillColor = b.BGColor
	}
	screen.FillRect(
		&sdl.Rect{
			X: b.X + int16(b.BorderWidth),
			Y: b.Y + int16(b.BorderWidth),
			W: b.W - 2*uint16(b.BorderWidth),
			H: b.H - 2*uint16(b.BorderWidth),
		},
		ui.ColorToInt(fillColor),
	)
	screen.Blit(
		&sdl.Rect{
			X: b.X + int16((int32(b.W)-b.labelText.W)/2),
			Y: b.Y + int16((int32(b.H)-b.labelText.H)/2),
			W: uint16(b.labelText.W),
			H: uint16(b.labelText.H),
		},
		b.labelText,
		&sdl.Rect{W: uint16(b.labelText.W), H: uint16(b.labelText.H)},
	)
}
開發者ID:bieber,項目名稱:drones,代碼行數:36,代碼來源:button.go

示例12: Render

func (g *entityLayer) Render(target *sdl.Surface) {

	var units = make(map[string]*sdl.Surface)

	turret_texture := g.texture_map.GetName("turret_basic").Surface

	for i := 0; i < g.game.NumPlayers; i++ {
		player := g.game.GetPlayer(i)

		for loc, _ := range player.Towers {
			target.Blit(
				&sdl.Rect{
					X: int16(loc.Col * g.square_size),
					Y: int16(loc.Row * g.square_size),
				},
				turret_texture,
				nil,
			)
		}

		for _, u := range player.Units {
			unit_name := u.Type.Name
			_, ok := units[unit_name]
			if !ok {
				units[unit_name] = g.texture_map.GetName(unit_name).Surface
			}

			loc := u.Loc
			target.Blit(
				&sdl.Rect{
					X: int16(loc.Col*float64(g.square_size)) - 32,
					Y: int16(loc.Row*float64(g.square_size)) - 32,
				},
				units[unit_name],
				nil,
			)

			health := 64 * (float64(u.Health) / float64(u.Type.Health))

			target.FillRect(
				&sdl.Rect{
					X: int16(loc.Col*float64(g.square_size)) - 32,
					Y: int16(loc.Row*float64(g.square_size)) - 32,
					W: 5,
					H: 64,
				},
				0x000000,
			)

			if health > 0 {
				target.FillRect(
					&sdl.Rect{
						X: int16(loc.Col*float64(g.square_size)) - 32,
						Y: int16(loc.Row*float64(g.square_size)) - 32,
						W: 5,
						H: uint16(health),
					},
					0x00ff00,
				)
			}

		}
	}

	if g.child != nil {
		g.child.Render(target)
	}

}
開發者ID:nickdavies,項目名稱:line_tower_wars,代碼行數:69,代碼來源:entity.go


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