1
我製作了一個Canvas(playArea),我在其上添加了1個Bee(使用playArea.children.Add(bee)
)。並且我還在playArea
的隨機點每X秒添加新的box
。我可以將我的bee
從當前點移動到點擊使用Storyboard
和DoubleAnimation
。C#每當另一個UIElement通過他時刪除UIElement
我想要做什麼是我想要刪除的box
這bee
是通過(像它應該只是做playAre.Children.Remove(box)
。我只是無法弄清楚如何去檢查一下。
下面是一個例子,如果我點擊A,我的bee
會去那個地方,並且移除3個盒子,我想我應該用我自己的EventHandler
(我不知道如何讓我自己做,但這是另一個問題)所以任何ide應該怎麼做,或者我應該做什麼條件?
編輯: 以下是我使用的方法的樣子。我在beggining做什麼,我只是畫一個蜜蜂,並把它添加到我的畫布,而每X秒我只是在隨機位置
//moving the bee to the position which I got from Point p = Mouse.GetPosition(playArea);
public static void MoveBee(UIElement element, double toX, double toY)
{
double fromX = Canvas.GetLeft(element);
double fromY = Canvas.GetTop(element);
Storyboard storyboard = new Storyboard();
DoubleAnimation animationX = CreateDoubleAnimation(element,
fromX, toX, new PropertyPath(Canvas.LeftProperty));
DoubleAnimation animationY = CreateDoubleAnimation(element,
fromY, toY, new PropertyPath(Canvas.TopProperty));
storyboard.Children.Add(animationX);
storyboard.Children.Add(animationY);
storyboard.Begin();
}
public static DoubleAnimation CreateDoubleAnimation(UIElement element,
double from, double to, PropertyPath propertyToAnimate)
{
DoubleAnimation animation = new DoubleAnimation();
Storyboard.SetTarget(animation, element);
Storyboard.SetTargetProperty(animation, propertyToAnimate);
animation.From = from;
animation.To = to;
animation.Duration = TimeSpan.FromSeconds(3);
return animation;
}
public void DrawBox()
{
BoxControl newBox = new BoxControl();
playArea.Children.Add(newBox);
Canvas.SetTop(newBox, random.Next(0, 419));
Canvas.SetLeft(newBox, random.Next(0, 792));
}
什麼框架,這是什麼?統一?更新標題或標籤會吸引更多有見識的人。 – akatakritos
它是.NET,更新它 – Tripper
你需要知道你的蜜蜂和你的盒子的位置(使用Canvas.GetLeft,Canvas.GetTop方法)及其尺寸。然後,檢查蜜蜂是否通過盒子,這是一個簡單的數學。你需要爲所有盒子做這件事(你可以像這樣playArea.children.OfType())獲得它們的集合。但除非您提供與您一起工作的實際代碼,否則很難提供幫助 –
Omilis