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

Add sprite interface: Name, OnTouchStart(sprite []SpriteName) #483

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
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
27 changes: 27 additions & 0 deletions sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type Sprite interface {
Move__0(step float64)
Move__1(step int)
NextCostume()
Name() string
OnCloned__0(onCloned func(data interface{}))
OnCloned__1(onCloned func())
OnMoving__0(onMoving func(mi *MovingInfo))
Expand All @@ -163,6 +164,8 @@ type Sprite interface {
OnTouchStart__1(onTouchStart func())
OnTouchStart__2(sprite SpriteName, onTouchStart func(Sprite))
OnTouchStart__3(sprite SpriteName, onTouchStart func())
OnTouchStart__4(sprite []SpriteName, onTouchStart func(Sprite))
OnTouchStart__5(sprite []SpriteName, onTouchStart func())
OnTurning__0(onTurning func(ti *TurningInfo))
OnTurning__1(onTurning func())
Parent() *Game
Expand Down Expand Up @@ -519,6 +522,10 @@ func Gopt_SpriteImpl_Clone__1(sprite Sprite, data interface{}) {
}
}

func (p *SpriteImpl) Name() string {
return p.name
}

func (p *SpriteImpl) OnCloned__0(onCloned func(data interface{})) {
p.hasOnCloned = true
p.allWhenCloned = &eventSink{
Expand Down Expand Up @@ -588,6 +595,26 @@ func (p *SpriteImpl) OnTouchStart__3(sprite SpriteName, onTouchStart func()) {
})
}

func (p *SpriteImpl) OnTouchStart__4(sprites []SpriteName, onTouchStart func(Sprite)) {
p.OnTouchStart__0(func(s Sprite) {
impl := spriteOf(s)
if impl != nil {
for _, spName := range sprites {
if impl.name == spName {
onTouchStart(s)
return
}
}
}
})
}

func (p *SpriteImpl) OnTouchStart__5(sprites []SpriteName, onTouchStart func()) {
p.OnTouchStart__4(sprites, func(Sprite) {
onTouchStart()
})
}

type MovingInfo struct {
OldX, OldY float64
NewX, NewY float64
Expand Down
Loading