Ebitengine v2 Migration Guide

Overview

Ebitengine v2 is a major version update from v1. There are some breaking changes in the API. Thus, you have to update the program in order to migrate to Ebitengine v2.

This document lists the action items for the migration to Ebitengine v2.

We don't add drastic changes to v2. Instead, we plan to add quiet changes.

Platforms

Action items

Updating the import paths

Update all the github.com/hajimehoshi/ebiten in import to github.com/hajimehoshi/ebiten/v2. github.com/hajimehoshi/ebiten/text will be github.com/hajimehoshi/ebiten/v2/text.

Lastly, execute go mod tidy command so that your go.mod will include github.com/hajimehoshi/ebiten/v2 and exclude github.com/hajimehoshi/ebiten.

You cannot mix Ebitengine v1 and v2 for one application. If you run go mod tidy but there are both version in your go.mod, confirm the dependency relationships and remove the dependency on v1. However, you don't have to do it if you intentionally manage multiple applications in one module.

Updating the API usages

github.com/hajimehoshi/ebiten

These types are introduced.

These APIs' signatures are changed.

v1v2
func GamepadAxisNum(id int, axis int) intfunc GamepadAxisNum(id GamepadID, axis int) int
func GamepadAxisNum(id int) intfunc GamepadAxisNum(id GamepadID) int
func GamepadButtonNum(id int) intfunc GamepadButtonNum(id GamepadID) int
func GamepadIDs() []intfunc GamepadIDs() []GamepadID
func GamepadName(id int) stringfunc GamepadName(id GamepadID) string
func GamepadSDLID(id int) stringfunc GamepadSDLID(id GamepadID) string
func (*Image).Clear() errorfunc (*Image).Clear()
func (*Image).Dispose() errorfunc (*Image).Dispose()
func (*Image).DrawImage(img *Image, options *DrawImageOptions) errorfunc (*Image).DrawImage(img *Image, options *DrawImageOptions)
func (*Image).Fill(clr color.Color) errorfunc (*Image).Fill(clr color.Color)
func (*Image).ReplacePixels(pixels []byte) errorfunc (*Image).ReplacePixels(pixels []byte)
func IsGamepadButtonPressed(id int, button GamepadButton) boolfunc IsGamepadButtonPressed(id GamepadID, button GamepadButton) bool
func NewImage(width, height int, filter Filter) (*Image, error)func NewImage(width, height int) *Image
func NewImageFromImage(source image.Image, filter Filter) (*Image, error)func NewImageFromImage(source image.Image) *Image
func TouchIDs() []intfunc TouchIDs() []TouchID
func TouchPosition(id int) (int, int)func TouchPosition(id TouchID) (int, int)

These APIs are removed or replaced.

v1v2
const FilterDefault(No replacement)
const FPS(No replacement)
const MaxImageSize(No replacement)
struct DrawImageOptions's ImagePartsfunc (*Image).SubImage
struct DrawImageOptions's Partsfunc (*Image).SubImage
struct DrawImageOptions's SourceRectfunc (*Image).SubImage
interface Touchfunc TouchPosition
func (*ColorM).Add(No replacement)
func (*GeoM).Add(No replacement)
func IsCursorVisiblefunc CursorMode
func IsDrawingSkippedfunc RunGame and interface Game's Draw
func IsRunningInBackgroundfunc IsRunnableOnUnfocused
func IsRunningSlowlyfunc RunGame and interface Game's Draw
func MonitorSizefunc ScreenSizeInFullscreen
func Monochromefunc (*ColorM).ChangeHSV with arguments 0, 0, 1
func RotateGeofunc (*GeoM).Rotate
func RotateHuefunc (*ColorM).RotateHue
func Runfunc RunGame
func ScaleColorfunc (*ColorM).Scale
func ScaleGeofunc (*GeoM).Scale
func ScreenScalefunc WindowSize
func SetCursorVisiblefunc SetCursorMode
func SetCursorVisibilityfunc SetCursorMode
func SetRunningInBackgroundfunc SetRunnableOnUnfocused
func SetScreenScalefunc RunGame and interface Game's Layout
func SetScreenSizefunc RunGame and interface Game's Layout
func Touchesfunc TouchIDs
func TranslateColorfunc (*ColorM).Translate
func TranslateGeofunc (*GeoM).Translate

github.com/hajimehoshi/ebiten/audio

These APIs' signatures are changed.

v1v2
func NewContext(sampleRate int) (*Context, error)func NewContext(sampleRate int) *Context
func NewInfiniteLoop(src ReadSeekCloser, length int64) *InfiniteLoopfunc NewInfiniteLoop(src io.ReadSeeker, length int64) *InfiniteLoop
func NewInfiniteLoopWithIntro(src ReadSeekCloser, introLength int64, loopLength int64) *InfiniteLoopfunc NewInfiniteLoopWithIntro(src io.ReadSeeker, introLength int64, loopLength int64) *InfiniteLoop
func NewPlayer(context *Context, src io.ReadCloser) (*Player, error)func NewPlayer(context *Context, src io.Reader) (*Player, error)
func NewPlayerFromBytes(context *Context, src []byte) (*Player, error)func NewPlayerFromBytes(context *Context, src []byte) *Player
func (*Player).Pause() errorfunc (*Player).Pause()
func (*Player).Play() errorfunc (*Player).Play()

These APIs are removed or replaced.

v1v2
BytesReadSeekCloser(No replacement, but bytes.NewReader works in most cases)
func (*Context).Update(No replacement)
ReadSeekCloser(No replacement, but io.ReadSeeker works in most cases)

github.com/hajimehoshi/ebiten/audio/mp3

These APIs' signatures are changed.

v1v2
func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error)func Decode(context *audio.Context, src io.ReadSeeker) (*Stream, error)

These APIs are removed or replaced.

v1v2
func (*Stream).Close(No replacement)
func (*Stream).Sizefunc (*Stream).Length

github.com/hajimehoshi/ebiten/audio/vorbis

These APIs' signatures are changed.

v1v2
func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error)func Decode(context *audio.Context, src io.ReadSeeker) (*Stream, error)

These APIs are removed or replaced.

v1v2
func (*Stream).Close(No replacement)
func (*Stream).Sizefunc (*Stream).Length

github.com/hajimehoshi/ebiten/audio/wav

These APIs' signatures are changed.

v1v2
func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error)func Decode(context *audio.Context, src io.ReadSeeker) (*Stream, error)

These APIs are removed or replaced.

v1v2
func (*Stream).Close(No replacement)
func (*Stream).Sizefunc (*Stream).Length

github.com/hajimehoshi/ebiten/ebitenutil

These APIs' signatures are changed.

v1v2
func DebugPrint(image *ebiten.Image, str string) errorfunc DebugPrint(image *ebiten.Image, str string)

github.com/hajimehoshi/ebiten/inpututil

These APIs' signatures are changed.

v1v2
func GamepadButtonPressDuration(id int, button ebiten.GamepadButton) intfunc GamepadButtonPressDuration(id ebiten.GamepadID, button ebiten.GamepadButton) int
func IsGamepadButtonJustPressed(id int, button ebiten.GamepadButton) boolfunc IsGamepadButtonJustPressed(id ebiten.GamepadID, button ebiten.GamepadButton) bool
func IsGamepadButtonJustReleased(id int, button ebiten.GamepadButton) boolfunc IsGamepadButtonJustReleased(id ebiten.GamepadID, button ebiten.GamepadButton) bool
func IsGamepadJustDisconnected(id int) boolfunc IsGamepadJustDisconnected(id ebiten.GamepadID) bool
func IsTouchJustReleased(id int) boolfunc IsTouchJustReleased(id ebiten.TouchID) bool
func JustConnectedGamepadIDs() []intfunc JustConnectedGamepadIDs() []ebiten.GamepadID
func JustPressedTouchIDs() []intfunc JustPressedTouchIDs() []ebiten.TouchID
func TouchPressDuration(id int) intfunc TouchPressDuration(id ebiten.TouchID) int

github.com/hajimehoshi/ebiten/mobile

These APIs are removed or replaced.

v1v2
interface Gameebiten's interface Game
func Startebitenmobile command and func SetGame
func Updateebitenmobile command and func SetGame
func UpdateTouchesOnAndroidebitenmobile command
func UpdateTouchesOnIOSebitenmobile command