1 Star 3 Fork 2

jiangtao99126 / Golang_2D_Engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Scene.go 2.42 KB
一键复制 编辑 原始数据 按行查看 历史
jiangtao99126 提交于 2020-12-24 01:51 . 场景
package Sarah
import (
"github.com/faiface/pixel/pixelgl"
"time"
)
func MakeSceneManager(window *pixelgl.Window) *SceneManager {
s := new(SceneManager)
s.Window = window
return s
}
type SceneManager struct {
Window *pixelgl.Window//窗口索引
Status bool//场景启动状态
Mouse_listener Mouse_listener//鼠标监听器
AudioPlayer *Audio_sound//音频播放器
KeyBord *KeyBord//键盘监听器
Camera *Camera//相机
Buttons map[string]*Button//按钮组件表
Sprite map[string]*Sprite//图像组件表
Animations map[string]*Animation//动画组件表
Text map[string]*Text//文字组件表
Rigid *Rigid//2d刚体
//计时器
Clock *Clock
//计时参数
DT float64
}
//初始化
func (this *SceneManager) Init(w *pixelgl.Window){
//设置场景启动状态为开启
this.Status = true
this.Window = w
//初始化相机
this.Camera = new(Camera)
this.AudioPlayer.Init("Sarah/init.wav")
//初始化键盘监听器
this.KeyBord = MakeKeyBord()
//初始化按钮组件表
this.Buttons = make(map[string]*Button)
//初始化图片件表
this.Sprite = make(map[string]*Sprite)
//初始化动画组件
this.Animations = make(map[string]*Animation)
//初始化文字组件
this.Text = make(map[string]*Text)
//初始化刚体系统
this.Rigid = new(Rigid)
this.Clock = new(Clock)
this.Clock.Work = make(map[string]float64)
}
//运行场景
func (this *SceneManager) Run(f func(s *SceneManager)){
Last := time.Now()
for this.Status == true && !this.Window.Closed(){
this.DT = time.Since(Last).Seconds()
Last = time.Now()
f(this)
this.Window.Update()
}
}
//按钮操作
func (this *SceneManager) AddButton(button *Button,id string){
//把按钮加入组件表
this.Buttons[id] = button
}
func (this *SceneManager) DeleteButton(id string){
delete(this.Buttons,id)//从组件表删除
}
//精灵操作
func (this *SceneManager) AddSprite(sprite *Sprite,id string){
this.Sprite[id] = sprite
}
func (this *SceneManager) DeleteSprite(id string){
delete(this.Sprite,id)//从组件表删除
}
//动画操作
func (this *SceneManager) AddAnimation(animation *Animation,id string){
this.Animations[id] = animation
}
func (this *SceneManager) DeleteAnimation(id string){
delete(this.Animations,id)//从组件表删除
}
//文字操作
func (this *SceneManager) AddText(text *Text,id string){
this.Text[id] = text
}
func (this *SceneManager) DeleteText(id string){
delete(this.Text,id)//从组件表删除
}
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