games.pdbrec.com業務連絡 20190410
とりあえず、
-------
package gameos
import (
"fmt"
"os"
"github.com/veandco/go-sdl2/sdl"
"github.com/veandco/go-sdl2/img"
)
var texture []*sdl.Texture // スライス化
func ImageMake (no int) {
texture = make([]*sdl.Texture, no)
}
func ImageDelete() {
for i := range texture {
if texture[i] != nil {
texture[i].Destroy()
}
}
}
func ImageLoad (no int, imageName string) {
image, err := img.Load(imageName)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load PNG: %s\n", err)
os.Exit(3)
}
defer image.Free()
if texture[no] != nil {
texture[no].Destroy()
}
texture[no], err = renderer.CreateTextureFromSurface(image)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", err)
os.Exit(4)
}
}
func ImageCopy(no int, x int32, y int32, xx int32, yy int32,
mx int32, my int32, mxx int32, myy int32) {
renderer.Copy(texture[no], &sdl.Rect{x, y, xx, yy}, &sdl.Rect{mx, my, mxx, myy})
}
func ImageCopyFill(no int, x int32, y int32, xx int32, yy int32) {
renderer.Copy(texture[no], nil, &sdl.Rect{x, y, xx, yy})
}
-------
Go言語でSDLで画像処理を行うライブラリ
Go言語はメモリを押さえてから処理を行うのが普通なので、makeでtextureポインタのスライスのメモリを確保して、スライスへ読み込んで使っている
押さえているスライスのメモリを超えてPNG画像を読み込んでもGo言語ではエラーにはならないはず。でも、メモリの押さえ直しとガベージコレクタで処理速度が遅くなるはず
SDLの画像処理は基本的にはCopy処理のみなので、MSXのSCREEN5的な処理でゲームを作る。追加出来るとしたらスプライトシート処理だろうな
WASMの準備も少し進めた