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

  • SEARCH
  • Home
  • 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 7726971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:20:38+00:00 2026-06-01T05:20:38+00:00

I’m making a Space Invaders game in C#, using Bitmap to store images for

  • 0

I’m making a Space Invaders game in C#, using Bitmap to store images for the invaders, bombs, etc.
What puzzles me:
I have an abstract class GameObject representing the simple elements in the game:

protected Bitmap image;
protected Rectangle bounds;
protected Rectangle movementBounds;

public GameObject(ref Bitmap image, Point position, Rectangle movementBounds)
{
    this.image = image;
    this.bounds = new Rectangle(position, new Size(image.Width, image.Height));
    this.movementBounds = movementBounds;
}

Than a ShieldSegment class representing a single square of a Shield, which has four images for various stages of damage:

private int timesHit = 0;
private IList<Bitmap> alternateImages = new List<Bitmap>();

public ShieldSegment(ref List<Bitmap> images, Point position, Rectangle movementBounds)
    : base(ref images.First(), position, movementBounds)
{
    alternateImages = images;
}

And a Shield class which represents the whole shield as a list of segments:

private IList<ShieldSegment> segments = new List<ShieldSegment>();

//fill, upper left, upper right, lower left, lower right
public Shield(ref List<List<Bitmap>> images, Point position, Size imageSize)
{
    //upper row
    Point startPosition = position;
    segments.Add(new ShieldSegment(ref images.ElementAt(1), startPosition,new Rectangle(startPosition, imageSize)));
    startPosition.X += imageSize.Width;
    segments.Add(new ShieldSegment(ref images.ElementAt(0), startPosition,new Rectangle(startPosition, imageSize)));
    startPosition.X += imageSize.Width;
    segments.Add(new ShieldSegment(ref images.ElementAt(0), startPosition, new Rectangle(startPosition, imageSize)));
    startPosition.X += imageSize.Width;
    segments.Add(new ShieldSegment(ref images.ElementAt(2), startPosition, new Rectangle(startPosition, imageSize)));
    //middle row
    startPosition = position;
    startPosition.Y += imageSize.Height;
...

I need to pass the list elements as references, since (and sorry if I’m wrong) it would be wasteful to store the images anew for each segment and shield. It works fine when passing a single reference to Bitmap, but here I get a ref or out argument must be an assignable variable.
Is there any way to do it?

  • 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-06-01T05:20:39+00:00Added an answer on June 1, 2026 at 5:20 am

    I need to pass the list elements as references

    You’re not really being clear here. The list reference is just passed, by value by default but by reference if necessary. When you access the list, you’ll get a reference. However, this code:

    public ShieldSegment(ref List<Bitmap> images, Point position, 
         Rectangle movementBounds)
        : base(ref images.First(), position, movementBounds)
    {
        alternateImages = images;
    }
    

    suggests you may not understand how parameter passing works in .NET to start with:

    • You’re not changing the value of the images parameter to start with, so you don’t need to use ref
    • It makes no sense to use ref with an argument which is the result of a method invocation… what do you expect it to do?

    I suggest you read my article on it, as well as my article on reference types and value types, which should clarify things.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.