Documentation
¶
Overview ¶
Package kamera provides a camera object for Ebitengine v2.
Index ¶
- type Camera
- func (cam *Camera) AddTrauma(factor float64)
- func (cam *Camera) ApplyCameraTransform(g *ebiten.GeoM)
- func (cam *Camera) ApplyCameraTransformToPoint(x, y float64) (float64, float64)
- func (cam *Camera) Bottom() float64
- func (cam *Camera) Center() (X float64, Y float64)
- func (cam *Camera) CenterX() float64
- func (cam *Camera) CenterY() float64
- func (cam *Camera) Draw(worldObject *ebiten.Image, worldObjectOps *ebiten.DrawImageOptions, ...)
- func (cam *Camera) DrawWithColorM(worldObject *ebiten.Image, cm colorm.ColorM, ...)
- func (cam *Camera) LookAt(targetX, targetY float64)
- func (cam *Camera) Reset()
- func (cam *Camera) Right() float64
- func (cam *Camera) ScreenToWorld(screenX, screenY int) (worldX float64, worldY float64)
- func (cam *Camera) SetCenter(x, y float64)
- func (cam *Camera) SetSize(w, h float64)
- func (cam *Camera) SetTopLeft(x, y float64)
- func (cam *Camera) String() string
- type ShakeOptions
- type SmoothOptions
- type SmoothType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Camera ¶
type Camera struct {
// Top-left X position of camera
X float64
// Top-left Y position of camera
Y float64
// Width is camera's width
Width float64
// Height is camera's height
Height float64
// Amgle is camera angle (without the angle of trauma shaking).
//
// The unit is radian.
Angle float64
// ActualAngle is camera angle (including the angle of trauma shaking).
//
// The unit is radian.
ActualAngle float64
// ZoomFactor is the camera zoom (scaling) factor. Default is 1.
ZoomFactor float64
// SmoothType is the camera movement smoothing type.
SmoothType SmoothType
// Trauma factor. Factor is in the range [0-1]. Use AddTrauma() function
Trauma float64
// SmoothOptions holds the camera movement smoothing settings
SmoothOptions *SmoothOptions
// ShakeOptions holds the camera shake options.
ShakeOptions *ShakeOptions
// If ShakeEnabled is false, AddTrauma() has no effect and shake is always 0.
//
// The default value is false
ShakeEnabled bool
// XAxisSmoothingDisabled disables the smoothing of the X axis if it's true.
XAxisSmoothingDisabled bool
// YAxisSmoothingDisabled disables the smoothing of the Y axis if it's true.
YAxisSmoothingDisabled bool
// Internal camera values. Do not change directly.
Tick, ZoomFactorShake float64
// Internal camera values. Do not change directly.
TempTargetX, CenterOffsetX, TraumaOffsetX, CurrentVelocityX float64
// Internal camera values. Do not change directly.
TempTargetY, CenterOffsetY, TraumaOffsetY, CurrentVelocityY float64
}
Camera object.
Use the `Camera.LookAt()` to align the center of the camera to the target.
func (*Camera) ApplyCameraTransform ¶
ApplyCameraTransform applies geometric transformation to given geoM
func (*Camera) ApplyCameraTransformToPoint ¶ added in v2.9.0
ApplyCameraTransformToPoint applies camera transformation to given point
func (*Camera) Bottom ¶ added in v2.95.1
Bottom returns the bottom edge position of the camera in world-space.
func (*Camera) CenterX ¶ added in v2.98.1
CenterX returns X axis center of the camera in world-space
func (*Camera) CenterY ¶ added in v2.98.1
CenterY returns Y axis center of the camera in world-space
func (*Camera) Draw ¶
func (cam *Camera) Draw(worldObject *ebiten.Image, worldObjectOps *ebiten.DrawImageOptions, screen *ebiten.Image)
Draw applies the Camera's geometric transformation then draws the object on the screen with drawing options.
func (*Camera) DrawWithColorM ¶ added in v2.93.0
func (cam *Camera) DrawWithColorM(worldObject *ebiten.Image, cm colorm.ColorM, worldObjectOps *colorm.DrawImageOptions, screen *ebiten.Image)
DrawWithColorM applies the Camera's geometric transformation then draws the object on the screen with colorm package drawing options.
func (*Camera) LookAt ¶
LookAt aligns the midpoint of the camera viewport to the target.
Camera motion smoothing is only applied with this method. Use this function only once in Update() and change only the (targetX, targetY)
func (*Camera) Right ¶ added in v2.95.1
Right returns the right edge position of the camera in world-space.
func (*Camera) ScreenToWorld ¶
ScreenToWorld converts screen-space coordinates to world-space
func (*Camera) SetCenter ¶ added in v2.95.2
SetCenter sets center position of the camera in world-space.
Unlike the LookAt() method, the position is set directly (teleport).
Can be used to cancel follow camera and teleport to target.
func (*Camera) SetTopLeft ¶ added in v2.95.1
SetTopLeft sets top-left position of the camera in world-space.
Unlike the LookAt() method, the position is set directly (teleport).
type ShakeOptions ¶ added in v2.93.0
type ShakeOptions struct {
// Noise generator for noise types and settings.
Noise *fastnoise.NoiseState[float64]
MaxX float64 // Maximum X-axis shake. 0 means disabled
MaxY float64 // Maximum Y-axis shake. 0 means disabled
MaxAngle float64 // Max shake angle (radians). 0 means disabled
MaxZoomFactor float64 // Zoom factor strength [1-0]. 0 means disabled
TimeScale float64 // Noise time domain speed
Decay float64 // Decay for trauma
}
func DefaultCameraShakeOptions ¶
func DefaultCameraShakeOptions() *ShakeOptions
type SmoothOptions ¶ added in v2.9.0
type SmoothOptions struct {
// LerpSpeedX is the X-axis linear interpolation speed every frame.
// Value is in the range [0-1]. Default value is 0.09
//
// A smaller value will reach the target slower.
LerpSpeedX float64
// LerpSpeedY is the Y-axis linear interpolation speed every frame. Value is in the range [0-1].
//
// A smaller value will reach the target slower.
LerpSpeedY float64
// SmoothDampTimeX is the X-Axis approximate time it will take to reach the target.
//
// A smaller value will reach the target faster. Default value is 0.2
SmoothDampTimeX float64
// SmoothDampTimeY is the Y-Axis approximate time it will take to reach the target.
//
// A smaller value will reach the target faster. Default value is 0.2
SmoothDampTimeY float64
// SmoothDampMaxSpeedX is the maximum speed the camera can move while smooth damping in X-Axis
//
// Default value is 1000
SmoothDampMaxSpeedX float64
// SmoothDampMaxSpeedY is the maximum speed the camera can move while smooth damping in Y-Axis
//
// Default value is 1000
SmoothDampMaxSpeedY float64
}
SmoothOptions is the camera movement smoothing options.
func DefaultSmoothOptions ¶ added in v2.9.0
func DefaultSmoothOptions() *SmoothOptions
type SmoothType ¶ added in v2.93.0
type SmoothType int
SmoothType is the camera movement smoothing type.
const ( // None is instant movement to the target. No smoothing. None SmoothType = iota // Lerp is Lerp() function. Lerp // SmoothDamp is SmoothDamp() function. SmoothDamp )