mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 12:32:05 +01:00
examples/video: reduce video FPS
This commit is contained in:
parent
d3befbf89b
commit
6f3f58cb32
@ -31,9 +31,17 @@ var shibuya_mpg []byte
|
|||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
player *mpegPlayer
|
player *mpegPlayer
|
||||||
|
|
||||||
|
counter int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
|
// Update the video player once per two ticks.
|
||||||
|
// This indicates to play the video in 30 FPS.
|
||||||
|
if g.counter % 2 == 0 {
|
||||||
|
g.player.Update()
|
||||||
|
}
|
||||||
|
g.counter++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +85,7 @@ func newMPEGPlayer(src io.Reader) (*mpegPlayer, error) {
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateFrame upadtes the current video frame.
|
func (p *mpegPlayer) Update() {
|
||||||
func (p *mpegPlayer) updateFrame() {
|
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -119,7 +118,6 @@ func (p *mpegPlayer) updateFrame() {
|
|||||||
|
|
||||||
// Draw draws the current frame onto the given screen.
|
// Draw draws the current frame onto the given screen.
|
||||||
func (p *mpegPlayer) Draw(screen *ebiten.Image) {
|
func (p *mpegPlayer) Draw(screen *ebiten.Image) {
|
||||||
p.updateFrame()
|
|
||||||
frame := p.currentFrame
|
frame := p.currentFrame
|
||||||
sw, sh := screen.Bounds().Dx(), screen.Bounds().Dy()
|
sw, sh := screen.Bounds().Dx(), screen.Bounds().Dy()
|
||||||
fw, fh := frame.Bounds().Dx(), frame.Bounds().Dy()
|
fw, fh := frame.Bounds().Dx(), frame.Bounds().Dy()
|
||||||
|
Loading…
Reference in New Issue
Block a user