public new void Update() { //并行计算,调高运算速度 Parallel.ForEach <List <VisualElement> >(VisualElementLists, VisualElementList => { Parallel.ForEach <VisualElement>(VisualElementList, VisualElement => { VisualElement.Update(); }); //移除消失在屏幕左边的对象 if (VisualElementList.Count > 0) { while (VisualElementList.First().X <= -VisualElementList.First().Width) { VisualElementList.RemoveAt(0); } } }); //右边对象消失完毕后在右边追加新的对象 if (Mountains.Count > 0) { while (Mountains.Last().X + Mountains.Last().Width < in_WorldSize.Width) { CreateNewMountain(Mountains.Last().X + Mountains.Last().Width); } } if (Trees.Count > 0) { while (Trees.Last().X + Trees.Last().Width < in_WorldSize.Width) { CreateNewTree(Trees.Last().X + Trees.Last().Width); } } if (Buildings.Count > 0) { while (Buildings.Last().X + Buildings.Last().Width < in_WorldSize.Width) { CreateNewBuilding(Buildings.Last().X + Buildings.Last().Width); } } if (Grounds.Count > 0) { while (Grounds.Last().X + Grounds.Last().Width < in_WorldSize.Width) { CreateNewGround(Grounds.Last().X + Grounds.Last().Width); } } }
/// <summary> /// Get the element at the specified point. Usually this methods simply return the current element, but an element can return inner elements drawed inside the main elements. /// Returns a list of elements, where the last element is the upper element and the first element is the background element. /// </summary> /// <param name="measure"></param> /// <param name="area"></param> /// <param name="point"></param> /// <returns></returns> public virtual VisualElementList GetElementsAtPoint(MeasureHelper measure, System.Drawing.RectangleF area, PointF point) { VisualElementList list = new VisualElementList(); if (GetDrawingArea(measure, area).Contains(point)) list.Add(this); return list; }