瓦片增加一个Loading动画
可以查看我的另一个博客WPF中自定义Loading图
从中心扩散
进行从里到外的扩散,方向是上左下右。如下图所示
文章来源:https://www.toymoban.com/news/detail-667797.html
于是我们可以定义一个拥有坐标X跟Y的集合,他允许这个集合,内部使用枚举器的MoveNext自动排序,中心的在前,外面在后。文章来源地址https://www.toymoban.com/news/detail-667797.html
public class SpiralArray : IEnumerable<(int, int)>
{
protected (int, int) Range;
public SpiralArray((int, int) range)
{
Range = range;
}
public IEnumerator<(int, int)> GetEnumerator()
{
return new SpiralArrayIEnumerator(Range);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class SpiralArrayIEnumerator : IEnumerator<(int, int)>
{
public int Start;
public int End;
public int CenterX;
public int CenterY;
private bool IsOver = false;
private int Direction = 0;// 0 上 1 左 2 : 下 3 : 右
private int Step = 0;
private int CurrentMoveSteps = 0;
private int ChangedDirectionTimes = 0; //改变方向次数
/// <summary>
/// 构造函数
/// </summary>
/// <param name="range"></param>
public SpiralArrayIEnumerator((int, int) range)
{
Start = range.Item1;
End = range.Item2;
Reset();
}
public (int, int) Current { get; set; }
object IEnumerator.Current => Current;
public void Dispose()
{
}
public bool MoveNext()
{
if(Step == 0)
{
Current = (CenterX, CenterY);
CurrentMoveSteps = 0;
Step = 1;
return true;
}
else
{
// 走一步
CurrentMoveSteps++;
// 改变方向
if(CurrentMoveSteps > Step)
{
Direction = (Direction + 1) % 4;
CurrentMoveSteps = 1;
ChangedDirectionTimes++;
if(ChangedDirectionTimes >= 2)
{
// 步长 + 1
Step++;
ChangedDirectionTimes = 0;
}
}
Move();
if(Current.Item1 >= End || Current.Item2 >= End || Current.Item1 < Start || Current.Item2 < Start)
return false;
return true;
}
}
/// <summary>
/// 移动一步
/// </summary>
private void Move()
{
switch (Direction)
{
// 上
case 0:
Current = (Current.Item1, Current.Item2 - 1);
break;
// 左
case 1:
Current = (Current.Item1 - 1, Current.Item2);
break;
// 下
case 2:
Current = (Current.Item1, Current.Item2 + 1);
break;
// 右
case 3:
Current = (Current.Item1 + 1, Current.Item2);
break;
default:
break;
}
}
public void Reset()
{
CenterX = (End + Start) / 2;
CenterY = (End + Start) / 2;
Current = (CenterX, CenterY);
Direction = 0;
Step = 0;
ChangedDirectionTimes = 0;
IsOver = false;
}
}
到了这里,关于WPF中手写地图控件(3)——动态加载地图图片的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!