Remove ebiten.FPS

This commit is contained in:
Hajime Hoshi 2013-11-23 19:51:24 +09:00
parent cc7b78bb9a
commit bcb8c0d45a
4 changed files with 13 additions and 13 deletions

View File

@ -4,10 +4,6 @@ import (
"github.com/hajimehoshi/go-ebiten/graphics" "github.com/hajimehoshi/go-ebiten/graphics"
) )
const (
FPS = 60
)
type Game interface { type Game interface {
InitTextures(tf graphics.TextureFactory) InitTextures(tf graphics.TextureFactory)
Update(context GameContext) Update(context GameContext)

View File

@ -61,27 +61,28 @@ func mean(a, b matrix.Color, k float64) matrix.Color {
} }
func (game *Monochrome) update() { func (game *Monochrome) update() {
const fps = 60
colorI := matrix.IdentityColor() colorI := matrix.IdentityColor()
colorMonochrome := matrix.Monochrome() colorMonochrome := matrix.Monochrome()
for { for {
for i := 0; i < ebiten.FPS; i++ { for i := 0; i < fps; i++ {
<-game.ch <-game.ch
rate := float64(i) / float64(ebiten.FPS) rate := float64(i) / float64(fps)
game.colorMatrix = mean(colorI, colorMonochrome, rate) game.colorMatrix = mean(colorI, colorMonochrome, rate)
game.ch <- true game.ch <- true
} }
for i := 0; i < ebiten.FPS; i++ { for i := 0; i < fps; i++ {
<-game.ch <-game.ch
game.colorMatrix = colorMonochrome game.colorMatrix = colorMonochrome
game.ch <- true game.ch <- true
} }
for i := 0; i < ebiten.FPS; i++ { for i := 0; i < fps; i++ {
<-game.ch <-game.ch
rate := float64(i) / float64(ebiten.FPS) rate := float64(i) / float64(fps)
game.colorMatrix = mean(colorMonochrome, colorI, rate) game.colorMatrix = mean(colorMonochrome, colorI, rate)
game.ch <- true game.ch <- true
} }
for i := 0; i < ebiten.FPS; i++ { for i := 0; i < fps; i++ {
<-game.ch <-game.ch
game.colorMatrix = colorI game.colorMatrix = colorI
game.ch <- true game.ch <- true

View File

@ -42,12 +42,14 @@ func (game *Rotating) InitTextures(tf graphics.TextureFactory) {
} }
func (game *Rotating) Update(context ebiten.GameContext) { func (game *Rotating) Update(context ebiten.GameContext) {
const fps = 60
game.x++ game.x++
game.geometryMatrix = matrix.IdentityGeometry() game.geometryMatrix = matrix.IdentityGeometry()
tx, ty := float64(ebitenTextureWidth), float64(ebitenTextureHeight) tx, ty := float64(ebitenTextureWidth), float64(ebitenTextureHeight)
game.geometryMatrix.Translate(-tx/2, -ty/2) game.geometryMatrix.Translate(-tx/2, -ty/2)
game.geometryMatrix.Rotate(float64(game.x) * 2 * math.Pi / float64(ebiten.FPS*10)) game.geometryMatrix.Rotate(float64(game.x) * 2 * math.Pi / float64(fps*10))
game.geometryMatrix.Translate(tx/2, ty/2) game.geometryMatrix.Translate(tx/2, ty/2)
centerX := float64(context.ScreenWidth()) / 2 centerX := float64(context.ScreenWidth()) / 2
centerY := float64(context.ScreenHeight()) / 2 centerY := float64(context.ScreenHeight()) / 2

View File

@ -48,15 +48,16 @@ func main() {
const screenWidth = 256 const screenWidth = 256
const screenHeight = 240 const screenHeight = 240
const screenScale = 2 const screenScale = 2
const fps = 60
const title = "Ebiten Demo" const title = "Ebiten Demo"
ui := cocoa.New(screenWidth, screenHeight, screenScale, title) ui := cocoa.New(screenWidth, screenHeight, screenScale, title)
ui.Start() ui.Start()
ui.InitTextures(game.InitTextures) ui.InitTextures(game.InitTextures)
frameTime := time.Duration(int64(time.Second) / int64(ebiten.FPS))
tick := time.Tick(frameTime)
lock := sync.Mutex{} lock := sync.Mutex{}
go func() { go func() {
frameTime := time.Duration(int64(time.Second) / int64(fps))
tick := time.Tick(frameTime)
for { for {
<-tick <-tick
ui.Update(func(c ebiten.GameContext) { ui.Update(func(c ebiten.GameContext) {