示例#1
0
func (sp *SmoothFollow) LateUpdate() {
	camera := engine.CurrentCamera()
	if camera != nil {
		myPos := sp.Target.Transform().Position()
		camPos := camera.Transform().Position()

		if sp.Speed > 0 {
			camPos = engine.Lerp(camPos, myPos, float32(engine.DeltaTime())*sp.Speed)
			disX := camPos.X - myPos.X
			disY := camPos.Y - myPos.Y
			if float32(math.Abs(float64(disX))) > sp.MaxDis {
				if disX < 0 {
					camPos.X = myPos.X - sp.MaxDis
				} else {
					camPos.X = myPos.X + sp.MaxDis
				}
			}
			if float32(math.Abs(float64(disY))) > sp.MaxDis {
				if disY < 0 {
					camPos.Y = myPos.Y - sp.MaxDis
				} else {
					camPos.Y = myPos.Y + sp.MaxDis
				}
			}
		} else {
			camPos = myPos
		}
		camera.Transform().SetPosition(camPos)
	}
}
示例#2
0
func (b *back) Update() {
	camera := engine.GetScene().SceneBase().Camera
	if camera != nil {
		myPos := engine.Vector{b.Transform().Position().X - float32(engine.Width/2), b.Transform().Position().Y - float32(engine.Height/2), 0}
		camPos := camera.Transform().Position()

		myPos = engine.Lerp(myPos, camPos, float32(engine.DeltaTime())*5)
		disX := myPos.X - camPos.X
		disY := myPos.Y - camPos.Y
		var MaxDis float32 = 300
		if float32(math.Abs(float64(disX))) > MaxDis {
			if disX < 0 {
				myPos.X = MaxDis - myPos.X
			} else {
				myPos.X = myPos.X + MaxDis
			}
		}
		if float32(math.Abs(float64(disY))) > MaxDis {
			if disY < 0 {
				myPos.Y = MaxDis - myPos.Y
			} else {
				myPos.Y = myPos.Y + MaxDis
			}
		}

		b.Transform().SetPosition(camPos)
	}
}