Checkpoints
A Checkpoint 2D moves the respawn point of a node with Respawn that enters it, to its own position or to the node in Spawn Point. A checkpoint never replaces one with a higher Priority, so walking back does not lose progress; Once makes it work for the first node only. Reached(by) fires when a node takes it.
Try it
Change the example parameters and compare the result. Reset restores the initial scene.
Starts the scene; open the example parameters to experiment.
Scene9 nodes
FloorA
Transform
position[-6, 3]rotation0scale[1, 1]
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
FloorB
Transform
position[12.5, 3]rotation0scale[1, 1]
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
FloorC
Transform
position[31.5, 3]rotation0scale[1, 1]
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Wall
Transform
position[-14, 0]rotation0scale[1, 1]
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Player
Transform
position[0, 0]rotation0scale[1, 1]
Rigid Body 2D
typeenumkinematicmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationbooltruebulletboolfalseallowSleepboolfalseinterpolatebooltruelayerlayer0masklayer mask-1
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Virtual Camera 2D
priorityint0outputstring""zoomfloat0blendTimefloat0.5blendCurveCurve{ ease=inOutQuad }timeDomainenumunscaleduseBoundsboolfalseboundsRect[0, 0, 0, 0]snapToPixelsboolfalse
Camera Follow 2D
targetNodeRefnode("d6600000000000000000000000000007")deadzoneRect[0.4, 0.4, 0.2, 0.2]dampingVec2[5, 5]lookaheadVec2[0.2, 0]maxLookaheadVec2[2, 1]lookaheadSmoothingfloat3snapDistancefloat20
Scriptmain.aes
package demo
import (
"aego/debug"
"aego/input"
)
// Player takes checkpoints; after a fall it comes back at the last one.
script Player {
func Update(dt float) {
m := node.Get<Motion2D>()
x := 0.0
if input.Down(input.KeyA) || input.Down(input.KeyLeft) {
x -= 1
}
if input.Down(input.KeyD) || input.Down(input.KeyRight) {
x += 1
}
m.Move(x)
if input.KeyPressed(input.KeySpace) || input.KeyPressed(input.KeyW) || input.KeyPressed(input.KeyUp) {
m.Jump()
}
if input.KeyReleased(input.KeySpace) || input.KeyReleased(input.KeyW) || input.KeyReleased(input.KeyUp) {
m.JumpReleased()
}
}
}
// Flag says which checkpoint was taken.
script Flag {
@export var Number int
var shown float
var conn Connection
func Ready() {
conn = node.Get<Checkpoint2D>().Reached.Connect(OnReached)
}
func OnReached(by NodeRef) {
shown = 2
}
func Update(dt float) {
p := node.WorldPosition()
if shown > 0 {
shown -= dt
debug.Text(Vec2{p.X - 1, p.Y - 2}, "checkpoint " + string(Number), Color{0.4, 1, 0.5, 1})
}
}
}