supertux
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Camera Class Referencefinal

A ""Camera"" that was given a name can be manipulated by scripts. More...

#include <camera.hpp>

Inheritance diagram for Camera:
Inheritance graph
[legend]
Collaboration diagram for Camera:
Collaboration graph
[legend]

Public Types

enum  Mode { NORMAL, MANUAL, AUTOSCROLL, SCROLLTO }
 

Public Member Functions

 Camera (const std::string &name)
 
 Camera (const ReaderMapping &reader)
 
virtual void update (float dt_sec) override
 This function is called once per frame and allows the object to update it's state. More...
 
virtual void draw (DrawingContext &) override
 The GameObject should draw itself onto the provided DrawingContext if this function is called. More...
 
virtual bool is_singleton () const override
 If true only a single object of this type is allowed in a given GameObjectManager.
 
virtual bool is_saveable () const override
 Indicates if the object will be saved. More...
 
virtual std::string get_class_name () const override
 
virtual std::string get_exposed_class_name () const override
 
virtual std::string get_display_name () const override
 Returns the display name of the object, translated to the user's locale.
 
virtual GameObjectClasses get_class_types () const override
 List notable classes in inheritance hierarchy of class. More...
 
virtual ObjectSettings get_settings () override
 
virtual void after_editor_set () override
 
void save_state () override
 Save/check the current state of the object. More...
 
void check_state () override
 
virtual const std::string get_icon_path () const override
 
Rectf get_rect () const
 
void reset (const Vector &tuxpos)
 reset camera position
 
const Vector get_translation () const
 return camera position
 
void set_translation (const Vector &translation)
 
void set_translation_centered (const Vector &translation)
 
void keep_in_bounds (const Rectf &bounds)
 
void shake (float duration, float x, float y)
 shake camera in a direction 1 time
 
void start_earthquake (float strength, float delay)
 Shake the camera vertically with a specified average strength, at a certain minimal delay, until stopped. More...
 
void stop_earthquake ()
 
void scroll_to (const Vector &goal, float scrolltime)
 scroll the upper left edge of the camera in scrolltime seconds to the position goal
 
void move (const Vector &offset)
 
Vector get_center () const
 get the coordinates of the point directly in the center of this camera
 
const Vector & get_position () const
 get the coordinates of the point directly in the top left of this camera
 
const Sizefget_screen_size () const
 get the width and height of the screen
 
void set_mode (Mode mode_)
 
Mode get_mode () const
 
float get_current_scale () const
 get the exact scale at this exact moment
 
float get_target_scale () const
 get the scale towards which the camera is moving
 
void ease_scale (float scale, float time, easing ease, AnchorPoint anchor=AnchorPoint::ANCHOR_MIDDLE)
 smoothly slide the scale and anchor position of the camera towards a new value
 
void set_pos (float x, float y)
 Moves the camera to the specified absolute position. More...
 
void move (float x, float y)
 Moves the camera ""x"" to the left and ""y"" down. More...
 
void set_mode (const std::string &mode)
 Sets the camera mode. More...
 
void scroll_to (float x, float y, float scrolltime)
 Scrolls the camera to specific coordinates in ""scrolltime"" seconds. More...
 
void set_scale (float scale)
 Sets the scale factor. More...
 
void set_scale_anchor (float scale, int anchor)
 Sets the scale factor and the target position anchor. More...
 
void scale (float scale, float time)
 Fades to a specified scale factor in ""time"" seconds. More...
 
void scale_anchor (float scale, float time, int anchor)
 Fades to a specified scale factor and target position anchor in ""time"" seconds. More...
 
void ease_scale (float scale, float time, const std::string &ease)
 Fades to a specified scale factor in ""time"" seconds with easing (smooth movement). More...
 
void ease_scale_anchor (float scale, float time, int anchor, const std::string &ease)
 Fades to a specified scale factor and target position anchor in ""time"" seconds with easing (smooth movement). More...
 
float get_screen_width () const
 Gets the current width of the screen.
 
float get_screen_height () const
 Gets the current height of the screen.
 
float get_x () const
 Gets the X coordinate of the top-left corner of the screen.
 
float get_y () const
 Gets the Y coordinate of the top-left corner of the screen.
 
- Public Member Functions inherited from GameObject
 GameObject (const std::string &name)
 
 GameObject (const ReaderMapping &reader)
 
virtual void finish_construction ()
 Called after all objects have been added to the Sector and the Sector is fully constructed. More...
 
UID get_uid () const
 
virtual void save (Writer &writer)
 This function saves the object. More...
 
std::string save ()
 
virtual std::vector< std::string > get_patches () const
 Version checking/updating, patch information.
 
virtual void update_version ()
 
int get_version () const
 Returns the current version of the object.
 
int get_latest_version () const
 Returns the latest version of the object.
 
bool is_up_to_date () const
 Checks whether the object's current version is equal to its latest one.
 
virtual bool has_variable_size () const
 Does this object have variable size (secret area trigger, wind, etc.)
 
virtual bool track_state () const
 Indicates if the object's state should be tracked. More...
 
virtual bool has_object_manager_priority () const
 Indicates if the object should be added at the beginning of the object list. More...
 
virtual bool has_settings () const
 Indicates if get_settings() is implemented. More...
 
virtual GameObjectTypes get_types () const
 Get all types of the object, if available. More...
 
int get_type () const
 Returns the type index of the object.
 
virtual void on_flip (float height)
 When level is flipped vertically.
 
virtual void remove_me ()
 schedules this object to be removed at the end of the frame
 
bool is_valid () const
 returns true if the object is not scheduled to be removed yet
 
void add_remove_listener (ObjectRemoveListener *listener)
 registers a remove listener which will be called if the object gets removed/destroyed
 
void del_remove_listener (ObjectRemoveListener *listener)
 unregisters a remove listener, so it will no longer be called if the object gets removed/destroyed
 
void set_name (const std::string &name)
 
const std::string & get_name () const
 Returns the name of the object.
 
virtual void stop_looping_sounds ()
 stops all looping sounds
 
virtual void play_looping_sounds ()
 continues all looping sounds
 
template<typename T >
T * get_component ()
 
void add_component (std::unique_ptr< GameObjectComponent > component)
 
void remove_component (GameObjectComponent *component)
 
virtual void editor_delete ()
 The editor requested the deletion of the object.
 
virtual void editor_select ()
 The user clicked on the object in the editor and selected it.
 
virtual void editor_deselect ()
 The object got deselected.
 
virtual void editor_update ()
 Called each frame in the editor, used to keep linked objects together (e.g. More...
 
GameObjectManagerget_parent () const
 
- Public Member Functions inherited from PathObject
void init_path (const ReaderMapping &mapping, bool running_default)
 For compatibilty reasons this needs to get the GameObjects main mapping, not the (path ...) mapping.
 
void init_path_pos (const Vector &pos, bool running=false)
 
PathGameObjectget_path_gameobject () const
 
Pathget_path () const
 
PathWalkerget_walker () const
 
void editor_clone_path (PathGameObject *path_object)
 
std::string get_path_ref () const
 
void editor_set_path_by_ref (const std::string &new_ref)
 
void goto_node (int node_idx)
 Moves the path object until at given node, then stops. More...
 
void set_node (int node_idx)
 Jumps instantly to the given node. More...
 
void start_moving ()
 Starts moving the path object automatically.
 
void stop_moving ()
 Stops moving the path object.
 

Static Public Member Functions

static void register_class (ssq::VM &vm)
 
static std::string class_name ()
 
static std::string display_name ()
 
- Static Public Member Functions inherited from GameObject
static void register_class (ssq::VM &vm)
 

Additional Inherited Members

- Protected Types inherited from GameObject
enum  TypeChange { INITIAL = -1 }
 When the type has been changed from the editor. More...
 
- Protected Member Functions inherited from GameObject
void parse_type (const ReaderMapping &reader)
 Parse object type. More...
 
virtual void on_type_change (int old_type)
 
int type_id_to_value (const std::string &id) const
 Conversion between type ID and value. More...
 
std::string type_value_to_id (int value) const
 
- Protected Member Functions inherited from PathObject
void save_state () const
 
void check_state () const
 
void on_flip ()
 
- Static Protected Member Functions inherited from PathObject
static void register_members (ssq::Class &cls)
 
- Protected Attributes inherited from GameObject
std::string m_name
 a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names being set or being unique
 
int m_type
 Type of the GameObject. More...
 
std::vector< std::unique_ptr< FadeHelper > > m_fade_helpers
 Fade Helpers are for easing/fading script functions.
 
bool m_track_undo
 Track the following creation/deletion of this object for undo. More...
 
- Protected Attributes inherited from PathObject
PathWalker::Handle m_path_handle
 

Detailed Description

A ""Camera"" that was given a name can be manipulated by scripts.

An instance named ""Camera"" (""sector.Camera"" in the console) is available.${SRG_NEWPARAGRAPH} The mode of the camera is either ""normal"" (the camera is following the player) or ""autoscroll"". In the latter mode, the camera is forced along a specified path.

Member Function Documentation

◆ ease_scale()

void Camera::ease_scale ( float  scale,
float  time,
const std::string &  ease 
)

Fades to a specified scale factor in ""time"" seconds with easing (smooth movement).

Parameters
float$scale
float$time
string$ease

◆ ease_scale_anchor()

void Camera::ease_scale_anchor ( float  scale,
float  time,
int  anchor,
const std::string &  ease 
)

Fades to a specified scale factor and target position anchor in ""time"" seconds with easing (smooth movement).

NOTE: Target position anchor is only applied, if the camera is in "manual" mode.

Parameters
float$scale
float$time
int$anchorAnchor point as represented by the ""ANCHOR_*"" constants (see ${SRG_REF_AnchorPoints}).
string$ease

◆ move()

void Camera::move ( float  x,
float  y 
)

Moves the camera ""x"" to the left and ""y"" down.

Parameters
float$x
float$y

◆ scale()

void Camera::scale ( float  scale,
float  time 
)

Fades to a specified scale factor in ""time"" seconds.

Parameters
float$scale
float$time

◆ scale_anchor()

void Camera::scale_anchor ( float  scale,
float  time,
int  anchor 
)

Fades to a specified scale factor and target position anchor in ""time"" seconds.

NOTE: Target position anchor is only applied, if the camera is in "manual" mode.

Parameters
float$scale
float$time
int$anchorAnchor point as represented by the ""ANCHOR_*"" constants (see ${SRG_REF_AnchorPoints}).

◆ scroll_to()

void Camera::scroll_to ( float  x,
float  y,
float  scrolltime 
)

Scrolls the camera to specific coordinates in ""scrolltime"" seconds.

Parameters
float$x
float$y
float$scrolltime

◆ set_mode()

void Camera::set_mode ( const std::string &  mode)

Sets the camera mode.

Parameters
string$modeThe mode can be "normal" or "manual".

◆ set_pos()

void Camera::set_pos ( float  x,
float  y 
)

Moves the camera to the specified absolute position.

The origin is at the top left.

Parameters
float$x
float$y

◆ set_scale()

void Camera::set_scale ( float  scale)

Sets the scale factor.

Parameters
float$scale

◆ set_scale_anchor()

void Camera::set_scale_anchor ( float  scale,
int  anchor 
)

Sets the scale factor and the target position anchor.

NOTE: Target position anchor is only applied, if the camera is in "manual" mode.

Parameters
float$scale
int$anchorAnchor point as represented by the ""ANCHOR_*"" constants (see ${SRG_REF_AnchorPoints}).

The documentation for this class was generated from the following files: