代码拉取完成,页面将自动刷新
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)//从组件表删除
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。