mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-09 09:24:43 +01:00
Remove Game.Fps()
This commit is contained in:
parent
a35c74790c
commit
55331e2453
@ -24,10 +24,13 @@ import (
|
|||||||
"github.com/hajimehoshi/go.ebiten/graphics"
|
"github.com/hajimehoshi/go.ebiten/graphics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
FPS = 60
|
||||||
|
)
|
||||||
|
|
||||||
type Game interface {
|
type Game interface {
|
||||||
ScreenWidth() int
|
ScreenWidth() int
|
||||||
ScreenHeight() int
|
ScreenHeight() int
|
||||||
Fps() int
|
|
||||||
Init(tf graphics.TextureFactory)
|
Init(tf graphics.TextureFactory)
|
||||||
Update(context GameContext)
|
Update(context GameContext)
|
||||||
Draw(context graphics.Context)
|
Draw(context graphics.Context)
|
||||||
|
@ -40,10 +40,6 @@ func (game *Blank) ScreenHeight() int {
|
|||||||
return 240
|
return 240
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Blank) Fps() int {
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Blank) Init(tf graphics.TextureFactory) {
|
func (game *Blank) Init(tf graphics.TextureFactory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,10 +47,6 @@ func (game *Input) ScreenHeight() int {
|
|||||||
return 240
|
return 240
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Input) Fps() int {
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Input) Init(tf graphics.TextureFactory) {
|
func (game *Input) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/text.png")
|
file, err := os.Open("images/text.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,10 +51,6 @@ func (game *Monochrome) ScreenHeight() int {
|
|||||||
return 240
|
return 240
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Monochrome) Fps() int {
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Monochrome) Init(tf graphics.TextureFactory) {
|
func (game *Monochrome) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/ebiten.png")
|
file, err := os.Open("images/ebiten.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,24 +86,24 @@ func (game *Monochrome) update() {
|
|||||||
colorI := matrix.IdentityColor()
|
colorI := matrix.IdentityColor()
|
||||||
colorMonochrome := matrix.Monochrome()
|
colorMonochrome := matrix.Monochrome()
|
||||||
for {
|
for {
|
||||||
for i := 0; i < game.Fps(); i++ {
|
for i := 0; i < ebiten.FPS; i++ {
|
||||||
<-game.ch
|
<-game.ch
|
||||||
rate := float64(i) / float64(game.Fps())
|
rate := float64(i) / float64(ebiten.FPS)
|
||||||
game.colorMatrix = mean(colorI, colorMonochrome, rate)
|
game.colorMatrix = mean(colorI, colorMonochrome, rate)
|
||||||
game.ch <- true
|
game.ch <- true
|
||||||
}
|
}
|
||||||
for i := 0; i < game.Fps(); i++ {
|
for i := 0; i < ebiten.FPS; i++ {
|
||||||
<-game.ch
|
<-game.ch
|
||||||
game.colorMatrix = colorMonochrome
|
game.colorMatrix = colorMonochrome
|
||||||
game.ch <- true
|
game.ch <- true
|
||||||
}
|
}
|
||||||
for i := 0; i < game.Fps(); i++ {
|
for i := 0; i < ebiten.FPS; i++ {
|
||||||
<-game.ch
|
<-game.ch
|
||||||
rate := float64(i) / float64(game.Fps())
|
rate := float64(i) / float64(ebiten.FPS)
|
||||||
game.colorMatrix = mean(colorMonochrome, colorI, rate)
|
game.colorMatrix = mean(colorMonochrome, colorI, rate)
|
||||||
game.ch <- true
|
game.ch <- true
|
||||||
}
|
}
|
||||||
for i := 0; i < game.Fps(); i++ {
|
for i := 0; i < ebiten.FPS; i++ {
|
||||||
<-game.ch
|
<-game.ch
|
||||||
game.colorMatrix = colorI
|
game.colorMatrix = colorI
|
||||||
game.ch <- true
|
game.ch <- true
|
||||||
|
@ -45,10 +45,6 @@ func (game *Rects) ScreenHeight() int {
|
|||||||
return 240
|
return 240
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Fps() int {
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Rects) Init(tf graphics.TextureFactory) {
|
func (game *Rects) Init(tf graphics.TextureFactory) {
|
||||||
game.rectsTexture = tf.NewTexture(game.ScreenWidth(), game.ScreenHeight())
|
game.rectsTexture = tf.NewTexture(game.ScreenWidth(), game.ScreenHeight())
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,6 @@ func (game *Rotating) ScreenHeight() int {
|
|||||||
return 240
|
return 240
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rotating) Fps() int {
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Rotating) Init(tf graphics.TextureFactory) {
|
func (game *Rotating) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/ebiten.png")
|
file, err := os.Open("images/ebiten.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -78,7 +74,7 @@ func (game *Rotating) Draw(g graphics.Context) {
|
|||||||
geometryMatrix := matrix.IdentityGeometry()
|
geometryMatrix := matrix.IdentityGeometry()
|
||||||
tx, ty := float64(game.ebitenTexture.Width()), float64(game.ebitenTexture.Height())
|
tx, ty := float64(game.ebitenTexture.Width()), float64(game.ebitenTexture.Height())
|
||||||
geometryMatrix.Translate(-tx/2, -ty/2)
|
geometryMatrix.Translate(-tx/2, -ty/2)
|
||||||
geometryMatrix.Rotate(float64(game.x) * 2 * math.Pi / float64(game.Fps()*10))
|
geometryMatrix.Rotate(float64(game.x) * 2 * math.Pi / float64(ebiten.FPS*10))
|
||||||
geometryMatrix.Translate(tx/2, ty/2)
|
geometryMatrix.Translate(tx/2, ty/2)
|
||||||
centerX := float64(game.ScreenWidth()) / 2
|
centerX := float64(game.ScreenWidth()) / 2
|
||||||
centerY := float64(game.ScreenHeight()) / 2
|
centerY := float64(game.ScreenHeight()) / 2
|
||||||
|
@ -96,10 +96,6 @@ func (game *Sprites) ScreenHeight() int {
|
|||||||
return 240
|
return 240
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Sprites) Fps() int {
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Sprites) Init(tf graphics.TextureFactory) {
|
func (game *Sprites) Init(tf graphics.TextureFactory) {
|
||||||
file, err := os.Open("images/ebiten.png")
|
file, err := os.Open("images/ebiten.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,10 +41,6 @@ func (game *Terminate) ScreenHeight() int {
|
|||||||
return 240
|
return 240
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Terminate) Fps() int {
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
|
|
||||||
func (game *Terminate) Init(tf graphics.TextureFactory) {
|
func (game *Terminate) Init(tf graphics.TextureFactory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ func Run(game ebiten.Game, screenScale int, title string) {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
frameTime := time.Duration(
|
frameTime := time.Duration(
|
||||||
int64(time.Second) / int64(game.Fps()))
|
int64(time.Second) / int64(ebiten.FPS))
|
||||||
tick := time.Tick(frameTime)
|
tick := time.Tick(frameTime)
|
||||||
gameContext := &GameContext{
|
gameContext := &GameContext{
|
||||||
inputState: ebiten.InputState{-1, -1},
|
inputState: ebiten.InputState{-1, -1},
|
||||||
|
Loading…
Reference in New Issue
Block a user