mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 01:42:05 +01:00
Remove ebiten.FPS
This commit is contained in:
parent
cc7b78bb9a
commit
bcb8c0d45a
@ -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)
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user