Exemplo n.º 1
0
func update(screen *ebiten.Image) error {
	if ebiten.IsKeyPressed(ebiten.KeyLeft) {
		sprites.num -= 20
		if sprites.num < MinSprites {
			sprites.num = MinSprites
		}
	}
	if ebiten.IsKeyPressed(ebiten.KeyRight) {
		sprites.num += 20
		if MaxSprites < sprites.num {
			sprites.num = MaxSprites
		}
	}
	sprites.Update()

	if ebiten.IsRunningSlowly() {
		return nil
	}
	op := &ebiten.DrawImageOptions{
		ImageParts: sprites,
	}
	op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
	if err := screen.DrawImage(ebitenImage, op); err != nil {
		return err
	}
	msg := fmt.Sprintf(`FPS: %0.2f
Num of sprites: %d
Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len())
	if err := ebitenutil.DebugPrint(screen, msg); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 2
0
func update(screen *ebiten.Image) error {
	if err := game.Update(); err != nil {
		return err
	}
	if ebiten.IsRunningSlowly() {
		return nil
	}
	if err := game.Draw(screen); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 3
0
func (game *Game) Update(r *ebiten.Image) error {
	game.input.Update()
	if err := game.sceneManager.Update(&GameState{
		SceneManager: game.sceneManager,
		Input:        &game.input,
	}); err != nil {
		return err
	}
	if !ebiten.IsRunningSlowly() {
		if err := game.sceneManager.Draw(r); err != nil {
			return err
		}
	}
	return nil
}