main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2018 The Ebiten Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "fmt"
  17. "image/color"
  18. "log"
  19. "github.com/hajimehoshi/ebiten/v2"
  20. "github.com/hajimehoshi/ebiten/v2/ebitenutil"
  21. )
  22. var pointerImage = ebiten.NewImage(8, 8)
  23. func init() {
  24. pointerImage.Fill(color.RGBA{0xff, 0, 0, 0xff})
  25. }
  26. const (
  27. screenWidth = 640
  28. screenHeight = 480
  29. )
  30. type Game struct {
  31. x float64
  32. y float64
  33. }
  34. func (g *Game) Update() error {
  35. dx, dy := ebiten.Wheel()
  36. g.x += dx
  37. g.y += dy
  38. return nil
  39. }
  40. func (g *Game) Draw(screen *ebiten.Image) {
  41. op := &ebiten.DrawImageOptions{}
  42. op.GeoM.Translate(g.x, g.y)
  43. op.GeoM.Translate(screenWidth/2, screenHeight/2)
  44. screen.DrawImage(pointerImage, op)
  45. ebitenutil.DebugPrint(screen,
  46. fmt.Sprintf("Move the red point by mouse wheel\n(%0.2f, %0.2f)", g.x, g.y))
  47. }
  48. func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
  49. return screenWidth, screenHeight
  50. }
  51. func main() {
  52. g := &Game{x: 0.0, y: 0.0}
  53. ebiten.SetWindowSize(screenWidth, screenHeight)
  54. ebiten.SetWindowTitle("Wheel (Ebitengine Demo)")
  55. if err := ebiten.RunGame(g); err != nil {
  56. log.Fatal(err)
  57. }
  58. }