spx

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2025 License: Apache-2.0 Imports: 46 Imported by: 15

README

spx - A Scratch Compatible 2D Game Engine

Build Status Go Report Card GitHub release Language Scratch diff

How to build

How to run games powered by XGo spx engine?

Games powered by spx

Tutorials

tutorial/01-Weather

Screen Shot1 Screen Shot2

Through this example you can learn how to listen events and do somethings.

Here are some codes in Kai.spx:

onStart => {
	say "Where do you come from?", 2
	broadcast "1"
}

onMsg "2", => {
	say "What's the climate like in your country?", 3
	broadcast "3"
}

onMsg "4", => {
	say "Which seasons do you like best?", 3
	broadcast "5"
}

We call onStart and onMsg to listen events. onStart is called when the program is started. And onMsg is called when someone calls broadcast to broadcast a message.

When the program starts, Kai says Where do you come from?, and then broadcasts the message 1. Who will recieve this message? Let's see codes in Jaime.spx:

onMsg "1", => {
	say "I come from England.", 2
	broadcast "2"
}

onMsg "3", => {
	say "It's mild, but it's not always pleasant.", 4
	# ...
	broadcast "4"
}

Yes, Jaime recieves the message 1 and says I come from England.. Then he broadcasts the message 2. Kai recieves it and says What's the climate like in your country?.

The following procedures are very similar. In this way you can implement dialogues between multiple actors.

tutorial/02-Dragon

Screen Shot1

Through this example you can learn how to define variables and show them on the stage.

Here are all the codes of Dragon:

var (
	score int
)

onStart => {
	score = 0
	for {
		turn rand(-30, 30)
		step 5
		if touching("Shark") {
			score++
			play chomp, true
			step -100
		}
	}
}

We define a variable named score for Dragon. After the program starts, it moves randomly. And every time it touches Shark, it gains one score.

How to show the score on the stage? You don't need write code, just add a stageMonitor object into assets/index.json:

{
  "zorder": [
    {
      "type": "monitor",
      "name": "dragon",
      "size": 1,
      "target": "Dragon",
      "val": "getVar:score",
      "color": 15629590,
      "label": "score",
      "mode": 1,
      "x": 5,
      "y": 5,
      "visible": true
    }
  ]
}
tutorial/03-Clone

Screen Shot1

Through this example you can learn:

  • Clone sprites and destory them.
  • Distinguish between sprite variables and shared variables that can access by all sprites.

Here are some codes in Calf.spx:

var (
	id int
)

onClick => {
	clone
}

onCloned => {
	gid++
	...
}

When we click the sprite Calf, it receives an onClick event. Then it calls clone to clone itself. And after cloning, the new Calf sprite will receive an onCloned event.

In onCloned event, the new Calf sprite uses a variable named gid. It doesn't define in Calf.spx, but in main.spx.

Here are all the codes of main.spx:

var (
	Arrow Arrow
	Calf  Calf
	gid   int
)

run "res", {Title: "Clone and Destory (by XGo)"}

All these three variables in main.spx are shared by all sprites. Arrow and Calf are sprites that exist in this project. gid means global id. It is used to allocate id for all cloned Calf sprites.

Let's back to Calf.spx to see the full codes of onCloned:

onCloned => {
	gid++
	id = gid
	step 50
	say id, 0.5
}

It increases gid value and assigns it to sprite id. This makes all these Calf sprites have different id. Then the cloned Calf moves forward 50 steps and says id of itself.

Why these Calf sprites need different id? Because we want destory one of them by its id.

Here are all the codes in Arrow.spx:

onClick => {
	broadcast "undo", true
	gid--
}

When we click Arrow, it broadcasts an "undo" message (NOTE: We pass the second parameter true to broadcast to indicate we wait all sprites to finish processing this message).

All Calf sprites receive this message, but only the last cloned sprite finds its id is equal to gid then destroys itself. Here are the related codes in Calf.spx:

onMsg "undo", => {
	if id == gid {
		destroy
	}
}
tutorial/04-Bullet

Screen Shot1

Through this example you can learn:

  • How to keep a sprite following mouse position.
  • How to fire bullets.

It's simple to keep a sprite following mouse position. Here are some related codes in MyAircraft.spx:

onStart => {
	for {
		# ...
		setXYpos mouseX, mouseY
	}
}

Yes, we just need to call setXYpos mouseX, mouseY to follow mouse position.

But how to fire bullets? Let's see all codes of MyAircraft.spx:

onStart => {
	for {
		wait 0.1
		Bullet.clone
		setXYpos mouseX, mouseY
	}
}

In this example, MyAircraft fires bullets every 0.1 seconds. It just calls Bullet.clone to create a new bullet. All the rest things are the responsibility of Bullet.

Here are all the codes in Bullet.spx:

onCloned => {
	setXYpos MyAircraft.xpos, MyAircraft.ypos+5
	show
	for {
		wait 0.04
		changeYpos 10
		if touching(Edge) {
			destroy
		}
	}
}

When a Bullet is cloned, it calls setXYpos MyAircraft.xpos, MyAircraft.ypos+5 to follow MyAircraft's position and shows itself (the default state of a Bullet is hidden). Then the Bullet moves forward every 0.04 seconds and this is why we see the Bullet is flying.

At last, when the Bullet touches screen Edge or any enemy (in this example we don't have enemies), it destroys itself.

These are all things about firing bullets.

Documentation

Index

Constants

View Source
const (
	GopPackage = true
	Gop_sched  = "Sched,SchedNow"
)
View Source
const (
	DbgFlagLoad dbgFlags = 1 << iota
	DbgFlagInstr
	DbgFlagEvent
	DbgFlagPerf
	DbgFlagAll = DbgFlagLoad | DbgFlagInstr | DbgFlagEvent | DbgFlagPerf
)
View Source
const (
	Prev switchAction = -1
	Next switchAction = 1
)
View Source
const (
	Right specialDir = 90
	Left  specialDir = -90
	Up    specialDir = 0
	Down  specialDir = 180
)
View Source
const (
	Mouse      specialObj = -5
	Edge       specialObj = touchingAllEdges
	EdgeLeft   specialObj = touchingScreenLeft
	EdgeTop    specialObj = touchingScreenTop
	EdgeRight  specialObj = touchingScreenRight
	EdgeBottom specialObj = touchingScreenBottom
)
View Source
const (
	StateDie   string = "die"
	StateTurn  string = "turn"
	StateGlide string = "glide"
	StateStep  string = "step"
)
View Source
const (
	AnimChannelFrame string = "@frame"
	AnimChannelTurn  string = "@turn"
	AnimChannelGlide string = "@glide"
	AnimChannelMove  string = "@move"
)

Variables

This section is empty.

Functions

func Exit__0 added in v1.0.0

func Exit__0(code int)

func Exit__1 added in v1.0.0

func Exit__1()

func Gopt_Game_Gopx_GetWidget added in v1.1.0

func Gopt_Game_Gopx_GetWidget[T any](sg ShapeGetter, name WidgetName) *T

GetWidget returns the widget instance (in given type) with given name. It panics if not found.

func Gopt_Game_Main added in v0.8.6

func Gopt_Game_Main(game Gamer, sprites ...Sprite)

Gopt_Game_Main is required by XGo compiler as the entry of a .gmx project.

func Gopt_Game_Reload added in v1.0.0

func Gopt_Game_Reload(game Gamer, index interface{}) (err error)

func Gopt_Game_Run added in v0.4.0

func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config)

Gopt_Game_Run runs the game. resource can be a string or fs.Dir object.

func Gopt_SpriteImpl_Clone__0 added in v1.1.0

func Gopt_SpriteImpl_Clone__0(sprite Sprite)

func Gopt_SpriteImpl_Clone__1 added in v1.1.0

func Gopt_SpriteImpl_Clone__1(sprite Sprite, data interface{})

func Iround added in v0.6.0

func Iround(v float64) int

Iround returns an integer value, while math.Round returns a float value.

func Rand__0 added in v0.4.0

func Rand__0(from, to int) float64

func Rand__1 added in v0.4.0

func Rand__1(from, to float64) float64

func Sched added in v0.2.1

func Sched() int

func SchedNow added in v0.2.1

func SchedNow() int

func SetDebug added in v0.3.0

func SetDebug(flags dbgFlags)

Types

type BackdropName added in v1.1.0

type BackdropName = string

type Camera added in v1.0.0

type Camera struct {
	// contains filtered or unexported fields
}

func (*Camera) ChangeXYpos added in v1.0.0

func (c *Camera) ChangeXYpos(x float64, y float64)

func (*Camera) On__0 added in v1.1.0

func (c *Camera) On__0(sprite Sprite)

func (*Camera) On__1 added in v1.1.0

func (c *Camera) On__1(sprite *SpriteImpl)

func (*Camera) On__2 added in v1.1.0

func (c *Camera) On__2(sprite SpriteName)

func (*Camera) On__3 added in v1.1.0

func (c *Camera) On__3(obj specialObj)

func (*Camera) SetXYpos added in v1.0.0

func (c *Camera) SetXYpos(x float64, y float64)

type Collider added in v1.1.0

type Collider struct {
	// contains filtered or unexported fields
}

func (*Collider) Reset added in v1.1.0

func (c *Collider) Reset()

func (*Collider) SetTouching added in v1.1.0

func (c *Collider) SetTouching(other *SpriteImpl, on bool)

type Color

type Color = color.RGBA

func RGB added in v0.6.0

func RGB(r, g, b uint8) Color

-----------------------------------------------------------------------------

func RGBA added in v0.6.0

func RGBA(r, g, b, a uint8) Color

type Config added in v0.2.0

type Config struct {
	Title              string      `json:"title,omitempty"`
	Width              int         `json:"width,omitempty"`
	Height             int         `json:"height,omitempty"`
	KeyDuration        int         `json:"keyDuration,omitempty"`
	ScreenshotKey      string      `json:"screenshotKey,omitempty"` // screenshot image capture key
	Index              interface{} `json:"-"`                       // where is index.json, can be file (string) or io.Reader
	DontParseFlags     bool        `json:"-"`
	FullScreen         bool        `json:"fullScreen,omitempty"`
	DontRunOnUnfocused bool        `json:"pauseOnUnfocused,omitempty"`
}

type EffectKind

type EffectKind int
const (
	ColorEffect EffectKind = iota
	BrightnessEffect
	GhostEffect
)

func (EffectKind) String added in v1.0.0

func (kind EffectKind) String() string

type Game

type Game struct {
	Camera
	// contains filtered or unexported fields
}

func (*Game) Answer

func (p *Game) Answer() Value

func (*Game) Ask

func (p *Game) Ask(msg interface{})

func (*Game) BackdropIndex added in v1.1.0

func (p *Game) BackdropIndex() int

func (*Game) BackdropName added in v1.1.0

func (p *Game) BackdropName() BackdropName

func (*Game) Broadcast__0 added in v0.3.0

func (p *Game) Broadcast__0(msg string)

func (*Game) Broadcast__1 added in v0.3.0

func (p *Game) Broadcast__1(msg string, wait bool)

func (*Game) Broadcast__2 added in v0.3.0

func (p *Game) Broadcast__2(msg string, data interface{}, wait bool)

func (*Game) ChangeEffect

func (p *Game) ChangeEffect(kind EffectKind, delta float64)

func (*Game) ChangeVolume

func (p *Game) ChangeVolume(delta float64)

func (*Game) ClearSoundEffects added in v1.0.0

func (p *Game) ClearSoundEffects()

func (*Game) Draw added in v0.8.0

func (p *Game) Draw(screen *ebiten.Image)

func (*Game) EraseAll added in v1.0.0

func (p *Game) EraseAll()

func (*Game) HideVar added in v0.7.0

func (p *Game) HideVar(name string)

func (*Game) IsRunned added in v1.1.0

func (p *Game) IsRunned() bool

func (*Game) KeyPressed

func (p *Game) KeyPressed(key Key) bool

func (*Game) Layout added in v0.8.0

func (p *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

func (*Game) Loudness added in v1.0.0

func (p *Game) Loudness() float64

func (*Game) MouseHitItem added in v1.0.0

func (p *Game) MouseHitItem() (target *SpriteImpl, ok bool)

MouseHitItem returns the topmost item which is hit by mouse.

func (*Game) MousePressed

func (p *Game) MousePressed() bool

func (*Game) MouseX

func (p *Game) MouseX() float64

func (*Game) MouseY

func (p *Game) MouseY() float64

func (*Game) NextBackdrop__0 added in v1.1.0

func (p *Game) NextBackdrop__0()

func (*Game) NextBackdrop__1 added in v1.1.0

func (p *Game) NextBackdrop__1(wait bool)

func (*Game) OnAnyKey added in v0.8.0

func (p *Game) OnAnyKey(onKey func(key Key))

func (*Game) OnBackdrop__0 added in v1.1.0

func (p *Game) OnBackdrop__0(onBackdrop func(name BackdropName))

func (*Game) OnBackdrop__1 added in v1.1.0

func (p *Game) OnBackdrop__1(name BackdropName, onBackdrop func())

func (*Game) OnClick added in v0.4.0

func (p *Game) OnClick(onClick func())

func (*Game) OnKey__0 added in v0.4.0

func (p *Game) OnKey__0(key Key, onKey func())

func (*Game) OnKey__1 added in v0.5.0

func (p *Game) OnKey__1(keys []Key, onKey func(Key))

func (*Game) OnKey__2 added in v0.8.0

func (p *Game) OnKey__2(keys []Key, onKey func())

func (*Game) OnMsg__0 added in v0.4.0

func (p *Game) OnMsg__0(onMsg func(msg string, data interface{}))

func (*Game) OnMsg__1 added in v0.4.0

func (p *Game) OnMsg__1(msg string, onMsg func())

func (*Game) OnStart added in v0.4.0

func (p *Game) OnStart(onStart func())

func (*Game) Play__0 added in v0.3.0

func (p *Game) Play__0(media Sound)

Play func:

Play(sound)
Play(video) -- maybe
Play(media, wait) -- sync
Play(media, opts)

func (*Game) Play__1 added in v1.0.0

func (p *Game) Play__1(media Sound, wait bool)

func (*Game) Play__2 added in v1.0.0

func (p *Game) Play__2(media Sound, action *PlayOptions)

func (*Game) Play__3 added in v1.1.0

func (p *Game) Play__3(media SoundName)

func (*Game) Play__4 added in v1.1.0

func (p *Game) Play__4(media SoundName, wait bool)

func (*Game) Play__5 added in v1.1.0

func (p *Game) Play__5(media SoundName, action *PlayOptions)

func (*Game) PrevBackdrop__0 added in v1.1.0

func (p *Game) PrevBackdrop__0()

func (*Game) PrevBackdrop__1 added in v1.1.0

func (p *Game) PrevBackdrop__1(wait bool)

func (*Game) ResetTimer

func (p *Game) ResetTimer()

func (*Game) SetEffect

func (p *Game) SetEffect(kind EffectKind, val float64)

func (*Game) SetVolume

func (p *Game) SetVolume(volume float64)

func (*Game) ShowVar added in v0.7.0

func (p *Game) ShowVar(name string)

func (*Game) StartBackdrop__0 added in v1.1.0

func (p *Game) StartBackdrop__0(backdrop BackdropName)

func (*Game) StartBackdrop__1 added in v1.1.0

func (p *Game) StartBackdrop__1(backdrop BackdropName, wait bool)

func (*Game) StartBackdrop__2 added in v1.1.0

func (p *Game) StartBackdrop__2(index float64)

func (*Game) StartBackdrop__3 added in v1.1.0

func (p *Game) StartBackdrop__3(index float64, wait bool)

func (*Game) StartBackdrop__4 added in v1.1.0

func (p *Game) StartBackdrop__4(index int)

func (*Game) StartBackdrop__5 added in v1.1.0

func (p *Game) StartBackdrop__5(index int, wait bool)

func (*Game) StartBackdrop__6 added in v1.1.0

func (p *Game) StartBackdrop__6(action switchAction)

func (*Game) StartBackdrop__7 added in v1.1.0

func (p *Game) StartBackdrop__7(action switchAction, wait bool)

func (*Game) Stop added in v0.4.0

func (p *Game) Stop(kind StopKind)

func (*Game) StopAllSounds

func (p *Game) StopAllSounds()

func (*Game) Timer

func (p *Game) Timer() float64

func (*Game) Update added in v0.8.0

func (p *Game) Update() error

func (*Game) Username

func (p *Game) Username() string

func (*Game) Volume

func (p *Game) Volume() float64

func (*Game) Wait

func (p *Game) Wait(secs float64)

type Gamer added in v0.2.0

type Gamer interface {
	// contains filtered or unexported methods
}

type IEventSinks added in v1.1.0

type IEventSinks interface {
	OnAnyKey(onKey func(key Key))
	OnBackdrop__0(onBackdrop func(name BackdropName))
	OnBackdrop__1(name BackdropName, onBackdrop func())
	OnClick(onClick func())
	OnKey__0(key Key, onKey func())
	OnKey__1(keys []Key, onKey func(Key))
	OnKey__2(keys []Key, onKey func())
	OnMsg__0(onMsg func(msg string, data interface{}))
	OnMsg__1(msg string, onMsg func())
	OnStart(onStart func())
	Stop(kind StopKind)
}

-------------------------------------------------------------------------------------

type Key

type Key = ebiten.Key
const (
	Key0            Key = ebiten.Key0
	Key1            Key = ebiten.Key1
	Key2            Key = ebiten.Key2
	Key3            Key = ebiten.Key3
	Key4            Key = ebiten.Key4
	Key5            Key = ebiten.Key5
	Key6            Key = ebiten.Key6
	Key7            Key = ebiten.Key7
	Key8            Key = ebiten.Key8
	Key9            Key = ebiten.Key9
	KeyA            Key = ebiten.KeyA
	KeyB            Key = ebiten.KeyB
	KeyC            Key = ebiten.KeyC
	KeyD            Key = ebiten.KeyD
	KeyE            Key = ebiten.KeyE
	KeyF            Key = ebiten.KeyF
	KeyG            Key = ebiten.KeyG
	KeyH            Key = ebiten.KeyH
	KeyI            Key = ebiten.KeyI
	KeyJ            Key = ebiten.KeyJ
	KeyK            Key = ebiten.KeyK
	KeyL            Key = ebiten.KeyL
	KeyM            Key = ebiten.KeyM
	KeyN            Key = ebiten.KeyN
	KeyO            Key = ebiten.KeyO
	KeyP            Key = ebiten.KeyP
	KeyQ            Key = ebiten.KeyQ
	KeyR            Key = ebiten.KeyR
	KeyS            Key = ebiten.KeyS
	KeyT            Key = ebiten.KeyT
	KeyU            Key = ebiten.KeyU
	KeyV            Key = ebiten.KeyV
	KeyW            Key = ebiten.KeyW
	KeyX            Key = ebiten.KeyX
	KeyY            Key = ebiten.KeyY
	KeyZ            Key = ebiten.KeyZ
	KeyApostrophe   Key = ebiten.KeyApostrophe
	KeyBackslash    Key = ebiten.KeyBackslash
	KeyBackspace    Key = ebiten.KeyBackspace
	KeyCapsLock     Key = ebiten.KeyCapsLock
	KeyComma        Key = ebiten.KeyComma
	KeyDelete       Key = ebiten.KeyDelete
	KeyDown         Key = ebiten.KeyDown
	KeyEnd          Key = ebiten.KeyEnd
	KeyEnter        Key = ebiten.KeyEnter
	KeyEqual        Key = ebiten.KeyEqual
	KeyEscape       Key = ebiten.KeyEscape
	KeyF1           Key = ebiten.KeyF1
	KeyF2           Key = ebiten.KeyF2
	KeyF3           Key = ebiten.KeyF3
	KeyF4           Key = ebiten.KeyF4
	KeyF5           Key = ebiten.KeyF5
	KeyF6           Key = ebiten.KeyF6
	KeyF7           Key = ebiten.KeyF7
	KeyF8           Key = ebiten.KeyF8
	KeyF9           Key = ebiten.KeyF9
	KeyF10          Key = ebiten.KeyF10
	KeyF11          Key = ebiten.KeyF11
	KeyF12          Key = ebiten.KeyF12
	KeyGraveAccent  Key = ebiten.KeyGraveAccent
	KeyHome         Key = ebiten.KeyHome
	KeyInsert       Key = ebiten.KeyInsert
	KeyKP0          Key = ebiten.KeyKP0
	KeyKP1          Key = ebiten.KeyKP1
	KeyKP2          Key = ebiten.KeyKP2
	KeyKP3          Key = ebiten.KeyKP3
	KeyKP4          Key = ebiten.KeyKP4
	KeyKP5          Key = ebiten.KeyKP5
	KeyKP6          Key = ebiten.KeyKP6
	KeyKP7          Key = ebiten.KeyKP7
	KeyKP8          Key = ebiten.KeyKP8
	KeyKP9          Key = ebiten.KeyKP9
	KeyKPDecimal    Key = ebiten.KeyKPDecimal
	KeyKPDivide     Key = ebiten.KeyKPDivide
	KeyKPEnter      Key = ebiten.KeyKPEnter
	KeyKPEqual      Key = ebiten.KeyKPEqual
	KeyKPMultiply   Key = ebiten.KeyKPMultiply
	KeyKPSubtract   Key = ebiten.KeyKPSubtract
	KeyLeft         Key = ebiten.KeyLeft
	KeyLeftBracket  Key = ebiten.KeyLeftBracket
	KeyMenu         Key = ebiten.KeyMenu
	KeyMinus        Key = ebiten.KeyMinus
	KeyNumLock      Key = ebiten.KeyNumLock
	KeyPageDown     Key = ebiten.KeyPageDown
	KeyPageUp       Key = ebiten.KeyPageUp
	KeyPause        Key = ebiten.KeyPause
	KeyPeriod       Key = ebiten.KeyPeriod
	KeyPrintScreen  Key = ebiten.KeyPrintScreen
	KeyRight        Key = ebiten.KeyRight
	KeyRightBracket Key = ebiten.KeyRightBracket
	KeyScrollLock   Key = ebiten.KeyScrollLock
	KeySemicolon    Key = ebiten.KeySemicolon
	KeySlash        Key = ebiten.KeySlash
	KeySpace        Key = ebiten.KeySpace
	KeyTab          Key = ebiten.KeyTab
	KeyUp           Key = ebiten.KeyUp
	KeyAlt          Key = ebiten.KeyAlt
	KeyControl      Key = ebiten.KeyControl
	KeyShift        Key = ebiten.KeyShift
	KeyMax          Key = ebiten.KeyMax
	KeyAny          Key = -1
)

type List added in v0.5.0

type List struct {
	// contains filtered or unexported fields
}

func (*List) Append added in v0.5.0

func (p *List) Append(v obj)

func (*List) At added in v0.5.0

func (p *List) At(i Pos) Value

func (*List) Contains added in v0.5.0

func (p *List) Contains(v obj) bool

func (*List) Delete added in v0.5.0

func (p *List) Delete(i Pos)

func (*List) Init added in v0.5.0

func (p *List) Init(data ...obj)

func (*List) InitFrom added in v0.5.0

func (p *List) InitFrom(src *List)

func (*List) Insert added in v0.5.0

func (p *List) Insert(i Pos, v obj)

func (*List) Len added in v0.5.0

func (p *List) Len() int

func (*List) Set added in v0.5.0

func (p *List) Set(i Pos, v obj)

func (*List) String added in v0.5.0

func (p *List) String() string

type Monitor added in v1.1.0

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor class.

func (*Monitor) ChangeSize added in v1.1.0

func (pself *Monitor) ChangeSize(delta float64)

func (*Monitor) ChangeXYpos added in v1.1.0

func (pself *Monitor) ChangeXYpos(dx float64, dy float64)

func (*Monitor) ChangeXpos added in v1.1.0

func (pself *Monitor) ChangeXpos(dx float64)

func (*Monitor) ChangeYpos added in v1.1.0

func (pself *Monitor) ChangeYpos(dy float64)

func (*Monitor) GetName added in v1.1.0

func (pself *Monitor) GetName() WidgetName

------------------------------------------------------------------------------------- IWidget

func (*Monitor) Hide added in v1.1.0

func (pself *Monitor) Hide()

func (*Monitor) SetSize added in v1.1.0

func (pself *Monitor) SetSize(size float64)

func (*Monitor) SetXYpos added in v1.1.0

func (pself *Monitor) SetXYpos(x float64, y float64)

func (*Monitor) SetXpos added in v1.1.0

func (pself *Monitor) SetXpos(x float64)

func (*Monitor) SetYpos added in v1.1.0

func (pself *Monitor) SetYpos(y float64)

func (*Monitor) Show added in v1.1.0

func (pself *Monitor) Show()

func (*Monitor) Size added in v1.1.0

func (pself *Monitor) Size() float64

func (*Monitor) Visible added in v1.1.0

func (pself *Monitor) Visible() bool

func (*Monitor) Xpos added in v1.1.0

func (pself *Monitor) Xpos() float64

func (*Monitor) Ypos added in v1.1.0

func (pself *Monitor) Ypos() float64

type MovingInfo added in v0.8.1

type MovingInfo struct {
	OldX, OldY float64
	NewX, NewY float64

	Obj *SpriteImpl
	// contains filtered or unexported fields
}

func (*MovingInfo) Dx added in v0.8.6

func (p *MovingInfo) Dx() float64

func (*MovingInfo) Dy added in v0.8.6

func (p *MovingInfo) Dy() float64

func (*MovingInfo) StopMoving added in v1.0.0

func (p *MovingInfo) StopMoving()

type PlayAction added in v1.0.0

type PlayAction int
const (
	PlayRewind PlayAction = iota
	PlayContinue
	PlayPause
	PlayResume
	PlayStop
)

type PlayOptions added in v1.0.0

type PlayOptions struct {
	Action PlayAction
	Wait   bool
	Loop   bool
}

type Pos added in v1.0.0

type Pos = int
const (
	Invalid Pos = -1
	Last    Pos = -2
	All         = -3 // Pos or StopKind
	Random  Pos = -4
)

type RotationStyle

type RotationStyle int
const (
	None RotationStyle = iota
	Normal
	LeftRight
)

type Shape added in v0.2.0

type Shape interface {
	// contains filtered or unexported methods
}

type ShapeGetter added in v1.1.0

type ShapeGetter interface {
	// contains filtered or unexported methods
}

type Sound added in v0.3.0

type Sound *soundConfig

type SoundName added in v1.1.0

type SoundName = string

type Sprite

type Sprite interface {
	IEventSinks
	Shape
	Main()

	Animate(name SpriteAnimationName)
	Ask(msg interface{})
	BounceOffEdge()
	Bounds() *math32.RotatedRect
	ChangeEffect(kind EffectKind, delta float64)
	ChangeHeading(dir float64)
	ChangePenColor(delta float64)
	ChangePenHue(delta float64)
	ChangePenShade(delta float64)
	ChangePenSize(delta float64)
	ChangeSize(delta float64)
	ChangeXpos(dx float64)
	ChangeXYpos(dx, dy float64)
	ChangeYpos(dy float64)
	ClearGraphEffects()
	CostumeHeight() float64
	CostumeIndex() int
	CostumeName() SpriteCostumeName
	CostumeWidth() float64
	DeleteThisClone()
	Destroy()
	Die()
	DistanceTo__0(sprite Sprite) float64
	DistanceTo__1(sprite SpriteName) float64
	DistanceTo__2(obj specialObj) float64
	DistanceTo__3(pos Pos) float64
	Glide__0(x, y float64, secs float64)
	Glide__1(sprite Sprite, secs float64)
	Glide__2(sprite SpriteName, secs float64)
	Glide__3(obj specialObj, secs float64)
	Glide__4(pos Pos, secs float64)
	GoBackLayers(n int)
	Goto__0(sprite Sprite)
	Goto__1(sprite SpriteName)
	Goto__2(obj specialObj)
	GotoBack()
	GotoFront()
	Heading() float64
	Hide()
	HideVar(name string)
	IsCloned() bool
	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))
	OnMoving__1(onMoving func())
	OnTouchStart__0(onTouchStart func(Sprite))
	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
	PenDown()
	PenUp()
	PrevCostume()
	Quote__0(message string)
	Quote__1(message string, secs float64)
	Quote__2(message, description string)
	Quote__3(message, description string, secs float64)
	Say__0(msg interface{})
	Say__1(msg interface{}, secs float64)
	SetCostume__0(costume SpriteCostumeName)
	SetCostume__1(index float64)
	SetCostume__2(index int)
	SetCostume__3(action switchAction)
	SetDying()
	SetEffect(kind EffectKind, val float64)
	SetHeading(dir float64)
	SetPenColor(color Color)
	SetPenHue(hue float64)
	SetPenShade(shade float64)
	SetPenSize(size float64)
	SetRotationStyle(style RotationStyle)
	SetSize(size float64)
	SetXpos(x float64)
	SetXYpos(x, y float64)
	SetYpos(y float64)
	Show()
	ShowVar(name string)
	Size() float64
	Stamp()
	Step__0(step float64)
	Step__1(step float64, animation SpriteAnimationName)
	Step__2(step int)
	Think__0(msg interface{})
	Think__1(msg interface{}, secs float64)
	Touching__0(sprite SpriteName) bool
	Touching__1(sprite Sprite) bool
	Touching__2(obj specialObj) bool
	TouchingColor(color Color) bool
	Turn__0(degree float64)
	Turn__1(dir specialDir)
	Turn__2(ti *TurningInfo)
	TurnTo__0(sprite Sprite)
	TurnTo__1(sprite SpriteName)
	TurnTo__2(degree float64)
	TurnTo__3(dir specialDir)
	TurnTo__4(obj specialObj)
	Visible() bool
	Xpos() float64
	Ypos() float64
}

type SpriteAnimationName added in v1.1.0

type SpriteAnimationName = string

type SpriteCostumeName added in v1.1.0

type SpriteCostumeName = string

type SpriteImpl added in v1.1.0

type SpriteImpl struct {
	// contains filtered or unexported fields
}

func (*SpriteImpl) Animate added in v1.1.0

func (p *SpriteImpl) Animate(name SpriteAnimationName)

func (*SpriteImpl) Ask added in v1.1.0

func (p *SpriteImpl) Ask(msg interface{})

func (*SpriteImpl) BounceOffEdge added in v1.1.0

func (p *SpriteImpl) BounceOffEdge()

func (*SpriteImpl) Bounds added in v1.1.0

func (p *SpriteImpl) Bounds() *math32.RotatedRect

func (*SpriteImpl) ChangeEffect added in v1.1.0

func (p *SpriteImpl) ChangeEffect(kind EffectKind, delta float64)

func (*SpriteImpl) ChangeHeading added in v1.1.0

func (p *SpriteImpl) ChangeHeading(dir float64)

func (*SpriteImpl) ChangePenColor added in v1.1.0

func (p *SpriteImpl) ChangePenColor(delta float64)

func (*SpriteImpl) ChangePenHue added in v1.1.0

func (p *SpriteImpl) ChangePenHue(delta float64)

func (*SpriteImpl) ChangePenShade added in v1.1.0

func (p *SpriteImpl) ChangePenShade(delta float64)

func (*SpriteImpl) ChangePenSize added in v1.1.0

func (p *SpriteImpl) ChangePenSize(delta float64)

func (*SpriteImpl) ChangeSize added in v1.1.0

func (p *SpriteImpl) ChangeSize(delta float64)

func (*SpriteImpl) ChangeXYpos added in v1.1.0

func (p *SpriteImpl) ChangeXYpos(dx, dy float64)

func (*SpriteImpl) ChangeXpos added in v1.1.0

func (p *SpriteImpl) ChangeXpos(dx float64)

func (*SpriteImpl) ChangeYpos added in v1.1.0

func (p *SpriteImpl) ChangeYpos(dy float64)

func (*SpriteImpl) ClearGraphEffects added in v1.1.0

func (p *SpriteImpl) ClearGraphEffects()

func (*SpriteImpl) CostumeHeight added in v1.1.0

func (p *SpriteImpl) CostumeHeight() float64

CostumeHeight returns height of sprite current costume.

func (*SpriteImpl) CostumeIndex added in v1.1.0

func (p *SpriteImpl) CostumeIndex() int

func (*SpriteImpl) CostumeName added in v1.1.0

func (p *SpriteImpl) CostumeName() SpriteCostumeName

func (*SpriteImpl) CostumeWidth added in v1.1.0

func (p *SpriteImpl) CostumeWidth() float64

CostumeWidth returns width of sprite current costume.

func (*SpriteImpl) DeleteThisClone added in v1.1.0

func (p *SpriteImpl) DeleteThisClone()

delete only cloned sprite, no effect on prototype sprite. Add this interface, to match Scratch.

func (*SpriteImpl) Destroy added in v1.1.0

func (p *SpriteImpl) Destroy()

func (*SpriteImpl) Die added in v1.1.0

func (p *SpriteImpl) Die()

func (*SpriteImpl) DistanceTo__0 added in v1.1.0

func (p *SpriteImpl) DistanceTo__0(sprite Sprite) float64

func (*SpriteImpl) DistanceTo__1 added in v1.1.0

func (p *SpriteImpl) DistanceTo__1(sprite SpriteName) float64

func (*SpriteImpl) DistanceTo__2 added in v1.1.0

func (p *SpriteImpl) DistanceTo__2(obj specialObj) float64

func (*SpriteImpl) DistanceTo__3 added in v1.1.0

func (p *SpriteImpl) DistanceTo__3(pos Pos) float64

func (*SpriteImpl) Glide__0 added in v1.1.0

func (p *SpriteImpl) Glide__0(x, y float64, secs float64)

func (*SpriteImpl) Glide__1 added in v1.1.0

func (p *SpriteImpl) Glide__1(sprite Sprite, secs float64)

func (*SpriteImpl) Glide__2 added in v1.1.0

func (p *SpriteImpl) Glide__2(sprite SpriteName, secs float64)

func (*SpriteImpl) Glide__3 added in v1.1.0

func (p *SpriteImpl) Glide__3(obj specialObj, secs float64)

func (*SpriteImpl) Glide__4 added in v1.1.0

func (p *SpriteImpl) Glide__4(pos Pos, secs float64)

func (*SpriteImpl) GoBackLayers added in v1.1.0

func (p *SpriteImpl) GoBackLayers(n int)

func (*SpriteImpl) GotoBack added in v1.1.0

func (p *SpriteImpl) GotoBack()

func (*SpriteImpl) GotoFront added in v1.1.0

func (p *SpriteImpl) GotoFront()

func (*SpriteImpl) Goto__0 added in v1.1.0

func (p *SpriteImpl) Goto__0(sprite Sprite)

func (*SpriteImpl) Goto__1 added in v1.1.0

func (p *SpriteImpl) Goto__1(sprite SpriteName)

func (*SpriteImpl) Goto__2 added in v1.1.0

func (p *SpriteImpl) Goto__2(obj specialObj)

func (*SpriteImpl) Heading added in v1.1.0

func (p *SpriteImpl) Heading() float64

func (*SpriteImpl) Hide added in v1.1.0

func (p *SpriteImpl) Hide()

func (*SpriteImpl) HideVar added in v1.1.0

func (p *SpriteImpl) HideVar(name string)

func (*SpriteImpl) InitFrom added in v1.1.0

func (p *SpriteImpl) InitFrom(src *SpriteImpl)

func (*SpriteImpl) IsCloned added in v1.1.0

func (p *SpriteImpl) IsCloned() bool

func (*SpriteImpl) Main added in v1.1.2

func (p *SpriteImpl) Main()

func (*SpriteImpl) Move__0 added in v1.1.0

func (p *SpriteImpl) Move__0(step float64)

func (*SpriteImpl) Move__1 added in v1.1.0

func (p *SpriteImpl) Move__1(step int)

func (*SpriteImpl) Name added in v1.1.2

func (p *SpriteImpl) Name() string

func (*SpriteImpl) NextCostume added in v1.1.0

func (p *SpriteImpl) NextCostume()

func (*SpriteImpl) OnAnyKey added in v1.1.0

func (p *SpriteImpl) OnAnyKey(onKey func(key Key))

func (*SpriteImpl) OnBackdrop__0 added in v1.1.0

func (p *SpriteImpl) OnBackdrop__0(onBackdrop func(name BackdropName))

func (*SpriteImpl) OnBackdrop__1 added in v1.1.0

func (p *SpriteImpl) OnBackdrop__1(name BackdropName, onBackdrop func())

func (*SpriteImpl) OnClick added in v1.1.0

func (p *SpriteImpl) OnClick(onClick func())

func (*SpriteImpl) OnCloned__0 added in v1.1.0

func (p *SpriteImpl) OnCloned__0(onCloned func(data interface{}))

func (*SpriteImpl) OnCloned__1 added in v1.1.0

func (p *SpriteImpl) OnCloned__1(onCloned func())

func (*SpriteImpl) OnKey__0 added in v1.1.0

func (p *SpriteImpl) OnKey__0(key Key, onKey func())

func (*SpriteImpl) OnKey__1 added in v1.1.0

func (p *SpriteImpl) OnKey__1(keys []Key, onKey func(Key))

func (*SpriteImpl) OnKey__2 added in v1.1.0

func (p *SpriteImpl) OnKey__2(keys []Key, onKey func())

func (*SpriteImpl) OnMoving__0 added in v1.1.0

func (p *SpriteImpl) OnMoving__0(onMoving func(mi *MovingInfo))

func (*SpriteImpl) OnMoving__1 added in v1.1.0

func (p *SpriteImpl) OnMoving__1(onMoving func())

func (*SpriteImpl) OnMsg__0 added in v1.1.0

func (p *SpriteImpl) OnMsg__0(onMsg func(msg string, data interface{}))

func (*SpriteImpl) OnMsg__1 added in v1.1.0

func (p *SpriteImpl) OnMsg__1(msg string, onMsg func())

func (*SpriteImpl) OnStart added in v1.1.0

func (p *SpriteImpl) OnStart(onStart func())

func (*SpriteImpl) OnTouchStart__0 added in v1.1.0

func (p *SpriteImpl) OnTouchStart__0(onTouchStart func(Sprite))

func (*SpriteImpl) OnTouchStart__1 added in v1.1.0

func (p *SpriteImpl) OnTouchStart__1(onTouchStart func())

func (*SpriteImpl) OnTouchStart__2 added in v1.1.0

func (p *SpriteImpl) OnTouchStart__2(sprite SpriteName, onTouchStart func(Sprite))

func (*SpriteImpl) OnTouchStart__3 added in v1.1.0

func (p *SpriteImpl) OnTouchStart__3(sprite SpriteName, onTouchStart func())

func (*SpriteImpl) OnTouchStart__4 added in v1.1.2

func (p *SpriteImpl) OnTouchStart__4(sprites []SpriteName, onTouchStart func(Sprite))

func (*SpriteImpl) OnTouchStart__5 added in v1.1.2

func (p *SpriteImpl) OnTouchStart__5(sprites []SpriteName, onTouchStart func())

func (*SpriteImpl) OnTurning__0 added in v1.1.0

func (p *SpriteImpl) OnTurning__0(onTurning func(ti *TurningInfo))

func (*SpriteImpl) OnTurning__1 added in v1.1.0

func (p *SpriteImpl) OnTurning__1(onTurning func())

func (*SpriteImpl) Parent added in v1.1.0

func (p *SpriteImpl) Parent() *Game

func (*SpriteImpl) PenDown added in v1.1.0

func (p *SpriteImpl) PenDown()

func (*SpriteImpl) PenUp added in v1.1.0

func (p *SpriteImpl) PenUp()

func (*SpriteImpl) PrevCostume added in v1.1.0

func (p *SpriteImpl) PrevCostume()

func (*SpriteImpl) Quote__0 added in v1.1.0

func (p *SpriteImpl) Quote__0(message string)

func (*SpriteImpl) Quote__1 added in v1.1.0

func (p *SpriteImpl) Quote__1(message string, secs float64)

func (*SpriteImpl) Quote__2 added in v1.1.0

func (p *SpriteImpl) Quote__2(message, description string)

func (*SpriteImpl) Quote__3 added in v1.1.0

func (p *SpriteImpl) Quote__3(message, description string, secs float64)

func (*SpriteImpl) Say__0 added in v1.1.0

func (p *SpriteImpl) Say__0(msg interface{})

func (*SpriteImpl) Say__1 added in v1.1.0

func (p *SpriteImpl) Say__1(msg interface{}, secs float64)

func (*SpriteImpl) SetCostume__0 added in v1.1.0

func (p *SpriteImpl) SetCostume__0(costume SpriteCostumeName)

func (*SpriteImpl) SetCostume__1 added in v1.1.0

func (p *SpriteImpl) SetCostume__1(index float64)

func (*SpriteImpl) SetCostume__2 added in v1.1.0

func (p *SpriteImpl) SetCostume__2(index int)

func (*SpriteImpl) SetCostume__3 added in v1.1.0

func (p *SpriteImpl) SetCostume__3(action switchAction)

func (*SpriteImpl) SetDying added in v1.1.0

func (p *SpriteImpl) SetDying()

func (*SpriteImpl) SetEffect added in v1.1.0

func (p *SpriteImpl) SetEffect(kind EffectKind, val float64)

func (*SpriteImpl) SetHeading added in v1.1.0

func (p *SpriteImpl) SetHeading(dir float64)

func (*SpriteImpl) SetPenColor added in v1.1.0

func (p *SpriteImpl) SetPenColor(color Color)

func (*SpriteImpl) SetPenHue added in v1.1.0

func (p *SpriteImpl) SetPenHue(hue float64)

func (*SpriteImpl) SetPenShade added in v1.1.0

func (p *SpriteImpl) SetPenShade(shade float64)

func (*SpriteImpl) SetPenSize added in v1.1.0

func (p *SpriteImpl) SetPenSize(size float64)

func (*SpriteImpl) SetRotationStyle added in v1.1.0

func (p *SpriteImpl) SetRotationStyle(style RotationStyle)

func (*SpriteImpl) SetSize added in v1.1.0

func (p *SpriteImpl) SetSize(size float64)

func (*SpriteImpl) SetXYpos added in v1.1.0

func (p *SpriteImpl) SetXYpos(x, y float64)

func (*SpriteImpl) SetXpos added in v1.1.0

func (p *SpriteImpl) SetXpos(x float64)

func (*SpriteImpl) SetYpos added in v1.1.0

func (p *SpriteImpl) SetYpos(y float64)

func (*SpriteImpl) Show added in v1.1.0

func (p *SpriteImpl) Show()

func (*SpriteImpl) ShowVar added in v1.1.0

func (p *SpriteImpl) ShowVar(name string)

func (*SpriteImpl) Size added in v1.1.0

func (p *SpriteImpl) Size() float64

func (*SpriteImpl) Stamp added in v1.1.0

func (p *SpriteImpl) Stamp()

func (*SpriteImpl) Step__0 added in v1.1.0

func (p *SpriteImpl) Step__0(step float64)

func (*SpriteImpl) Step__1 added in v1.1.0

func (p *SpriteImpl) Step__1(step float64, animation SpriteAnimationName)

func (*SpriteImpl) Step__2 added in v1.1.0

func (p *SpriteImpl) Step__2(step int)

func (*SpriteImpl) Stop added in v1.1.0

func (p *SpriteImpl) Stop(kind StopKind)

func (*SpriteImpl) Think__0 added in v1.1.0

func (p *SpriteImpl) Think__0(msg interface{})

func (*SpriteImpl) Think__1 added in v1.1.0

func (p *SpriteImpl) Think__1(msg interface{}, secs float64)

func (*SpriteImpl) TouchingColor added in v1.1.0

func (p *SpriteImpl) TouchingColor(color Color) bool

func (*SpriteImpl) Touching__0 added in v1.1.0

func (p *SpriteImpl) Touching__0(sprite SpriteName) bool

func (*SpriteImpl) Touching__1 added in v1.1.0

func (p *SpriteImpl) Touching__1(sprite Sprite) bool

func (*SpriteImpl) Touching__2 added in v1.1.0

func (p *SpriteImpl) Touching__2(obj specialObj) bool

func (*SpriteImpl) TurnTo__0 added in v1.1.0

func (p *SpriteImpl) TurnTo__0(sprite Sprite)

func (*SpriteImpl) TurnTo__1 added in v1.1.0

func (p *SpriteImpl) TurnTo__1(sprite SpriteName)

func (*SpriteImpl) TurnTo__2 added in v1.1.0

func (p *SpriteImpl) TurnTo__2(degree float64)

func (*SpriteImpl) TurnTo__3 added in v1.1.0

func (p *SpriteImpl) TurnTo__3(dir specialDir)

func (*SpriteImpl) TurnTo__4 added in v1.1.0

func (p *SpriteImpl) TurnTo__4(obj specialObj)

func (*SpriteImpl) Turn__0 added in v1.1.0

func (p *SpriteImpl) Turn__0(degree float64)

func (*SpriteImpl) Turn__1 added in v1.1.0

func (p *SpriteImpl) Turn__1(dir specialDir)

func (*SpriteImpl) Turn__2 added in v1.1.0

func (p *SpriteImpl) Turn__2(ti *TurningInfo)

func (*SpriteImpl) Visible added in v1.1.0

func (p *SpriteImpl) Visible() bool

func (*SpriteImpl) Xpos added in v1.1.0

func (p *SpriteImpl) Xpos() float64

func (*SpriteImpl) Ypos added in v1.1.0

func (p *SpriteImpl) Ypos() float64

type SpriteName added in v1.1.0

type SpriteName = string

type StopKind added in v1.0.0

type StopKind int
const (
	AllOtherScripts      StopKind = -100 // stop all other scripts
	AllSprites           StopKind = -101 // stop all scripts of sprites
	ThisSprite           StopKind = -102 // stop all scripts of this sprite
	ThisScript           StopKind = -103 // abort this script
	OtherScriptsInSprite StopKind = -104 // stop other scripts of this sprite
)

type TurningInfo added in v1.0.0

type TurningInfo struct {
	OldDir float64
	NewDir float64
	Obj    *SpriteImpl
}

func (*TurningInfo) Dir added in v1.0.0

func (p *TurningInfo) Dir() float64

type Value

type Value struct {
	// contains filtered or unexported fields
}

func (Value) Equal added in v0.5.0

func (p Value) Equal(v obj) bool

func (Value) Float

func (p Value) Float() float64

func (Value) Int

func (p Value) Int() int

func (Value) String

func (p Value) String() string

type Widget added in v1.1.0

type Widget interface {
	GetName() WidgetName
	Visible() bool
	Show()
	Hide()

	Xpos() float64
	Ypos() float64
	SetXpos(x float64)
	SetYpos(y float64)
	SetXYpos(x float64, y float64)
	ChangeXpos(dx float64)
	ChangeYpos(dy float64)
	ChangeXYpos(dx float64, dy float64)

	Size() float64
	SetSize(size float64)
	ChangeSize(delta float64)
}

func GetWidget_ added in v1.1.0

func GetWidget_(sg ShapeGetter, name WidgetName) Widget

GetWidget_ returns the widget instance with given name. It panics if not found. Instead of being used directly, it is meant to be called by `Gopt_Game_Gopx_GetWidget` only. We extract `GetWidget_` to keep `Gopt_Game_Gopx_GetWidget` simple, which simplifies work in ispx, see details in https://github.com/goplus/builder/issues/765#issuecomment-2313915805.

type WidgetName added in v1.1.0

type WidgetName = string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL