跳轉到

Class gridpp::GridObject

ClassList > gridpp > GridObject

操作遊戲世界中單一網格物件的 handler。 More...

  • #include <GridObject.h>

Public Functions

Type Name
GridObject () = default
建立不指向任何物件的 handler。
Color color () const
GridObject deepCopy () const
int direction () const
bool exists () const
int get (const std::string & key, int & value) const
int get (const std::string & key, long long & value) const
int get (const std::string & key, double & value) const
int get (const std::string & key, bool & value) const
int get (const std::string & key, std::string & value) const
int get (const std::string & key, std::vector< T > & value) const
void hide ()
隱藏物件;隱藏期間仍會更新,但不會繪製或參與碰撞。
std::string image () const
int layer () const
void move (int dx, int dy)
將物件相對移動 dx 欄、dy 列。
void remove ()
從引擎移除物件;呼叫後所有指向它的 handler 都會失效。
void set (const std::string & key, int value)
以 key 儲存整數;int 與 long long 都以 long long 保存。
void set (const std::string & key, long long value)
以 key 儲存長整數。
void set (const std::string & key, double value)
以 key 儲存浮點數。
void set (const std::string & key, bool value)
以 key 儲存布林值。
void set (const std::string & key, const std::string & value)
以 key 儲存字串。
void set (const std::string & key, const char * value)
以 key 儲存 C 字串;內部會複製為 std::string。
void set (const std::string & key, const std::vector< T > & value)
以 key 儲存指定類型的 vector。
void setCollideFunction (CollisionCallback function)
取代碰撞 callback。
void setColor (Color color)
設定圖片 tint 或幾何形狀的顏色。
void setDirection (int direction)
設定繪製方向;輸入會正規化至 0 到 3。
void setImage (const std::string & image)
設定圖片物件使用的素材名稱。
void setInitFunction (GridObjectCallback function)
取代初始化 callback;若物件已初始化,新函式不會自動補呼叫。
void setLayer (int layer)
設定繪製層級;數值越大越晚繪製,相同層級保持建立順序。
void setPosition (int x, int y)
將物件移到指定網格座標。
void setUpdateFunction (GridObjectCallback function)
取代每幀更新 callback。
void show ()
顯示物件。
bool visible () const
int x () const
int y () const

Detailed Description

複製 handler 不會複製物件;所有複本仍指向同一個遊戲實體。物件被移除或 GameEngine 銷毀後,可以用 exists() 檢查 handler 是否仍有效。除 exists() 之外,對失效 handler 呼叫其他函式會拋出 std::runtime_error。

Public Functions Documentation

function GridObject

建立不指向任何物件的 handler。

gridpp::GridObject::GridObject () = default


function color

inline Color gridpp::GridObject::color () const

Returns:

圖片 tint 或幾何形狀的顏色。


function deepCopy

inline GridObject gridpp::GridObject::deepCopy () const

Returns:

一個擁有獨立狀態、callback 與新 handler 的物件複本。


function direction

inline int gridpp::GridObject::direction () const

Returns:

繪製方向,0 到 3 分別表示逆時針旋轉 0°、90°、180° 與 270°。


function exists

inline bool gridpp::GridObject::exists () const

Returns:

handler 是否仍指向存在的物件。


function get [1/6]

inline int gridpp::GridObject::get (
    const std::string & key,
    int & value
) const

Returns:

找到 key 時為 0;找不到時將 value 清為預設值並回傳 1。

Exception:

  • std::runtime_error 若類型不同,或儲存的整數無法容納於 int。

function get [2/6]

inline int gridpp::GridObject::get (
    const std::string & key,
    long long & value
) const

Returns:

找到 key 時為 0;找不到時將 value 清為預設值並回傳 1。

Exception:

  • std::runtime_error 若取值類型與儲存類型不同。

function get [3/6]

inline int gridpp::GridObject::get (
    const std::string & key,
    double & value
) const

Returns:

找到 key 時為 0;找不到時將 value 清為預設值並回傳 1。

Exception:

  • std::runtime_error 若取值類型與儲存類型不同。

function get [4/6]

inline int gridpp::GridObject::get (
    const std::string & key,
    bool & value
) const

Returns:

找到 key 時為 0;找不到時將 value 清為預設值並回傳 1。

Exception:

  • std::runtime_error 若取值類型與儲存類型不同。

function get [5/6]

inline int gridpp::GridObject::get (
    const std::string & key,
    std::string & value
) const

Returns:

找到 key 時為 0;找不到時將 value 清為預設值並回傳 1。

Exception:

  • std::runtime_error 若取值類型與儲存類型不同。

function get [6/6]

template<typename T>
inline int gridpp::GridObject::get (
    const std::string & key,
    std::vector< T > & value
) const

Returns:

找到 key 時為 0;找不到時將 value 清為空 vector 並回傳 1。

Exception:

  • std::runtime_error 若取值類型與儲存類型不同。

function hide

隱藏物件;隱藏期間仍會更新,但不會繪製或參與碰撞。

inline void gridpp::GridObject::hide () 


function image

inline std::string gridpp::GridObject::image () const

Returns:

圖片物件的素材名稱。

Exception:

  • std::runtime_error 若此 handler 指向幾何形狀。

function layer

inline int gridpp::GridObject::layer () const

Returns:

物件的繪製層級。


function move

將物件相對移動 dx 欄、dy 列。

inline void gridpp::GridObject::move (
    int dx,
    int dy
) 


function remove

從引擎移除物件;呼叫後所有指向它的 handler 都會失效。

inline void gridpp::GridObject::remove () 


function set [1/7]

以 key 儲存整數;int 與 long long 都以 long long 保存。

inline void gridpp::GridObject::set (
    const std::string & key,
    int value
) 


function set [2/7]

以 key 儲存長整數。

inline void gridpp::GridObject::set (
    const std::string & key,
    long long value
) 


function set [3/7]

以 key 儲存浮點數。

inline void gridpp::GridObject::set (
    const std::string & key,
    double value
) 


function set [4/7]

以 key 儲存布林值。

inline void gridpp::GridObject::set (
    const std::string & key,
    bool value
) 


function set [5/7]

以 key 儲存字串。

inline void gridpp::GridObject::set (
    const std::string & key,
    const std::string & value
) 


function set [6/7]

以 key 儲存 C 字串;內部會複製為 std::string。

inline void gridpp::GridObject::set (
    const std::string & key,
    const char * value
) 


function set [7/7]

以 key 儲存指定類型的 vector。

template<typename T>
inline void gridpp::GridObject::set (
    const std::string & key,
    const std::vector< T > & value
) 


function setCollideFunction

取代碰撞 callback。

inline void gridpp::GridObject::setCollideFunction (
    CollisionCallback function
) 


function setColor

設定圖片 tint 或幾何形狀的顏色。

inline void gridpp::GridObject::setColor (
    Color color
) 


function setDirection

設定繪製方向;輸入會正規化至 0 到 3。

inline void gridpp::GridObject::setDirection (
    int direction
) 


function setImage

設定圖片物件使用的素材名稱。

inline void gridpp::GridObject::setImage (
    const std::string & image
) 

Exception:

  • std::runtime_error 若此 handler 指向幾何形狀。

function setInitFunction

取代初始化 callback;若物件已初始化,新函式不會自動補呼叫。

inline void gridpp::GridObject::setInitFunction (
    GridObjectCallback function
) 


function setLayer

設定繪製層級;數值越大越晚繪製,相同層級保持建立順序。

inline void gridpp::GridObject::setLayer (
    int layer
) 


function setPosition

將物件移到指定網格座標。

inline void gridpp::GridObject::setPosition (
    int x,
    int y
) 


function setUpdateFunction

取代每幀更新 callback。

inline void gridpp::GridObject::setUpdateFunction (
    GridObjectCallback function
) 


function show

顯示物件。

inline void gridpp::GridObject::show () 


function visible

inline bool gridpp::GridObject::visible () const

Returns:

物件是否可見。


function x

inline int gridpp::GridObject::x () const

Returns:

物件的網格 x 座標。


function y

inline int gridpp::GridObject::y () const

Returns:

物件的網格 y 座標。



The documentation for this class was generated from the following file GridObject.h