mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
examples/sprites: Accept touches
This commit is contained in:
parent
bf07ead6ae
commit
87bc2e6f02
@ -134,9 +134,29 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func leftTouched() bool {
|
||||||
|
for _, id := range ebiten.TouchIDs() {
|
||||||
|
x, _ := ebiten.TouchPosition(id)
|
||||||
|
if x < screenWidth/2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func rightTouched() bool {
|
||||||
|
for _, id := range ebiten.TouchIDs() {
|
||||||
|
x, _ := ebiten.TouchPosition(id)
|
||||||
|
if x >= screenWidth/2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
// Decrease the nubmer of the sprites.
|
// Decrease the nubmer of the sprites.
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
if ebiten.IsKeyPressed(ebiten.KeyLeft) || leftTouched() {
|
||||||
sprites.num -= 20
|
sprites.num -= 20
|
||||||
if sprites.num < MinSprites {
|
if sprites.num < MinSprites {
|
||||||
sprites.num = MinSprites
|
sprites.num = MinSprites
|
||||||
@ -144,7 +164,7 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Increase the nubmer of the sprites.
|
// Increase the nubmer of the sprites.
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyRight) {
|
if ebiten.IsKeyPressed(ebiten.KeyRight) || rightTouched() {
|
||||||
sprites.num += 20
|
sprites.num += 20
|
||||||
if MaxSprites < sprites.num {
|
if MaxSprites < sprites.num {
|
||||||
sprites.num = MaxSprites
|
sprites.num = MaxSprites
|
||||||
|
Loading…
Reference in New Issue
Block a user