Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 777083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:32:56+00:00 2026-05-14T19:32:56+00:00

I am starting to learn silverlight and to practice I am doing a simple

  • 0

I am starting to learn silverlight and to practice I am doing a simple space invaders type videogame.

My issue is I am creating custom controls (bullets) programmatically like so:

if(shooting)
{
    if(currBulletRate == bulletRate)
    {
        Bullet aBullet = new Bullet();

        aBullet.X = mouse.X - 5;
        aBullet.Y = mouse.Y - Ship.Height;
        aBullet.Width = 10;
        aBullet.Height = 40;
        aBullet.Tag = "Bullet";

        LayoutRoot.Children.Add(aBullet);

        currBulletRate = 0;
    }
    else
        currBulletRate++;
}

However I am having trouble removing them once they go off bounds (leave the LayoutRoot).

I tried looping throught the LayoutRoot.Children and removing but I can’t seem to get it right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:32:56+00:00Added an answer on May 14, 2026 at 7:32 pm
    UIElement[] tmp = new UIElement[LayoutRoot.Children.Count];             
    LayoutRoot.Children.CopyTo(tmp, 0);  
    
    foreach (UIElement aElement in tmp)
    {
        Shape aShape = aElement as Shape; 
    
        if (aShape != null && aShape.Tag != null)
        {
    
            if (aShape.Tag.ToString().Contains("Bullet"))
            {
                if (Canvas.GetTop(aShape) + aShape.ActualHeight < 0) // This checks if it leaves the top
                {
                    LayoutRoot.Children.Remove(aElement);
                }
                else if(Canvas.GetTop(aShape) > Canvas.ActualHeight) // This condition checks if it leaves the bottom
                {
                    LayoutRoot.Children.Remove(aElement);
                }
            }
        }
    }
    

    The code you pasted was only checking if the bullet left the top of the canvas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting to learn Excel Programming and have been doing the development in Excel
I am starting to learn Silverlight game programming, and was wondering if anyone knows
At the moment I am starting to learn Silverlight . I have expriences in
Whilst starting to learn lisp, I've come across the term tail-recursive . What does
Im starting to learn RoR and i want to make my personal blog in
I am just starting to learn javascript, so I don't have the skills to
I'm starting to learn Python and I've come across generator functions, those that have
I'm starting to learn about using Memcached with PHP and I was wondering; is
I am starting to learn the Clojure programming language. Are there any recommendations for
im just starting to learn flex and im trying to understand how Flex does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.