ebiten/examples/wheel/main.go

74 lines
1.6 KiB
Go
Raw Normal View History

2018-09-30 10:03:40 +02:00
// Copyright 2018 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2020-10-06 17:45:54 +02:00
// +build example
2018-09-30 10:03:40 +02:00
package main
import (
2018-09-30 10:13:22 +02:00
"fmt"
2018-09-30 10:03:40 +02:00
"image/color"
"log"
2020-10-03 19:35:13 +02:00
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
2018-09-30 10:03:40 +02:00
)
var pointerImage = ebiten.NewImage(8, 8)
2018-09-30 10:03:40 +02:00
func init() {
pointerImage.Fill(color.RGBA{0xff, 0, 0, 0xff})
}
const (
screenWidth = 640
screenHeight = 480
2018-09-30 10:03:40 +02:00
)
type Game struct {
x float64
y float64
}
2018-09-30 10:03:40 +02:00
func (g *Game) Update() error {
2018-09-30 10:03:40 +02:00
dx, dy := ebiten.Wheel()
g.x += dx
g.y += dy
return nil
}
2018-09-30 10:03:40 +02:00
func (g *Game) Draw(screen *ebiten.Image) {
2018-09-30 10:03:40 +02:00
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(g.x, g.y)
2018-09-30 10:03:40 +02:00
op.GeoM.Translate(screenWidth/2, screenHeight/2)
screen.DrawImage(pointerImage, op)
2018-09-30 10:13:22 +02:00
ebitenutil.DebugPrint(screen,
fmt.Sprintf("Move the red point by mouse wheel\n(%0.2f, %0.2f)", g.x, g.y))
}
2018-09-30 10:03:40 +02:00
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
2018-09-30 10:03:40 +02:00
}
func main() {
g := &Game{x: 0.0, y: 0.0}
ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("Wheel (Ebiten Demo)")
if err := ebiten.RunGame(g); err != nil {
2018-09-30 10:03:40 +02:00
log.Fatal(err)
}
}