func update(screen *ebiten.Image) error { if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { count++ } mx, my := ebiten.CursorPosition() if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { op := &ebiten.DrawImageOptions{} op.GeoM.Translate(float64(mx), float64(my)) op.ColorM.Scale(1.0, 0.25, 0.25, 1.0) theta := 2.0 * math.Pi * float64(count%60) / 60.0 op.ColorM.Concat(ebiten.RotateHue(theta)) if err := canvasImage.DrawImage(brushImage, op); err != nil { return err } } if err := screen.DrawImage(canvasImage, nil); err != nil { return err } if err := ebitenutil.DebugPrint(screen, fmt.Sprintf("(%d, %d)", mx, my)); err != nil { return err } return nil }
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 }
func (p *Player) updateBar() error { if p.audioPlayer == nil { return nil } if p.seekedCh != nil { return nil } if !ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { mouseButtonState[ebiten.MouseButtonLeft] = 0 return nil } mouseButtonState[ebiten.MouseButtonLeft]++ if mouseButtonState[ebiten.MouseButtonLeft] != 1 { return nil } x, y := ebiten.CursorPosition() bx, by, bw, bh := playerBarRect() const padding = 4 if y < by-padding || by+bh+padding <= y { return nil } if x < bx || bx+bw <= x { return nil } pos := time.Duration(x-bx) * p.total / time.Duration(bw) p.seekedCh = make(chan error, 1) go func() { // This can't be done parallely! !?!? p.seekedCh <- p.audioPlayer.Seek(pos) }() return nil }
func update(screen *ebiten.Image) error { for key, _ := range keyStates { if !ebiten.IsKeyPressed(key) { keyStates[key] = 0 continue } keyStates[key]++ } d := 0 switch screenScale { case 1: d = 32 case 2: d = 16 } if keyStates[ebiten.KeyUp] == 1 { screenHeight += d } if keyStates[ebiten.KeyDown] == 1 { if 16 < screenHeight { screenHeight -= d } } if keyStates[ebiten.KeyLeft] == 1 { if 16 < screenWidth { screenWidth -= d } } if keyStates[ebiten.KeyRight] == 1 { screenWidth += d } if keyStates[ebiten.KeyS] == 1 { screenScale = 3 - screenScale // Swap 1 and 2 } ebiten.SetScreenSize(screenWidth, screenHeight) ebiten.SetScreenScale(screenScale) screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff}) w, h := gophersImage.Size() w2, h2 := screen.Size() op := &ebiten.DrawImageOptions{} op.GeoM.Translate(float64(-w+w2)/2, float64(-h+h2)/2) if err := screen.DrawImage(gophersImage, op); err != nil { return err } x, y := ebiten.CursorPosition() msg := fmt.Sprintf(`Press arrow keys to change the window size Press S key to change the window scale Cursor: (%d, %d) FPS: %0.2f`, x, y, ebiten.CurrentFPS()) ebitenutil.DebugPrint(screen, msg) return nil }
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 }
func (p *Player) updateBar() error { if p.audioPlayer == nil { return nil } if !ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { mouseButtonState[ebiten.MouseButtonLeft] = 0 return nil } mouseButtonState[ebiten.MouseButtonLeft]++ if mouseButtonState[ebiten.MouseButtonLeft] != 1 { return nil } x, y := ebiten.CursorPosition() bx, by, bw, bh := playerBarRect() const padding = 4 if y < by-padding || by+bh+padding <= y { return nil } if x < bx || bx+bw <= x { return nil } pos := time.Duration(x-bx) * p.total / time.Duration(bw) return p.audioPlayer.Seek(pos) }