mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
parent
596efc86fe
commit
599571c7a7
@ -455,7 +455,7 @@ type GameWithCRTEffect struct {
|
||||
crtShader *ebiten.Shader
|
||||
}
|
||||
|
||||
func (g *GameWithCRTEffect) DrawFinalScreen(screen ebiten.FinalScreen, offscreen *ebiten.Image) {
|
||||
func (g *GameWithCRTEffect) DrawFinalScreen(screen ebiten.FinalScreen, offscreen *ebiten.Image, geoM ebiten.GeoM) {
|
||||
if g.crtShader == nil {
|
||||
s, err := ebiten.NewShader(crtGo)
|
||||
if err != nil {
|
||||
@ -465,11 +465,10 @@ func (g *GameWithCRTEffect) DrawFinalScreen(screen ebiten.FinalScreen, offscreen
|
||||
}
|
||||
|
||||
ow, oh := offscreen.Size()
|
||||
sw, sh := screen.Size()
|
||||
|
||||
op := &ebiten.DrawRectShaderOptions{}
|
||||
op.Images[0] = offscreen
|
||||
op.GeoM.Scale(float64(sw)/float64(ow), float64(sh)/float64(oh))
|
||||
op.GeoM = geoM
|
||||
screen.DrawRectShader(ow, oh, g.crtShader, op)
|
||||
}
|
||||
|
||||
|
17
gameforui.go
17
gameforui.go
@ -148,29 +148,30 @@ func (g *gameForUI) DrawOffscreen() error {
|
||||
}
|
||||
|
||||
func (g *gameForUI) DrawScreen() {
|
||||
scale, offsetX, offsetY := g.ScreenScaleAndOffsets()
|
||||
var geoM GeoM
|
||||
geoM.Scale(scale, scale)
|
||||
geoM.Translate(offsetX, offsetY)
|
||||
|
||||
if d, ok := g.game.(FinalScreenDrawer); ok {
|
||||
d.DrawFinalScreen(g.screen, g.offscreen)
|
||||
d.DrawFinalScreen(g.screen, g.offscreen, geoM)
|
||||
return
|
||||
}
|
||||
|
||||
scale, offsetX, offsetY := g.ScreenScaleAndOffsets()
|
||||
switch {
|
||||
case !isScreenFilterEnabled(), math.Floor(scale) == scale:
|
||||
op := &DrawImageOptions{}
|
||||
op.GeoM.Scale(scale, scale)
|
||||
op.GeoM.Translate(offsetX, offsetY)
|
||||
op.GeoM = geoM
|
||||
g.screen.DrawImage(g.offscreen, op)
|
||||
case scale < 1:
|
||||
op := &DrawImageOptions{}
|
||||
op.GeoM.Scale(scale, scale)
|
||||
op.GeoM.Translate(offsetX, offsetY)
|
||||
op.GeoM = geoM
|
||||
op.Filter = FilterLinear
|
||||
g.screen.DrawImage(g.offscreen, op)
|
||||
default:
|
||||
op := &DrawRectShaderOptions{}
|
||||
op.Images[0] = g.offscreen
|
||||
op.GeoM.Scale(scale, scale)
|
||||
op.GeoM.Translate(offsetX, offsetY)
|
||||
op.GeoM = geoM
|
||||
w, h := g.offscreen.Size()
|
||||
g.screen.DrawRectShader(w, h, g.screenShader, op)
|
||||
}
|
||||
|
6
run.go
6
run.go
@ -107,7 +107,11 @@ type FinalScreenDrawer interface {
|
||||
// DrawFinalScreen draws the final screen.
|
||||
// If a game implementing FinalScreenDrawer is passed to RunGame, DrawFinalScreen is called after Draw.
|
||||
// screen is the final screen. offscreen is the offscreen modified at Draw.
|
||||
DrawFinalScreen(screen FinalScreen, offscreen *Image)
|
||||
//
|
||||
// geoM is the default geometry matrix to render the offscreen onto the final screen.
|
||||
// geoM scales the offscreen to fit the final screen without changing the aspect ratio, and
|
||||
// translates the offscreen to put it on the center of the final screen.
|
||||
DrawFinalScreen(screen FinalScreen, offscreen *Image, geoM GeoM)
|
||||
}
|
||||
|
||||
// DefaultTPS represents a default ticks per second, that represents how many times game updating happens in a second.
|
||||
|
Loading…
Reference in New Issue
Block a user