mirror of
https://github.com/stevenhowes/GoRetro.git
synced 2026-05-27 00:03:29 +01:00
Some error handling and re-enable sequence changes
This commit is contained in:
+19
-7
@@ -30,14 +30,14 @@ func NewAnimator(
|
|||||||
imagepath string,
|
imagepath string,
|
||||||
sequences map[string]*Sequence,
|
sequences map[string]*Sequence,
|
||||||
defaultSequence string,
|
defaultSequence string,
|
||||||
renderer *sdl.Renderer) *animator {
|
renderer *sdl.Renderer) (*animator, error) {
|
||||||
var an animator
|
var an animator
|
||||||
|
|
||||||
imagepath = Config.DataDir + imagepath
|
imagepath = Config.DataDir + imagepath
|
||||||
|
|
||||||
tex, err := loadTextureFromBMP(imagepath, renderer)
|
tex, err := loadTextureFromBMP(imagepath, renderer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("texture err ", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
an.tex = tex
|
an.tex = tex
|
||||||
@@ -46,7 +46,7 @@ func NewAnimator(
|
|||||||
an.current = defaultSequence
|
an.current = defaultSequence
|
||||||
an.lastFrameChange = time.Now()
|
an.lastFrameChange = time.Now()
|
||||||
|
|
||||||
return &an
|
return &an, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (an *animator) onUpdate() error {
|
func (an *animator) onUpdate() error {
|
||||||
@@ -80,7 +80,20 @@ func (an *animator) onCollision(other *Element) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (an *animator) setSequence(name string) bool {
|
func (an *animator) setSequence(name string) bool {
|
||||||
return false
|
_, ok := an.sequences[name]
|
||||||
|
if ok {
|
||||||
|
// If we *are* changing sequence, change the name and reset the frame
|
||||||
|
if an.current != name {
|
||||||
|
// Reset the old sequence to frame 0
|
||||||
|
sequence := an.sequences[an.current]
|
||||||
|
sequence.resetFrame()
|
||||||
|
|
||||||
|
// Use the new sequence
|
||||||
|
an.current = name
|
||||||
|
an.lastFrameChange = time.Now()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -110,12 +123,11 @@ func NewSequence(
|
|||||||
|
|
||||||
jsonFile, err := os.Open(indexpath)
|
jsonFile, err := os.Open(indexpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return nil, err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
jsonParser := json.NewDecoder(jsonFile)
|
jsonParser := json.NewDecoder(jsonFile)
|
||||||
if err = jsonParser.Decode(&seq.frames); err != nil {
|
if err = jsonParser.Decode(&seq.frames); err != nil {
|
||||||
fmt.Println("parser err ", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
defer jsonFile.Close()
|
defer jsonFile.Close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user