SpriteBaseSwitchToState Method |
Switch the sprite to the the specified state, ensuring that the sprite doesn't hit a solid.
Namespace: (Default Namespace)Assembly: Default (in Default.exe) Version: 1.0.0.0
Syntax public virtual bool SwitchToState(
int State,
RelativePosition Alignment
)
Parameters
- State
- Type: SystemInt32
State to which the sprite will be switched - Alignment
- Type: (Default Namespace)RelativePosition
Specifies a point within the sprite which will remain constant. For example, RelativePosition.BottomCenter will ensure that the bottom center point of the new state aligns with the bottom center point of this state.
Return Value
Type:
BooleanTrue if the state could be switched, false if the new state's differing size would
have caused the sprite the sprite to pass through a solid tile.
Remarks This function is handy for performing action like switching from a crouching
state to a standing state because it will prevent you from standing up if there is a low
ceiling in the way. It also helps you align the two states properly. For example, if you
switched from the crouching state to the standing state without moving the sprite at
all, the origin (usually the top left corner of the sprite) would remain in the same place,
which would cause the head to remain in the same place and the feet to stick through the
floor. But by using the Alignment paremeter, you can make sure that the botton of the
new state aligns with the bottom of the current state.
See Also