示例#1
0
文件: camera.go 项目: Lealen/engi
func NewMouseZoomer(zoomSpeed float32) *MouseZoomer {
	es := &MouseZoomer{
		zoomSpeed: zoomSpeed,
	}
	es.New(nil)
	es.AddEntity(ecs.NewEntity([]string{es.Type()}))
	return es
}
示例#2
0
文件: camera.go 项目: Lealen/engi
func NewEdgeScroller(scrollSpeed float32, margin float64) *EdgeScroller {
	es := &EdgeScroller{
		scrollSpeed: scrollSpeed,
		margin:      margin,
	}
	es.New(nil)
	es.AddEntity(ecs.NewEntity([]string{es.Type()}))
	return es
}
示例#3
0
文件: camera.go 项目: Lealen/engi
func NewKeyboardScroller(scrollSpeed float32, up, right, down, left Key) *KeyboardScroller {
	kbs := &KeyboardScroller{
		scrollSpeed: scrollSpeed,
	}
	kbs.New(nil)
	kbs.BindKeyboard(up, right, down, left)
	kbs.AddEntity(ecs.NewEntity([]string{kbs.Type()}))
	return kbs
}
示例#4
0
// BenchmarkEntity1000 creates 1000 `Entity`s which all depend on the `NilSystem`
func BenchmarkEntity1000(b *testing.B) {
	const count = 1000

	preload := func() {}
	setup := func(w *ecs.World) {
		w.AddSystem(&NilSystem{})
		for i := 0; i < count; i++ {
			w.AddEntity(ecs.NewEntity([]string{"NilSystem"}))
		}
	}
	Bench(b, preload, setup)
}
示例#5
0
文件: camera.go 项目: Lealen/engi
func (cam *cameraSystem) New(*ecs.World) {
	cam.System = ecs.NewSystem()

	cam.x = WorldBounds.Max.X / 2
	cam.y = WorldBounds.Max.Y / 2
	cam.z = 1

	cam.AddEntity(ecs.NewEntity([]string{cam.Type()}))

	Mailbox.Listen("CameraMessage", func(msg Message) {
		cammsg, ok := msg.(CameraMessage)
		if !ok {
			return
		}

		if cammsg.Incremental {
			switch cammsg.Axis {
			case XAxis:
				cam.moveX(cammsg.Value)
			case YAxis:
				cam.moveY(cammsg.Value)
			case ZAxis:
				cam.zoom(cammsg.Value)
			}
		} else {
			switch cammsg.Axis {
			case XAxis:
				cam.moveToX(cammsg.Value)
			case YAxis:
				cam.moveToY(cammsg.Value)
			case ZAxis:
				cam.zoomTo(cammsg.Value)
			}
		}
	})
}