void StarChangedHandler(object sender, StarChangedEventArgs e) { if (e.Removed) { StarControl starControl = _stars[e.StarThatChanged]; _stars.Remove(e.StarThatChanged); _fadedStars.Add(starControl); starControl.FadeOut(); } else { StarControl newStar; if (_stars.ContainsKey(e.StarThatChanged)) { newStar = _stars[e.StarThatChanged]; } else { newStar = new StarControl(); _stars[e.StarThatChanged] = newStar; newStar.FadeIn(); BeeStarHelper.SendToBack(newStar); _sprites.Add(newStar); } BeeStarHelper.SetCanvasLocation( newStar, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y); } }
void StarChangedHandler(object sender, StarChangedEventArgs e) { StarControl starControl = null; if (_stars.ContainsKey(e.StarThatChanged)) { starControl = _stars[e.StarThatChanged]; } if (e.Removed && starControl != null) { _fadedStars.Add(starControl); _stars.Remove(e.StarThatChanged); starControl.FadeOut(); return; } else if (starControl == null) { starControl = new StarControl(); if (_stars.ContainsKey(e.StarThatChanged)) { _stars[e.StarThatChanged] = starControl; } else { _stars.Add(e.StarThatChanged, starControl); } _sprites.Add(starControl); starControl.FadeIn(); BeeStarHelper.SendToBack(starControl); } BeeStarHelper.SetCanvasLocation(starControl, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y); }
private void StarChangedHandler(object sender, StarChangedEventArgs e) { if (_stars.ContainsKey(e.StarThatChanged)) { if (e.Removed) { _fadedStars.Add(_stars[e.StarThatChanged]); _stars[e.StarThatChanged].FadeOut(); _stars.Remove(e.StarThatChanged); } else { BeeStarHelper.SetCanvasLocation(_stars[e.StarThatChanged], e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y); } } else { StarControl newStarControl = new StarControl(); newStarControl.FadeIn(); _stars.Add(e.StarThatChanged, newStarControl); _sprites.Add(newStarControl); BeeStarHelper.SendToBack(newStarControl); BeeStarHelper.SetCanvasLocation(newStarControl, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y); } }
void StarChangedHandler(object sender, StarChangedEventArgs e) { // The _stars dictionary works just like the _bees one, except that it maps Star objects // to their corresponding StarControl controls. The EventArgs contains references to // the Star object (which has a Location property) and a Boolean to tell you if the star // was removed. If it is then we want it to fade out, so remove it from _stars, add it // to _fadedStars, and call its FadeOut() method (it'll be removed from _sprites the next // time the Update() method is called, which is why we set the timer’s tick interval to // be greater than the StarControl's fade out animation). if (e.Removed) { StarControl starControl = _stars[e.StarThatChanged]; _stars.Remove(e.StarThatChanged); _fadedStars.Add(starControl); starControl.FadeOut(); } // // If the star is not being removed, then check to see if _stars contains it - if so, get // the StarControl reference; if not, you'll need to create a new StarControl, fade it in, // add it to _sprites, and send it to back so the bees can fly in front of it. Then set // the canvas location for the StarControl. else { StarControl starControl; if (!_stars.ContainsKey(e.StarThatChanged)) { starControl = new StarControl(); _stars.Add(e.StarThatChanged, starControl); starControl.FadeIn(); starControl.Rotate(e.StarThatChanged.Rotating); _sprites.Add(starControl); BeeStarHelper.SendToBack(starControl); } else { starControl = _stars[e.StarThatChanged]; } BeeStarHelper.SetCanvasLocation(starControl, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y); } }