1 Star 3 Fork 2

jiangtao99126 / Golang_2D_Engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Animation.go 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
jiangtao99126 提交于 2020-12-24 01:23 . 动画组件
package Sarah
import "github.com/faiface/pixel"
func CreateAnimation() *Animation {
a := new(Animation)
a.Index = 0.0
a.Time = 0.0
return a
}
type Animation struct {
Sprites []*Sprite
Index float64//图组索引
Time float64//运行的时长
pos pixel.Vec//位置
}
func (this *Animation) SetPos(x float64,y float64){
this.pos.X=x
this.pos.Y=y
for _,v := range this.Sprites{
v.pos = pixel.Vec{this.pos.X,this.pos.Y}
}
}
func (this *Animation) GetPos()(float64,float64){
return this.pos.X,this.pos.Y
}
func (this *Animation) AddPic(path string){
pic,err := LoadPicture_l(path)
CheckError(err)
s := CreatSprite(path)
s.Sprite = pixel.NewSprite(pic,pic.Bounds())
s.pos = this.pos
this.Sprites = append(this.Sprites,s)
}
func (this *Animation) set_index(){
if int(this.Index) == len(this.Sprites)-1 {
this.Index = 0.0
}else {
this.Index+=0.2
}
}
func (this *Animation) Play(scene *SceneManager){
this.set_index()
this.Sprites[int(this.Index)].Draw(scene,1)
}
Go
1
https://gitee.com/jangtao99126/Golang2dEngine-Sarah.git
git@gitee.com:jangtao99126/Golang2dEngine-Sarah.git
jangtao99126
Golang2dEngine-Sarah
Golang_2D_Engine
master

搜索帮助