Documentation ¶
Overview ¶
This package defines a Tracker interface that the ebipixel camera can use to update its position, and provides a few default implementations.
All provided implementations respect a few properties:
- Resolution independent: range of motion for the tracking is not hardcoded, but proportional to the game's resolution.
- Tick-rate independent: tracking preserves the same relative speed regardless of your Tick().UPS() and Tick().GetRate() values. See ups-vs-tps if you need more context.
These are nice properties for public implementations, but if you are writing your own, remember that most often these properties won't be relevant to you. You can ignore them and make your life easier if you are only getting started.
Index ¶
- Variables
- type Parametrized
- func (self *Parametrized) SetFrozenTrackingBelow(screens float64)
- func (self *Parametrized) SetInstantTrackingBelow(screensPerSecond float64)
- func (self *Parametrized) SetMaxSpeed(maxScreensPerSecond, screensToMaxSpeed float64)
- func (self *Parametrized) Update(currentX, currentY, targetX, targetY, prevSpeedX, prevSpeedY float64) (float64, float64)
- type Spring
- type SpringTailer
- type Tailer
- type Tracker
Constants ¶
This section is empty.
Variables ¶
var ( // Update(...) always returns (0, 0). Frozen tracker = frozenTracker{} // Update(...) always returns (target - current). Instant tracker = instantTracker{} // Applies a lerp between current and target position. Linear tracker = linearTracker{} )
A few stateless built-in trackers.
Functions ¶
This section is empty.
Types ¶
type Parametrized ¶
type Parametrized struct {
// contains filtered or unexported fields
}
A configurable linear tracker.
func (*Parametrized) SetFrozenTrackingBelow ¶
func (self *Parametrized) SetFrozenTrackingBelow(screens float64)
If set, the tracking error (difference between camera's target and current positions) must reach the given distance in screens before the tracker starts moving.
func (*Parametrized) SetInstantTrackingBelow ¶
func (self *Parametrized) SetInstantTrackingBelow(screensPerSecond float64)
If set, speeds below the given threshold will result in instantaneous tracking.
func (*Parametrized) SetMaxSpeed ¶
func (self *Parametrized) SetMaxSpeed(maxScreensPerSecond, screensToMaxSpeed float64)
Sets the maximum speed of the tracking:
- maxScreensPerSecond is the maximum speed you want to allow the camera to move at. It defaults to 2.0 screens per second.
- screensToMaxSpeed is the distance at which the maximum speed is reached. The difference between the camera's target and the current position must be >= screensToMaxSpeed for the camera to reach maximum speed. The default is 0.5.
type Spring ¶
type Spring struct {
// contains filtered or unexported fields
}
func (*Spring) SetParameters ¶
type SpringTailer ¶
type SpringTailer struct { Spring Spring // contains filtered or unexported fields }
Like Tailer, but based on a Spring tracker, and the catch up algorithm also uses a spring instead of quadratic easings.
Example settings configuration for a gentle tracker:
springTailer := tracker.SpringTailer{} springTailer.Spring.SetParameters(0.8, 2.4) springTailer.SetCatchUpParameters(0.9, 1.75)
func (*SpringTailer) SetCatchUpParameters ¶
func (self *SpringTailer) SetCatchUpParameters(damping, power float64)
Sets the spring parameters for the catch up corrector. The default values are (0.9, 1.75).
func (*SpringTailer) SetCatchUpTimes ¶
func (self *SpringTailer) SetCatchUpTimes(engage, disengage float64)
See Tailer.SetCatchUpTimes(). The default values are (1.0, 0.5).
type Tailer ¶
type Tailer struct { Parametrized Parametrized // contains filtered or unexported fields }
A tracker that uses a Parametrized implementation as its base, which you can access and configure directly as a struct field, and then adds a catch up mechanism that triggers after you move for some time in a more or less consistent speed.
func (*Tailer) SetCatchUpAcceleration ¶
Once the catching up mechanism is triggered, it uses a static acceleration to progressively change speed. Reasonable values range between [0.1, 0.5]. The default is 0.2.
func (*Tailer) SetCatchUpTimes ¶
Specifies how long it takes the catch up mechanism to engage and disengage. The values are given in seconds:
- Engaging happens when we have been moving the target at a more or less consistent speed for a while.
- Disengaging happens when we have been stopped for a while.
The default values are 1.0, 0.5. The disengage time must always be <= than the engage time.