Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#builder#300 default animtion bug #304

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ type Sprite struct {
hasOnCloned bool
hasOnTouched bool

gamer reflect.Value
lastAnim *anim.Anim
gamer reflect.Value
lastAnim *anim.Anim
isWaitingStopAnim bool
}

func (p *Sprite) SetDying() { // dying: visible but can't be touched
Expand Down Expand Up @@ -193,12 +194,9 @@ func (p *Sprite) init(
}
}
func (p *Sprite) awake() {
if p.defaultAnimation != "" {
if p.isVisible {
p.Animate(p.defaultAnimation)
}
}
p.playDefaultAnim()
}

func (p *Sprite) InitFrom(src *Sprite) {
p.baseObj.initFrom(&src.baseObj)
p.eventSinks.initFrom(&src.eventSinks, p)
Expand Down Expand Up @@ -592,7 +590,9 @@ func lerp(a float64, b float64, progress float64) float64 {

func (p *Sprite) goAnimate(name string, ani *aniConfig) {
if p.lastAnim != nil {
p.isWaitingStopAnim = true
p.lastAnim.Stop()
p.isWaitingStopAnim = false
}
var animwg sync.WaitGroup
animwg.Add(1)
Expand Down Expand Up @@ -715,12 +715,19 @@ func (p *Sprite) goAnimate(name string, ani *aniConfig) {
}
}
})
isNeedPlayDefault := false
an.SetOnStopingListener(func() {
if debugInstr {
log.Printf("stop anim [name %s id %d] ", an.Name, an.Id)
}
animwg.Done()
p.lastAnim = nil
if !p.isWaitingStopAnim && name != p.defaultAnimation && p.isVisible {
dieAnimName := p.getStateAnimName(StateDie)
if name != dieAnimName {
isNeedPlayDefault = true
}
}
})

var h *tickHandler
Expand All @@ -731,6 +738,9 @@ func (p *Sprite) goAnimate(name string, ani *aniConfig) {
}
})
waitToDo(animwg.Wait)
if isNeedPlayDefault {
p.playDefaultAnim()
Copy link
Collaborator

@nighca nighca Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no default animation (the sprite has its current costume). We should use the "current costume" of sprite instead of the last costume of the animation?

}
}

func (p *Sprite) Animate(name string) {
Expand Down Expand Up @@ -870,6 +880,17 @@ func (p *Sprite) Step__2(step float64, animname string) {
p.goMoveForward(step)
}

func (p *Sprite) playDefaultAnim() {
animName := p.defaultAnimation
if animName != "" && p.isVisible {
if ani, ok := p.animations[animName]; ok {
anicopy := *ani
anicopy.IsLoop = true
p.goAnimate(animName, &anicopy)
}
}
}

// Goto func:
//
// Goto(sprite)
Expand Down
Binary file added tutorial/07-Camera/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions tutorial/07-Camera/Bullet.spx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
onCloned => {
setXYpos MyAircraft.xpos, MyAircraft.ypos+5
show
for {
wait 0.04
step 10
if touching(Edge) {
destroy
}
}
}
17 changes: 17 additions & 0 deletions tutorial/07-Camera/MyAircraft.spx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "math"
onStart => {
setXYpos 0, 0
for {
wait 0.1
Bullet.clone
}
}

onStart => {
setXYpos 0, 0
Camera.setXYpos 0, 0
for {
wait 0.03
setXYpos mouseX, mouseY
}
}
Binary file added tutorial/07-Camera/assets/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tutorial/07-Camera/assets/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"backdrops": [
{
"bitmapResolution": 2,
"name": "backdrop1",
"path": "1.png"
}
],
"map": { "width": 240, "height": 240 },
"run": { "width": 720, "height": 720 },
"zorder": [
"MyAircraft",
"Bullet"
]
}
Binary file added tutorial/07-Camera/assets/sprites/Bullet/30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions tutorial/07-Camera/assets/sprites/Bullet/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"costumes": [
{
"bitmapResolution": 2,
"name": "bullet",
"path": "30.png",
"faceRight": 90,
"x": 8,
"y": 20
}
],
"costumeIndex": 0,
"heading": 0,
"isDraggable": false,
"rotationStyle": "normal",
"size": 0.65,
"visible": false,
"x": 230,
"y": 185
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions tutorial/07-Camera/assets/sprites/MyAircraft/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"costumes": [
{
"bitmapResolution": 2,
"name": "hero",
"path": "8.png",
"x": 98,
"y": 122
}
],
"costumeIndex": 0,
"heading": 90,
"isDraggable": false,
"rotationStyle": "normal",
"size": 0.45,
"visible": true,
"x": -131,
"y": -161
}
4 changes: 4 additions & 0 deletions tutorial/07-Camera/main.spx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var (
MyAircraft MyAircraft
Bullet Bullet
)
Empty file added tutorial/09-LoopAnim/Bullet.spx
Empty file.
6 changes: 6 additions & 0 deletions tutorial/09-LoopAnim/SmallEnemy.spx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
onStart => {
setXYpos 0,0
show
wait 1
animate "die"
}
Binary file added tutorial/09-LoopAnim/assets/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tutorial/09-LoopAnim/assets/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"backdrops": [
{
"bitmapResolution": 2,
"name": "backdrop1",
"path": "1.png"
}
],
"zorder": [
"Bullet",
"SmallEnemy"
]
}
Binary file added tutorial/09-LoopAnim/assets/sounds/explode/1.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions tutorial/09-LoopAnim/assets/sounds/explode/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "1.wav"
}
Binary file added tutorial/09-LoopAnim/assets/sprites/Bullet/30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions tutorial/09-LoopAnim/assets/sprites/Bullet/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"costumes": [
{
"bitmapResolution": 2,
"name": "bullet",
"path": "30.png",
"faceRight": 90,
"x": 8,
"y": 20
}
],
"costumeIndex": 0,
"heading": 0,
"isDraggable": false,
"rotationStyle": "normal",
"size": 0.65,
"visible": false,
"x": 230,
"y": 185
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions tutorial/09-LoopAnim/assets/sprites/SmallEnemy/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"costumes": [
{
"bitmapResolution": 2,
"name": "normal",
"path": "32.png",
"x": 50,
"y": 36
},
{
"bitmapResolution": 2,
"name": "die-0",
"path": "33.png",
"x": 50,
"y": 36
},
{
"bitmapResolution": 2,
"name": "die-1",
"path": "34.png",
"x": 50,
"y": 44
},
{
"bitmapResolution": 2,
"name": "die-2",
"path": "35.png",
"x": 56,
"y": 50
},
{
"bitmapResolution": 2,
"name": "die-3",
"path": "36.png",
"x": 44,
"y": 38
}
],
"costumeIndex": 0,
"fAnimations": {
"die": {
"duration": 0.2,
"from": "die-0",
"to": "die-3",
"isLoop": true
}
},
"defaultAnimation": "init",
"heading": 90,
"isDraggable": false,
"rotationStyle": "normal",
"size": 0.65,
"visible": false,
"x": -58,
"y": -179
}
4 changes: 4 additions & 0 deletions tutorial/09-LoopAnim/main.spx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var (
explode Sound
Bullet Bullet
)
27 changes: 27 additions & 0 deletions tutorial/10-PivotPoint/Calf.spx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import "math"
onStart => {
say "Hello Go+"
updateInterval := 0.03
timer := 0.0
setXYpos 0, 0
for timer < 3{
timer += updateInterval
wait updateInterval
setXYpos mouseX, mouseY
}
timer=0.0
for timer < 3{
timer += updateInterval
wait updateInterval
setHeading timer*60

sin, _ := math.Sincos(timer*90 * math.Pi / 180)
setSize(sin*0.5+1.5)
}
timer=0.0
for timer < 5{
timer += updateInterval
wait updateInterval
step 40*updateInterval
}
}
9 changes: 9 additions & 0 deletions tutorial/10-PivotPoint/assets/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"map": {
"width": 480,
"height": 360
},
"zorder": [
"Calf"
]
}
Binary file added tutorial/10-PivotPoint/assets/sprites/Calf/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions tutorial/10-PivotPoint/assets/sprites/Calf/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"costumes": [
{
"bitmapResolution": 2,
"name": "calf-0",
"path": "1.png",
"x": 55,
"y": 50
}
],
"pivot":{
"x": 0,
"y": -25
},
"costumeIndex": 0,
"heading": 90,
"isDraggable": false,
"rotationStyle": "normal",
"size": 1,
"visible": true,
"x": -59,
"y": 2
}
22 changes: 22 additions & 0 deletions tutorial/11_MutilScene/Bullet.spx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
onTouched => {
destroy
}

onStart => {
for {
wait 0.3
clone
}
}

onCloned => {
setXYpos mouseX, mouseY
show
for {
wait 0.04
step 10
if touching(Edge) {
destroy
}
}
}
Loading
Loading