Documentation ¶
Overview ¶
動作橋段
孤 使用 sdl2 封裝的一個 2d 遊戲引擎
Index ¶
- Constants
- func CreateWindow(title string, w, h, fps int) error
- func DestoryEngine()
- func DestoryWindow()
- func GetWindow() *sdl.Window
- func InitEngine() error
- func LoadTexture(file string) (*sdl.Texture, error)
- func LoadTextureMem(b []byte) (*sdl.Texture, error)
- func PushEvent(evt interface{})
- func PushScene(scene IObject)
- func Run(r, g, b, a uint8, show bool)
- func SetFocus(obj IObject)
- type ActionAlphaTo
- type ActionBase
- func (a *ActionBase) Destroy()
- func (a *ActionBase) GetAutoDestroy() bool
- func (a *ActionBase) GetCallBack() (ActionCallBack, interface{})
- func (a *ActionBase) GetLoop() bool
- func (a *ActionBase) SetAutoDestory(yes bool)
- func (a *ActionBase) SetCallBack(callback ActionCallBack, params interface{})
- func (a *ActionBase) SetLoop(yes bool)
- type ActionCallBack
- type ActionLinear
- type ActionMoveTo
- type ActionMovie
- type ActionScaleTo
- type ActionTogether
- type Director
- type FocusInEvent
- type FocusOutEvent
- type IAction
- type IObject
- type IUi
- type Node
- func (n *Node) Add(obj IObject)
- func (n *Node) BindAction(a IAction)
- func (n *Node) Destroy()
- func (n *Node) Draw(renderer *sdl.Renderer, duration time.Duration)
- func (n *Node) GetAlpha() float64
- func (n *Node) GetAnchor() (anchorX, anchorY float64)
- func (n *Node) GetDrawPos() (float64, float64)
- func (n *Node) GetDrawScale() (float64, float64)
- func (n *Node) GetDrawSize() (float64, float64)
- func (n *Node) GetId() string
- func (n *Node) GetMaxZ() int
- func (n *Node) GetMinZ() int
- func (n *Node) GetParent() IObject
- func (n *Node) GetPos() (float64, float64)
- func (n *Node) GetScale() (float64, float64)
- func (n *Node) GetScaleX() float64
- func (n *Node) GetScaleY() float64
- func (n *Node) GetSize() (int, int)
- func (n *Node) GetTag() string
- func (n *Node) GetTexture() *sdl.Texture
- func (n *Node) GetZ() int
- func (n *Node) IsVisible() bool
- func (n *Node) LenChilds() int
- func (n *Node) OnAction(duration time.Duration)
- func (n *Node) OnEvent(evt sdl.Event) bool
- func (n *Node) Remove(obj IObject)
- func (n *Node) RemoveAction(a IAction)
- func (n *Node) RemoveById(id string)
- func (n *Node) RemoveByTag(tag string)
- func (n *Node) SetAlpha(a float64)
- func (n *Node) SetAnchor(anchorX, anchorY float64)
- func (n *Node) SetAnchorX(anchor float64)
- func (n *Node) SetAnchorY(anchor float64)
- func (n *Node) SetId(id string)
- func (n *Node) SetParent(obj IObject)
- func (n *Node) SetPos(x float64, y float64)
- func (n *Node) SetScale(scaleX, scaleY float64)
- func (n *Node) SetScaleX(scale float64)
- func (n *Node) SetScaleY(scale float64)
- func (n *Node) SetSize(w int, h int)
- func (n *Node) SetTag(tag string)
- func (n *Node) SetTexture(texture *sdl.Texture)
- func (n *Node) SetVisible(ok bool)
- func (n *Node) SetZ(z int)
- func (n *Node) ToPos(x, y float64) (float64, float64)
- func (n *Node) ToScreenPos(x, y float64) (float64, float64)
- type RendererFlip
- type UiBase
- type UiBtuuon
- type UiCallBack
- type UiDialog
- type UiLabel
- func (u *UiLabel) Destroy()
- func (u *UiLabel) Draw(renderer *sdl.Renderer, duration time.Duration)
- func (u *UiLabel) GetColor() sdl.Color
- func (u *UiLabel) GetPadding() int32
- func (u *UiLabel) GetValue() string
- func (u *UiLabel) SetColor(color sdl.Color)
- func (u *UiLabel) SetPadding(pading int32)
- func (u *UiLabel) SetValue(val string)
- type UiLineEdit
- func (u *UiLineEdit) Destroy()
- func (u *UiLineEdit) Draw(renderer *sdl.Renderer, duration time.Duration)
- func (u *UiLineEdit) GetBackgroundColor() sdl.Color
- func (u *UiLineEdit) GetChartRGB() (r uint8, g uint8, b uint8)
- func (u *UiLineEdit) GetColor() sdl.Color
- func (u *UiLineEdit) GetMax() int
- func (u *UiLineEdit) GetPwdChar() string
- func (u *UiLineEdit) GetValue() string
- func (u *UiLineEdit) IsPwd() bool
- func (u *UiLineEdit) OnEvent(evt sdl.Event) bool
- func (u *UiLineEdit) ReplaceRune(arrs []rune) error
- func (u *UiLineEdit) ReplaceStr(str string) error
- func (u *UiLineEdit) Select(begin, end int)
- func (u *UiLineEdit) SelectAll()
- func (u *UiLineEdit) SetBackgroundColor(color sdl.Color)
- func (u *UiLineEdit) SetChartRGB(r, g, b uint8)
- func (u *UiLineEdit) SetColor(color sdl.Color)
- func (u *UiLineEdit) SetMax(max int)
- func (u *UiLineEdit) SetPwd(yes bool)
- func (u *UiLineEdit) SetPwdChar(c string)
- func (u *UiLineEdit) SetValue(text string)
Constants ¶
View Source
const ( //鼠標 單擊 UI_EVT_LBTN_CLICK = "k-lbtn_click" UI_EVT_RBTN_CLICK = "k-rbtn_click" UI_EVT_MBTN_CLICK = "k-mbtn_click" //鼠標 雙擊 UI_EVT_LBTN_DCLICK = "k-lbtn_dclick" UI_EVT_RBTN_DCLICK = "k-rbtn_dclick" UI_EVT_MBTN_DCLICK = "k-mbtn_dclick" //鍵盤 按鍵 UI_EVT_KEY_DOWM = "k-key-down" UI_EVT_KEY_UP = "k-key-up" //焦點 UI_EVT_FOCUS_IN = "k-foucs-in" UI_EVT_FOCUS_OUT = "k-foucs-out" )
View Source
const ( R_MASK = 0x000000ff G_MASK = 0x0000ff00 B_MASK = 0x00ff0000 A_MASK = 0xff000000 )
View Source
const ( FLIP_NONE = sdl.FLIP_NONE FLIP_HORIZONTAL = sdl.FLIP_HORIZONTAL FLIP_VERTICAL = sdl.FLIP_VERTICAL )
View Source
const ( FONT_DEFAULT_FILE = "NotoSansCJKtc-Regular.otf" FONT_DEFAULT_SIZE = 16 )
View Source
const (
BUFFER_INIT_COUNT = 10
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActionAlphaTo ¶
type ActionAlphaTo struct { ActionBase // contains filtered or unexported fields }
勻速 改變 Alpha 到指定值
func NewActionAlphaTo ¶
func NewActionAlphaTo(alpha float64, duration time.Duration) *ActionAlphaTo
alpha 目標alpha duration 花費時間
type ActionBase ¶
type ActionBase struct {
// contains filtered or unexported fields
}
func (*ActionBase) GetAutoDestroy ¶
func (a *ActionBase) GetAutoDestroy() bool
是否自動 釋放 返回 true 移除action時 自動調用 a.Destroy()
func (*ActionBase) GetCallBack ¶
func (a *ActionBase) GetCallBack() (ActionCallBack, interface{})
返回 action 完成 通知
func (*ActionBase) SetAutoDestory ¶
func (a *ActionBase) SetAutoDestory(yes bool)
func (*ActionBase) SetCallBack ¶
func (a *ActionBase) SetCallBack(callback ActionCallBack, params interface{})
func (*ActionBase) SetLoop ¶
func (a *ActionBase) SetLoop(yes bool)
type ActionCallBack ¶
動作執行完一個週期後的 回調
type ActionLinear ¶
type ActionLinear struct { ActionBase // contains filtered or unexported fields }
將多個 action 線性執行 對於 ActionLinear 中的 Action GetLoop() 的返回值 會被忽略直接以 false 處理
type ActionMoveTo ¶
type ActionMoveTo struct { ActionBase // contains filtered or unexported fields }
勻速 移動到 指定 坐標
func NewActionMoveTo ¶
func NewActionMoveTo(x, y float64, duration time.Duration) *ActionMoveTo
x,y 目標坐標 duration 花費時間
type ActionMovie ¶
type ActionMovie struct { ActionBase // contains filtered or unexported fields }
播放動畫
func NewActionMovie ¶
func NewActionMovie(n int, duration time.Duration) *ActionMovie
n 預計紋理數量 duration 花費時間
type ActionScaleTo ¶
type ActionScaleTo struct { ActionBase // contains filtered or unexported fields }
勻速 改變 scale x y 到指定值
func NewActionScaleTo ¶
func NewActionScaleTo(scaleX, scaleY float64, duration time.Duration) *ActionScaleTo
scaleX scaleY 目標scale duration 花費時間
type ActionTogether ¶
type ActionTogether struct { ActionBase // contains filtered or unexported fields }
將多個 action 並行執行 ActionTogether 的 callback 會在 所有 action 完成後被 調用
type IAction ¶
type IAction interface { //執行動作 DoAction(node IObject, duration time.Duration) //釋放 動作 Destroy() //是否自動 釋放 //返回 true 移除action時 自動調用 a.Destory() GetAutoDestroy() bool SetAutoDestory(yes bool) //返回一個動作副本 Clone() IAction //設置 action 完成 通知 SetCallBack(callback ActionCallBack, params interface{}) //返回 action 完成 通知 GetCallBack() (ActionCallBack, interface{}) //返回 是否 循環執行 GetLoop() bool //設置 是否 循環執行 SetLoop(yes bool) }
施加到 演員的 動作定義
type IObject ¶
type IObject interface { //繪製自己 Draw(renderer *sdl.Renderer, duration time.Duration) //執行動作 OnAction(duration time.Duration) //處理 事件 返回 true 停止事件傳遞 OnEvent(evt sdl.Event) bool //是否可見 IsVisible() bool //設置是否可見 SetVisible(yes bool) //返回 坐標 (相對父節點) GetPos() (float64, float64) //坐標轉 屏幕坐標 ToScreenPos(x, y float64) (float64, float64) //坐標轉 相對坐標 ToPos(x, y float64) (float64, float64) //設置 坐標 SetPos(x float64, y float64) //返回 大小 GetSize() (int, int) //設置 大小 SetSize(w int, h int) //返回繪製坐標 GetDrawPos() (float64, float64) //返回繪製 大小 GetDrawSize() (float64, float64) //返回 z 坐標 GetZ() int //返回 z 坐標 SetZ(z int) //返回 子節點中的 最大 z 坐標 GetMaxZ() int //返回 子節點中的 最小 z 坐標 GetMinZ() int //銷毀 元素 Destroy() //設置元素 id SetId(id string) //設置元素 Tag SetTag(tag string) //返回元素 id GetId() string //返回元素 Tag GetTag() string //增加一個 子元素 Add(obj IObject) //刪除一個 子元素 Remove(obj IObject) //刪除一個 指定id的 子元素 RemoveById(id string) //刪除 指定 tag 的元素 RemoveByTag(tag string) //返回 子元素 數量 LenChilds() int //返回 父節點 GetParent() IObject //設置 父節點 SetParent(parent IObject) //綁定一個 動作 多次 bind 的 動作 同時被執行 BindAction(a IAction) //移除一個 動作 RemoveAction(a IAction) //設置紋理 SetTexture(texture *sdl.Texture) //返回當前 紋理 GetTexture() *sdl.Texture //返回 錨點 GetAnchor() (anchorX, anchorY float64) //設置 錨點 SetAnchor(anchorX, anchorY float64) SetAnchorX(anchor float64) SetAnchorY(anchor float64) //設置 透明度 SetAlpha(a float64) //返回 透明度 GetAlpha() float64 //設置 縮放 SetScale(scaleX, scaleY float64) SetScaleX(scaleX float64) SetScaleY(scaleY float64) //返回 縮放 GetScale() (scaleX float64, scaleY float64) GetScaleX() float64 GetScaleY() float64 }
基礎接口定義
type IUi ¶
type IUi interface { IObject //設置 事件回調 SetEventCallback(evt string, callback UiCallBack) //返回 事件回調 函數 GetEventCallback(evt string) UiCallBack }
type Node ¶
type Node struct { //紋理 Texture *sdl.Texture //坐標 大小 X, Y float64 //放大縮小 [0,+...) ScaleX, ScaleY float64 Width, Height int //z坐標 值越小 越先繪製 越後響應事件 Z int //錨點 [0,1] AnchorX, AnchorY float64 //旋轉角度 Angle float64 //翻轉 Flip sdl.RendererFlip //透明 Alpha float64 // contains filtered or unexported fields }
基礎 接口 實現
func (*Node) GetDrawScale ¶
func (*Node) SetAnchorX ¶
func (*Node) SetAnchorY ¶
type RendererFlip ¶
type RendererFlip sdl.RendererFlip
type UiBase ¶
type UiBase struct { Node // contains filtered or unexported fields }
func (*UiBase) GetEventCallback ¶
func (u *UiBase) GetEventCallback(evt string) UiCallBack
返回 事件回調 函數
func (*UiBase) SetEventCallback ¶
func (u *UiBase) SetEventCallback(evt string, callback UiCallBack)
設置 事件回調
type UiBtuuon ¶
type UiBtuuon struct { UiBase // contains filtered or unexported fields }
按鈕
func NewUiBtuuon ¶
type UiDialog ¶
type UiDialog struct { UiBase // contains filtered or unexported fields }
對話框 對於模式對話框 需要自己保證 其 z 值爲最大
func NewUiDialog ¶
type UiLabel ¶
type UiLabel struct { UiBase // contains filtered or unexported fields }
靜態文本框
func NewUiLabel ¶
func (*UiLabel) GetPadding ¶
func (*UiLabel) SetPadding ¶
type UiLineEdit ¶
type UiLineEdit struct { UiBase // contains filtered or unexported fields }
單行編輯框
func NewUiLineEdit ¶
func NewUiLineEdit() (*UiLineEdit, error)
func NewUiLineEditFont ¶
func NewUiLineEditFont(fFile string, fSize int) (*UiLineEdit, error)
func (*UiLineEdit) Destroy ¶
func (u *UiLineEdit) Destroy()
func (*UiLineEdit) GetBackgroundColor ¶
func (u *UiLineEdit) GetBackgroundColor() sdl.Color
func (*UiLineEdit) GetChartRGB ¶
func (u *UiLineEdit) GetChartRGB() (r uint8, g uint8, b uint8)
func (*UiLineEdit) GetColor ¶
func (u *UiLineEdit) GetColor() sdl.Color
func (*UiLineEdit) GetValue ¶
func (u *UiLineEdit) GetValue() string
func (*UiLineEdit) ReplaceRune ¶
func (u *UiLineEdit) ReplaceRune(arrs []rune) error
將 選中項 以 []rune 替換
func (*UiLineEdit) SetBackgroundColor ¶
func (u *UiLineEdit) SetBackgroundColor(color sdl.Color)
func (*UiLineEdit) SetChartRGB ¶
func (u *UiLineEdit) SetChartRGB(r, g, b uint8)
func (*UiLineEdit) SetColor ¶
func (u *UiLineEdit) SetColor(color sdl.Color)
func (*UiLineEdit) SetValue ¶
func (u *UiLineEdit) SetValue(text string)
Click to show internal directories.
Click to hide internal directories.