1 Star 3 Fork 2

jiangtao99126 / Golang_2D_Engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Button.go 1003 Bytes
一键复制 编辑 原始数据 按行查看 历史
jiangtao99126 提交于 2020-12-24 01:30 . 按钮组件
package Sarah
import (
"github.com/faiface/pixel"
)
func MakeButton(x float64,y float64,str string)*Button {
return &Button{Pos: pixel.Vec{X: x,Y: y},Text: CreatText(x,y,str)}
}
type Button struct {
Width float64//宽
Height float64//高
Pos pixel.Vec//坐标
Bg_pic *pixel.Sprite//背景图
Text *Text//文字
Scale_status bool//缩放状态
}
func (this *Button) SetSize(width float64,height float64){
this.Width = width
this.Height = height
}
func (this *Button) SetPos(x float64,y float64){
this.Pos = pixel.Vec{X: x,Y: y}
}
//设置文字
func (this *Button) SetText(str string){
this.Text.str = str
}
func (this *Button)Draw(scene *SceneManager){
this.Scale()
//画一个矩形
imd := DrawRect(this.Pos,this.Width,this.Height)
imd.Draw(scene.Window)
//画出文字
this.Text.Draw(scene,1,this.Pos.X,this.Pos.Y)
}
//缩放
func (this *Button) Scale(){
if this.Scale_status == false{
this.Height = 50
this.Width = 100
}else{
this.Height = 75
this.Width = 200
}
}
Go
1
https://gitee.com/jangtao99126/Golang2dEngine-Sarah.git
git@gitee.com:jangtao99126/Golang2dEngine-Sarah.git
jangtao99126
Golang2dEngine-Sarah
Golang_2D_Engine
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891