本文整理匯總了Golang中github.com/hajimehoshi/ebiten.Image類的典型用法代碼示例。如果您正苦於以下問題:Golang Image類的具體用法?Golang Image怎麽用?Golang Image使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Image類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: update
func update(screen *ebiten.Image) error {
drawn := false
mx, my := ebiten.CursorPosition()
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
if err := paint(screen, mx, my); err != nil {
return err
}
drawn = true
}
for _, t := range ebiten.Touches() {
x, y := t.Position()
if err := paint(screen, x, y); err != nil {
return err
}
drawn = true
}
if drawn {
count++
}
if err := screen.DrawImage(canvasImage, nil); err != nil {
return err
}
msg := fmt.Sprintf("(%d, %d)", mx, my)
for _, t := range ebiten.Touches() {
x, y := t.Position()
msg += fmt.Sprintf("\n(%d, %d) touch %d", x, y, t.ID())
}
if err := ebitenutil.DebugPrint(screen, msg); err != nil {
return err
}
return nil
}
示例2: update
func update(screen *ebiten.Image) error {
readKeys()
select {
case <-simulationTimer:
newSimulation := currentSimulation.Step()
wires := currentSimulation.Circuit().Wires()
for i, wire := range wires {
oldCharge := currentSimulation.State(wire).Charge()
charge := newSimulation.State(wire).Charge()
if oldCharge == charge {
continue
}
position := wire.Bounds().Min
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(position.X), float64(position.Y))
r, g, b, a := simulationImage.Palette[charge+1].RGBA()
op.ColorM.Scale(float64(r)/0xFFFF, float64(g)/0xFFFF, float64(b)/0xFFFF, float64(a)/0xFFFF)
if err := backgroundImage.DrawImage(wireImages[i], op); err != nil {
return err
}
}
currentSimulation = newSimulation
default:
}
if err := screen.DrawImage(backgroundImage, &ebiten.DrawImageOptions{}); err != nil {
return err
}
if err := handleCursor(screen); err != nil {
return err
}
return nil
}
示例3: Draw
func (s *GamepadScene) Draw(screen *ebiten.Image) error {
screen.Fill(color.Black)
if s.buttonStates == nil {
return nil
}
f := `GAMEPAD CONFIGURATION
(PRESS ESC TO CANCEL)
MOVE LEFT: %s
MOVE RIGHT: %s
DROP: %s
ROTATE LEFT: %s
ROTATE RIGHT: %s
%s`
msg := ""
if s.currentIndex == len(gamepadStdButtons) {
msg = "OK!"
}
str := fmt.Sprintf(f, s.buttonStates[0], s.buttonStates[1], s.buttonStates[2], s.buttonStates[3], s.buttonStates[4], msg)
if err := common.ArcadeFont.DrawTextWithShadow(screen, str, 16, 16, 1, color.White); err != nil {
return err
}
return nil
}
示例4: drawGroundImage
func drawGroundImage(screen *ebiten.Image, ground *ebiten.Image) error {
op := &ebiten.DrawImageOptions{}
if err := screen.DrawImage(ground, op); err != nil {
return err
}
return nil
}
示例5: update
func update(screen *ebiten.Image) error {
count++
count %= 600
diff := float64(count) * 0.2
switch {
case 480 < count:
diff = 0
case 240 < count:
diff = float64(480-count) * 0.2
}
if err := tmpRenderTarget.Clear(); err != nil {
return err
}
for i := 0; i < 10; i++ {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(15+float64(i)*diff, 20)
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil {
return err
}
}
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
for i := 0; i < 10; i++ {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(0, float64(i)*diff)
if err := screen.DrawImage(tmpRenderTarget, op); err != nil {
return err
}
}
return nil
}
示例6: Draw
func (s *SceneManager) Draw(r *ebiten.Image) error {
if s.transitionCount == -1 {
return s.current.Draw(r)
}
if err := transitionFrom.Clear(); err != nil {
return err
}
if err := s.current.Draw(transitionFrom); err != nil {
return err
}
if err := transitionTo.Clear(); err != nil {
return err
}
if err := s.next.Draw(transitionTo); err != nil {
return err
}
if err := r.DrawImage(transitionFrom, nil); err != nil {
return err
}
alpha := float64(s.transitionCount) / float64(transitionMaxCount)
op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1, 1, 1, alpha)
return r.DrawImage(transitionTo, op)
}
示例7: update
func update(screen *ebiten.Image) error {
if ebiten.IsKeyPressed(ebiten.KeySpace) {
thePlayer.MoveForward()
}
rotated := false
if ebiten.IsKeyPressed(ebiten.KeyRight) {
thePlayer.RotateRight()
rotated = true
}
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
thePlayer.RotateLeft()
rotated = true
}
if !rotated {
thePlayer.Stabilize()
}
if err := screen.Fill(skyColor); err != nil {
return err
}
if err := updateGroundImage(groundImage); err != nil {
return err
}
if err := drawGroundImage(screen, groundImage); err != nil {
return err
}
tutrial := "Space: Move forward\nLeft/Right: Rotate"
msg := fmt.Sprintf("FPS: %0.2f\n%s", ebiten.CurrentFPS(), tutrial)
if err := ebitenutil.DebugPrint(screen, msg); err != nil {
return err
}
return nil
}
示例8: drawBackground
func (s *GameScene) drawBackground(r *ebiten.Image) error {
if err := r.Fill(color.White); err != nil {
return err
}
w, h := imageGameBG.Size()
scaleW := ScreenWidth / float64(w)
scaleH := ScreenHeight / float64(h)
scale := scaleW
if scale < scaleH {
scale = scaleH
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Scale(scale, scale)
op.GeoM.Translate(ScreenWidth/2, ScreenHeight/2)
a := 0.7
m := ebiten.Monochrome()
m.Scale(a, a, a, a)
op.ColorM.Scale(1-a, 1-a, 1-a, 1-a)
op.ColorM.Add(m)
op.ColorM.Translate(0.3, 0.3, 0.3, 0)
return r.DrawImage(imageGameBG, op)
}
示例9: drawBlocks
func drawBlocks(r *ebiten.Image, blocks [][]BlockType, x, y int, clr ebiten.ColorM) error {
op := &ebiten.DrawImageOptions{
ImageParts: blocksImageParts(blocks),
ColorM: clr,
}
op.GeoM.Translate(float64(x), float64(y))
return r.DrawImage(imageBlocks, op)
}
示例10: drawWindow
func drawWindow(r *ebiten.Image, x, y, width, height int) error {
op := &ebiten.DrawImageOptions{}
w, h := imageEmpty.Size()
op.GeoM.Scale(float64(width)/float64(w), float64(height)/float64(h))
op.GeoM.Translate(float64(x), float64(y))
op.ColorM.Scale(0, 0, 0, 0.75)
return r.DrawImage(imageEmpty, op)
}
示例11: Draw
func (t *Tile) Draw(boardImage *ebiten.Image) error {
i, j := t.current.x, t.current.y
ni, nj := t.next.x, t.next.y
v := t.current.value
if v == 0 {
return nil
}
op := &ebiten.DrawImageOptions{}
x := i*tileSize + (i+1)*tileMargin
y := j*tileSize + (j+1)*tileMargin
nx := ni*tileSize + (ni+1)*tileMargin
ny := nj*tileSize + (nj+1)*tileMargin
switch {
case 0 < t.movingCount:
rate := 1 - float64(t.movingCount)/maxMovingCount
x = mean(x, nx, rate)
y = mean(y, ny, rate)
case 0 < t.startPoppingCount:
rate := 1 - float64(t.startPoppingCount)/float64(maxPoppingCount)
scale := meanF(0.0, 1.0, rate)
op.GeoM.Translate(float64(-tileSize/2), float64(-tileSize/2))
op.GeoM.Scale(scale, scale)
op.GeoM.Translate(float64(tileSize/2), float64(tileSize/2))
case 0 < t.poppingCount:
const maxScale = 1.2
rate := 0.0
if maxPoppingCount*2/3 <= t.poppingCount {
// 0 to 1
rate = 1 - float64(t.poppingCount-2*maxPoppingCount/3)/float64(maxPoppingCount/3)
} else {
// 1 to 0
rate = float64(t.poppingCount) / float64(maxPoppingCount*2/3)
}
scale := meanF(1.0, maxScale, rate)
op.GeoM.Translate(float64(-tileSize/2), float64(-tileSize/2))
op.GeoM.Scale(scale, scale)
op.GeoM.Translate(float64(tileSize/2), float64(tileSize/2))
}
op.GeoM.Translate(float64(x), float64(y))
r, g, b, a := colorToScale(tileBackgroundColor(v))
op.ColorM.Scale(r, g, b, a)
if err := boardImage.DrawImage(tileImage, op); err != nil {
return err
}
str := strconv.Itoa(v)
scale := 2
if 2 < len(str) {
scale = 1
}
w := common.ArcadeFont.TextWidth(str) * scale
h := common.ArcadeFont.TextHeight(str) * scale
x = x + (tileSize-w)/2
y = y + (tileSize-h)/2
if err := common.ArcadeFont.DrawText(boardImage, str, x, y, scale, tileColor(v)); err != nil {
return err
}
return nil
}
示例12: Draw
func (s *GameScene) Draw(r *ebiten.Image) error {
if err := s.drawBackground(r); err != nil {
return err
}
if err := r.DrawImage(imageWindows, nil); err != nil {
return err
}
// Draw score
x, y := scoreTextBoxPosition()
if err := drawTextBoxContent(r, strconv.Itoa(s.score), x, y, textBoxWidth()); err != nil {
return err
}
// Draw level
x, y = levelTextBoxPosition()
if err := drawTextBoxContent(r, strconv.Itoa(s.level()), x, y, textBoxWidth()); err != nil {
return err
}
// Draw lines
x, y = linesTextBoxPosition()
if err := drawTextBoxContent(r, strconv.Itoa(s.lines), x, y, textBoxWidth()); err != nil {
return err
}
// Draw blocks
fieldX, fieldY := fieldWindowPosition()
if err := s.field.Draw(r, fieldX, fieldY); err != nil {
return err
}
if s.currentPiece != nil && !s.field.Flushing() {
x := fieldX + s.currentPieceX*blockWidth
y := fieldY + s.currentPieceY*blockHeight
if err := s.currentPiece.Draw(r, x, y, s.currentPieceAngle); err != nil {
return err
}
}
if s.nextPiece != nil {
// TODO: Make functions to get these values.
x := fieldX + fieldWidth + blockWidth*2
y := fieldY + blockHeight
if err := s.nextPiece.DrawAtCenter(r, x, y, blockWidth*5, blockHeight*5, 0); err != nil {
return err
}
}
if s.gameover {
if err := r.DrawImage(imageGameover, nil); err != nil {
return err
}
}
return nil
}
示例13: updateGroundImage
func updateGroundImage(ground *ebiten.Image) error {
if err := ground.Clear(); err != nil {
return err
}
x16, y16 := theViewport.Position()
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(-x16)/16, float64(-y16)/16)
if err := ground.DrawImage(repeatedBgImage, op); err != nil {
return err
}
return nil
}
示例14: handleCursor
func handleCursor(screen *ebiten.Image) error {
mx, my := ebiten.CursorPosition()
cursorMoved := image.Point{mx, my}.In(screen.Bounds()) && (mx != oldMouseCursorPosition.X || my != oldMouseCursorPosition.Y)
oldMouseCursorPosition = image.Point{mx, my}
if cursorMoved {
cursorPosition = oldMouseCursorPosition
} else {
const cursorInterval = 6
switch {
case keyStates[ebiten.KeyUp]%cursorInterval == 0:
cursorPosition = cursorPosition.Add(image.Point{0, -1})
cursorMoved = true
case keyStates[ebiten.KeyDown]%cursorInterval == 0:
cursorPosition = cursorPosition.Add(image.Point{0, +1})
cursorMoved = true
case keyStates[ebiten.KeyLeft]%cursorInterval == 0:
cursorPosition = cursorPosition.Add(image.Point{-1, 0})
cursorMoved = true
case keyStates[ebiten.KeyRight]%cursorInterval == 0:
cursorPosition = cursorPosition.Add(image.Point{+1, 0})
cursorMoved = true
}
}
if cursorBlinking == 127 {
cursorBlinking = 0
} else {
cursorBlinking++
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(0.25, .25)
op.GeoM.Translate(float64(cursorPosition.X), float64(cursorPosition.Y))
if cursorBlinking > 64 {
op.ColorM.Scale(1, 1, 1, 0.25+float64(127-cursorBlinking)/255.0)
} else {
op.ColorM.Scale(1, 1, 1, 0.25+float64(cursorBlinking)/255.0)
}
if err := screen.DrawImage(cursorImage, op); err != nil {
return err
}
if keyStates[ebiten.KeySpace] >= 0 ||
ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
if cursorMoved || !wasMouseButtonPressed {
if err := togglePixel(cursorPosition); err != nil {
return err
}
wasMouseButtonPressed = true
}
} else {
wasMouseButtonPressed = false
}
return nil
}
示例15: drawText
func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) {
ur, ug, ub, ua := c.RGBA()
const max = math.MaxUint16
r := float64(ur) / max
g := float64(ug) / max
b := float64(ub) / max
a := float64(ua) / max
if 0 < a {
r /= a
g /= a
b /= a
}
op := &ebiten.DrawImageOptions{
ImageParts: debugPrintImageParts(str),
}
op.GeoM.Translate(float64(x+1), float64(y))
op.ColorM.Scale(r, g, b, a)
rt.DrawImage(d.textImage, op)
}