Spring class

Classical spring implementing Hooke's law with configurable friction and tension.

Constructors

Spring(BaseSpringSystem springSystem)
create a new spring

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(SpringListener newListener) Spring
add a listener @param newListener to add @return the spring for chaining
advance(double realDeltaTime) → void
advance the physics simulation in SOLVER_TIMESTEP_SEC sized chunks to fulfill the required realTimeDelta. The math is inlined inside the loop since it made a huge performance impact when there are several springs being advanced. @param realDeltaTime clock drift
currentValueIsApproximately(double value) bool
This method checks to see that the current spring displacement value is equal to the input, accounting for the spring's rest displacement threshold. @param value The value to compare the spring value to @return Whether the displacement value from the spring is within the bounds of the compare value, accounting for threshold
destroy() → void
Destroys this Spring, meaning that it will be deregistered from its BaseSpringSystem so it won't be iterated anymore and will clear its set of listeners. Do not use the Spring after calling this, doing so may just cause an exception to be thrown.
getCurrentDisplacementDistance() double
get the displacement of the springs current value from its rest value. @return the distance displaced by
getCurrentValue() double
Get the current @return current value
getDisplacementDistanceForState(_PhysicsState state) double
get the displacement from rest for a given physics state @param state the state to measure from @return the distance displaced by
getEndValue() double
get the rest value used for determining the displacement of the spring @return the rest value for the spring
getId() String
get the unique id for this spring @return the unique id
getRestDisplacementThreshold() double
get the threshold of displacement from rest below which the spring should be considered at rest @return displacement to consider resting below
getRestSpeedThreshold() double
Returns the speed at which the spring should be considered at rest in pixels per second @return speed in pixels per second
getSpringConfig() SpringConfig
retrieve the spring config for this spring @return the SpringConfig applied to this spring
getStartValue() double
Get the displacement value from the last time setCurrentValue was called. @return displacement value
getVelocity() double
get the velocity of the spring @return the current velocity
interpolate(double alpha) → void
linear interpolation between the previous and current physics state based on the amount of timestep remaining after processing the rendering delta time in timestep sized chunks. @param alpha from 0 to 1, where 0 is the previous state, 1 is the current state
isAtRest() bool
check if the current state is at rest @return is the spring at rest
isOvershootClampingEnabled() bool
Check if overshoot clamping is enabled. @return is overshoot clamping enabled
isOvershooting() bool
Check if the spring is overshooting beyond its target. @return true if the spring is overshooting its target
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAllListeners() Spring
remove all of the listeners @return the spring for chaining
removeListener(SpringListener listenerToRemove) Spring
remove a listener @param listenerToRemove to remove @return the spring for chaining
setAtRest() Spring
Set the spring to be at rest by making its end value equal to its current value and setting velocity to 0. @return this object
setCurrentValue(double currentValue, {bool setAtRest = true}) Spring
The full signature for setCurrentValue includes the option of not setting the spring at rest after updating its currentValue. Passing setAtRest false means that if the endValue of the spring is not equal to the currentValue, the physics system will start iterating to resolve the spring to the end value. This is almost never the behavior that you want, so the default setCurrentValue signature passes true. @param currentValue the new start and current value for the spring @param setAtRest optionally set the spring at rest after updating its current value. see {@link com.facebook.rebound.Spring#setAtRest()} @return the spring for chaining
setEndValue(double endValue) Spring
set the rest value to determine the displacement for the spring @param endValue the endValue for the spring @return the spring for chaining
setOvershootClampingEnabled(bool overshootClampingEnabled) Spring
Force the spring to clamp at its end value to avoid overshooting the target value. @param overshootClampingEnabled whether or not to enable overshoot clamping @return the spring for chaining
setRestDisplacementThreshold(double displacementFromRestThreshold) Spring
set the threshold of displacement from rest below which the spring should be considered at rest @param displacementFromRestThreshold displacement to consider resting below @return the spring for chaining
setRestSpeedThreshold(double restSpeedThreshold) Spring
Sets the speed at which the spring should be considered at rest. @param restSpeedThreshold speed pixels per second @return the spring for chaining
setSpringConfig(SpringConfig springConfig) Spring
set the config class @param springConfig config class for the spring @return this Spring instance for chaining
setVelocity(double velocity) Spring
set the velocity on the spring in pixels per second @param velocity velocity value @return the spring for chaining
systemShouldAdvance() bool
Check if this spring should be advanced by the system. * The rule is if the spring is currently at rest and it was at rest in the previous advance, the system can skip this spring @return should the system process this spring
toString() String
A string representation of this object.
inherited
wasAtRest() bool
Check if the spring was at rest in the prior iteration. This is used for ensuring the ending callbacks are fired as the spring comes to a rest. @return true if the spring was at rest in the prior iteration

Operators

operator ==(Object other) bool
The equality operator.
inherited