Space Invaders

Help requested.

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 8385 Views - Last Post: 10 December 2010 - 12:38 PM

#1 SimonSays  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 10

Space Invaders

Posted 06 December 2010 - 11:45 PM

So I'm working on a creating a version of space invaders (using XNA), and I'm having some issues. The biggest issue currently is that I cannot get my array of aliens to display on the screen. I was wondering if anyone could point out what I'm doing wrong.
I apologize in advance for my disjointed code, I just been trying different things in my futile attempts at getting this thing to work. I will post some code here, but I will also include all of my source code if that makes it easier.
Main Code
 using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Windows.Forms;          // needed so that we can add normal buttons, etc.

// This project doesn't do anything useful, but it illustrates the functions you'll need
// to implement your game.
namespace FinalProject
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics; // this represents the graphics device 
        SpriteBatch spriteBatch;        // all drawing takes place via this object
        Texture2D backGroundTexture;    // will point to a picture to use for background
        Texture2D missileTexture;       // will point to a picture to use for the missile
        Texture2D alien;
        Vector2 missilePos;             // position of the missle
        bool isMissleInFlight;          // is the missle active?
        int numMissilesFired = 0;       // how many times has missle been fired?
        //List<Bombs> bombs;
        Rectangle viewPort;             // tells us the size of the drawable area in the window
        Ship myShip;                    // reference to the ship controlled by the user
        AlienGroup Aliens;
        KeyboardState oldState;         // keeps previous state of keys pressed, so we can
        // detect when a change in state occurs

        // NOTE: we really ought to have a class to keep up with the missle information; 
        // this is left as an exercise for the reader

        const int PANEL_WIDTH = 100;    // width of a panel we'll add for adding buttons, etc.
        // Controls we'll add to form, just for sake of example.
        Panel pnl = new Panel();
        Label lblFireCount = new Label();

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            this.IsMouseVisible = true;
            InitializeControlPanel();
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {

            viewPort = GraphicsDevice.Viewport.Bounds;
            oldState = Keyboard.GetState();
            missilePos = Vector2.Zero;
            isMissleInFlight = false;
            myShip = new Ship(new Vector2((viewPort.Width - PANEL_WIDTH) / 2,
                                          viewPort.Bottom-39));
            Aliens = new FinalProject.AlienGroup(this);
            base.Initialize();
        }

        // Since this is an xna project; we can't easily drag/drop controls onto the
        // main Form like we have been doing in the past. But, we can do it programatically,
        // as illustrated below.
        private void InitializeControlPanel()
        {
            // get game window as a win form Form class            
            Form frm = Control.FromHandle(this.window.Handle) as Form;
            // setup the panel control. Note: this panel will overlay the viewport
            // for 100 pixels; we can adjust for this in our algorithms
            this.pnl.Dock = DockStyle.Right;
            this.pnl.Width = PANEL_WIDTH;
            // createa a button and add it to the panel           
            Button btn = new Button();
            btn.Location = new System.Drawing.Point(10, 10);
            btn.Text = "Testing";
            btn.Click += new EventHandler(btn_Click);
            // add the button to the panel and add the panel to the game window form
            this.pnl.Controls.Add(btn);
            frm.Controls.Add(this.pnl);
            // setup the label control and add it to the panel control            
            this.lblFireCount.Text = "";
            this.lblFireCount.Location = new System.Drawing.Point(10, btn.Top + btn.Height + 10);
            this.lblFireCount.AutoSize = true;
            this.pnl.Controls.Add(this.lblFireCount);
        }

        // sample button event handler
        void btn_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You clicked a button!");
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);
            // load textures into memory once during LoadContent()
            backGroundTexture = Content.Load<Texture2D>("stars");
            Ship.Texture = Content.Load<Texture2D>("ship-small");
            AlienGroup.Sprites = Content.Load<Texture2D>("spaceinvader");
            missileTexture = Content.Load<Texture2D>("missile");
            //Aliens = new FinalProject.AlienGroup(this, Content.Load<Texture2D>("spaceinvader"));

        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
            alien.Dispose();
            //myShip.Dispose();
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// This gets called ~60 times per second
        protected override void Update(GameTime gameTime)
        {
            moveShip();     // if a arrow key is held down, move the ship
            fireMissle();   // create a missle if the space bar was hit
            moveMissle();  // if the missle is alive, update its position

            base.Update(gameTime);
        }

        // Check to see if an arrow key is currently pressed. Take appropriate
        // action to move ship (note, note boundary checking is done to ensure
        // ship doesn't move off-screen.
        private void moveShip()
        {
            KeyboardState state = Keyboard.GetState();

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                myShip.move(Ship.Direction.Left);
            }
            else if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                myShip.move(Ship.Direction.Right);
            }
            else if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                myShip.move(Ship.Direction.Up);
            }
            else if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                myShip.move(Ship.Direction.Down);
            }

        }

        // Check to see if the space key is down. If so, set flag and position so
        // that the Draw will Draw the missle. Note: this is a little different than
        // the ship, because we only want to fire the missle on a button click
        private void fireMissle()
        {
            KeyboardState newState = Keyboard.GetState();

            // Is the SPACE key down?
            if (newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
            {

                // If it was not down the previous time we checked, then this is a 
                // new key press. If the key was down in the old state, they're just
                // holding it down, so we ignore this state.
                if (!oldState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
                 {
                    // can only have one missle at a time
                    if (!isMissleInFlight)
                    {
                        isMissleInFlight = true;
                        missilePos = myShip.GunPosition;
                        numMissilesFired++;
                        lblFireCount.Text = numMissilesFired.ToString();
                    }
                }

            }


            // Update saved state.
            oldState = newState;
        }

        // If the missle is alive, move it up a few clicks until it goes off screen
        public void moveMissle()
        {
            if (isMissleInFlight)
            {
                missilePos.Y -= 8;
                if (missilePos.Y <= 0)
                {
                    isMissleInFlight = false;
                    missilePos = Vector2.Zero;
                }
            }

        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// This is called in the main loop after Update to render the current state of the game 
        /// on the screen. 
        protected override void Draw(GameTime gameTime)
        {

            // spriteBatch is an object that allows us to draw everything
            // on screen (it contains the Draw functions).
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

            // draw the background
            spriteBatch.Draw(backGroundTexture, viewPort, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
            // draw the ship over background

            myShip.Draw(spriteBatch);
            // draw the missle
            if (isMissleInFlight)
                spriteBatch.Draw(missileTexture, missilePos, Color.White);

            // This tells the graphics pipeline that we're done drawing this frame,
            // and asks it to push the pixels to the graphics frame buffer.
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}


The Alien class.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Windows.Forms;          // needed so that we can add normal buttons, etc.


namespace FinalProject
{
    public class Aliens : MovingObjects
    {
        public Aliens(Game game, Texture2D inSprite, Vector2 inPosition)
            : base(game)
        {
            Sprite = inSprite;
            Position = inPosition;
            Width = 22;
            Height = 15;
            Velocity = 2;
            outRect = new Rectangle(0, 0, Width, Height);
        }
    }
} 


The AlienGroup class
 using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;

namespace FinalProject
{
    class AlienGroup : MovingObjects
    {
        public Aliens[] GroupList;
        public int n;
        public int Direction;
        public static Texture2D Sprites;

        public AlienGroup(Game game)//, Texture2D Sprites)
            : base(game)
        {
            n = 30;
            int NoInLine = 8;
            Direction = 6;
            GroupList = new Aliens[n];
            for (int i = 0; i < n; i++)
            {
                GroupList[i] = new Aliens(game, Sprites,
                    new Vector2((float)Math.Round((double)(i % NoInLine * 45)), (float)Math.Round((double)(i / NoInLine * 30))));
            }
        }

        public bool OutOfScreen(int Direction)
        {
            for (int i = 0; i < n; i++)
            {
                if (GroupList[i] != null && GroupList[i].OutOfScreen(Direction))
                {
                    return true;
                }
            }
            return false;
        }

        public void RemoveFly(int pos)
        {
            GroupList[pos].Dispose();
            GroupList[pos] = null;
        }

        public void Move()
        {
            if (OutOfScreen(Direction))
            {
                if (Direction == 4) Direction = 6;
                else Direction = 4;
            }
            for (int i = 0; i < n; i++)
            {
                if (GroupList[i] != null)
                {
                    GroupList[i].Move(Direction);
                }
            }
        }

        public override void Update(GameTime gameTime)
        {
            Move();
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            for (int i = 0; i < n; i++)
            {
                if (GroupList[i] != null)
                {
                    GroupList[i].Draw(gameTime);
                }
            }
        }
    }
}



Thanks!

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Space Invaders

#2 Guest_Zunera*


Reputation:

Re: Space Invaders

Posted 07 December 2010 - 06:33 AM

Hi,

one of the problems of not drawing any aliens is the missing "Sprite" for you aliens. You are creating the aliens with the empty "Sprites". Later on (LoadContent-method) you set the static Aliens.Sprites to a new value which doesn't have no effect on the Aliens-object in you AlienGroup class at all. You could define a property for the "Sprites" in the AlienGroup class (and don't define it static!) as follows:

...
using System.Linq;
public class AlienGroup : MovingObjects
{
  public Aliens[] GroupList;
  public int n;
  public int Direction;

  private Texture2D _sprites;
  public Texture2D Sprites
  {
    set
    {
      _sprites = value;
      foreach(Aliens alien in GroupList.Where(elem => elem != null)) alien.Sprite = value;
    }
    get { return _sprites; }
  }

  ...
}



Hf!
Was This Post Helpful? 1

#3 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Space Invaders

Posted 07 December 2010 - 06:45 AM

It might be a good idea for you to check out the Alien Aggressors tutorial that's floating around on the web. I don't have a link to it, but I'm sure Google can help you with that.
Was This Post Helpful? 1
  • +
  • -

#4 SimonSays  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 10

Re: Space Invaders

Posted 07 December 2010 - 05:06 PM

View PostZunera, on 07 December 2010 - 05:33 AM, said:

Hi,

one of the problems of not drawing any aliens is the missing "Sprite" for you aliens. You are creating the aliens with the empty "Sprites". Later on (LoadContent-method) you set the static Aliens.Sprites to a new value which doesn't have no effect on the Aliens-object in you AlienGroup class at all. You could define a property for the "Sprites" in the AlienGroup class (and don't define it static!) as follows:

...
using System.Linq;
public class AlienGroup : MovingObjects
{
  public Aliens[] GroupList;
  public int n;
  public int Direction;

  private Texture2D _sprites;
  public Texture2D Sprites
  {
    set
    {
      _sprites = value;
      foreach(Aliens alien in GroupList.Where(elem => elem != null)) alien.Sprite = value;
    }
    get { return _sprites; }
  }

  ...
}



Hf!


Thank you for your response!
But when I try to use the code you recommended I get the following syntax error: Error 1 'System.Array' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

What I am missing?
Was This Post Helpful? 0
  • +
  • -

#5 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Space Invaders

Posted 07 December 2010 - 05:45 PM

Quote

Thank you for your response!
But when I try to use the code you recommended I get the following syntax error: Error 1 'System.Array' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

What I am missing?


Make sure you've added the System.Linq namespace:

using namespace System.Linq;

Was This Post Helpful? 2
  • +
  • -

#6 SimonSays  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 10

Re: Space Invaders

Posted 07 December 2010 - 06:12 PM

Quote

Make sure you've added the System.Linq namespace:

using namespace System.Linq;

Yeah that got rid of the syntax error. Thanks.
Unfortunately however, the aliens still will not load.
Here is my updated code.
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);
            // load textures into memory once during LoadContent()
            backGroundTexture = Content.Load<Texture2D>("stars");
            Ship.Texture = Content.Load<Texture2D>("ship-small");
            missileTexture = Content.Load<Texture2D>("missile");
            Aliens = new FinalProject.AlienGroup(this);

        } 



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;

namespace FinalProject
{
    class AlienGroup : MovingObjects
    {
        public Aliens[] GroupList;
        public int n;
        public int Direction;
        private Texture2D _sprites;
        public Texture2D Sprites
        {
            set
            {
                _sprites = value;
                foreach (Aliens alien in GroupList.Where(elem => elem != null)) alien.Sprite = value;
            }
            get { return _sprites; }
        }

        public AlienGroup(Game game)
            : base(game)
        {
            n = 30;
            int NoInLine = 8;
            Direction = 6;
            GroupList = new Aliens[n];
            for (int i = 0; i < n; i++)
            {
                GroupList[i] = new Aliens(game, Sprites,
                    new Vector2((float)Math.Round((double)(i % NoInLine * 45)), (float)Math.Round((double)(i / NoInLine * 30))));
            }
        }

        public bool OutOfScreen(int Direction)
        {
            for (int i = 0; i < n; i++)
            {
                if (GroupList[i] != null && GroupList[i].OutOfScreen(Direction))
                {
                    return true;
                }
            }
            return false;
        }

        public void RemoveFly(int pos)
        {
            GroupList[pos].Dispose();
            GroupList[pos] = null;
        }

        public void Move()
        {
            if (OutOfScreen(Direction))
            {
                if (Direction == 4) Direction = 6;
                else Direction = 4;
            }
            for (int i = 0; i < n; i++)
            {
                if (GroupList[i] != null)
                {
                    GroupList[i].Move(Direction);
                }
            }
        }

        public override void Update(GameTime gameTime)
        {
            Move();
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            for (int i = 0; i < n; i++)
            {
                if (GroupList[i] != null)
                {
                    GroupList[i].Draw(gameTime);
                }
            }
        }
    }
}


Was This Post Helpful? 0
  • +
  • -

#7 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Space Invaders

Posted 07 December 2010 - 07:17 PM

I don't see where you're drawing the the ships. If MovingObjects derives from DrawableGameComponent, it may be as simple as adding the AlienGroup instance to the game's components:

protected override void Initialize()
{
    // ...
    Aliens = new AlienGroup(this);
    Components.Add(Aliens);
}


If not, then call the draw code yourself:

protected override void Draw(GameTime gameTime)
{
    // ...
    Aliens.Draw(gameTime);
}

Was This Post Helpful? 0
  • +
  • -

#8 SimonSays  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 10

Re: Space Invaders

Posted 07 December 2010 - 08:36 PM

View PostlesPaul456, on 07 December 2010 - 06:17 PM, said:

I don't see where you're drawing the the ships. If MovingObjects derives from DrawableGameComponent, it may be as simple as adding the AlienGroup instance to the game's components:

protected override void Initialize()
{
    // ...
    Aliens = new AlienGroup(this);
    Components.Add(Aliens);
}



If not, then call the draw code yourself:
protected override void Draw(GameTime gameTime)
{
    // ...
    Aliens.Draw(gameTime);
}

Using the first method resulted in the program crashing upon starting.

In order for the second method to work, it wants me to create an object to call Draw on, so I'm not sure if that is what I should be doing?

I appreciate your help thus far.
Was This Post Helpful? 0
  • +
  • -

#9 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Space Invaders

Posted 07 December 2010 - 08:57 PM

As lesPaul456 pointed out, calling the draw method of the AlienGroup class is the only way to be able to actually use the Draw method of that class. Just having a Draw method doesn't mean it's being used. Create an instance of the AlienGroup class in the Game1 class, then use the name of that instance to call the Draw method of the AlienGroup class. Example:
// In the Game1 class at the top where all the variable declarations reside
AlienGroup aliens;

...

// Then inside the Draw method of the Game1 class...
aliens.Draw(gameTime);



I generally use classes as just a basic framework for what an object should be, and leave all the logic pertaining to the instances of that class for the Game1 class to deal with. Creating a class is effectively just creating another data type to be used in your code. So you can think of the class you've created as just another variable. Therefore you need to declare an instance of that variable, and use it in some way in your Game1 class.

This post has been edited by Kilorn: 07 December 2010 - 08:58 PM

Was This Post Helpful? 1
  • +
  • -

#10 SimonSays  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 10

Re: Space Invaders

Posted 07 December 2010 - 10:06 PM

Thank you for the clarification, but my program still crashes as soon as I run it after I made the changes. So I'm not sure if the issue lies in the Game1 class or the AlienGroup class.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#11 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Space Invaders

Posted 08 December 2010 - 08:24 AM

I took a look at your code, and as I expected, MovingObjects derives from GameObject, which derives from DrawableGameComponent. :)

So, you could just add it to the game's components. Calling Draw yourself may end up being a little easier, though.

The game crashes with an ArgumentNullException. This exception is thrown because Sprite is null. A quick and simple fix is to modify the AlienGroup constructor:
public AlienGroup(Game game) : base(game)
{
    // ...

    for (int i = 0; i < n; i++)
    {
        Sprites = game.Content.Load<Texture2D>("spaceinvaders");
       // ...
    } 

    // ...
}



This is not a best practice, and should be a temporary fix only. This will get your game to build and run without any exceptions; I'll leave the rest to you.
Was This Post Helpful? 2
  • +
  • -

#12 SimonSays  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 10

Re: Space Invaders

Posted 09 December 2010 - 10:50 AM

So I've changed my approach somewhat and started using the Alien Aggressors tutorial (thanks Kilorn) but I've come across an issue that has been caused by XNA 4.0.


Error 1 The name 'TextureUsage' does not exist in the current context.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SpaceInvaders
{
    class StarryBackground: Texture2D
    {
        public StarryBackground(GraphicsDevice graphics, int width, int height, int numberOfStars)
            : base(graphics, width, height, 0, TextureUsage.None, SurfaceFormat.Color)
        {
                if (numberOfStars >= width * height || numberOfStars < 0)
                throw new Exception("numberOfStars must be in the range of [0, width * height - 1]");
                Random rand = new Random();
                Color[] pixels = new Color[width * height];
                int starsAdded = 0;
                while (starsAdded < numberOfStars)
                {
	                int index = rand.Next(pixels.Length);
	                if (pixels[index] == Color.Transparent)
	                {
		                float value = (float)rand.NextDouble() + .5f;
		                pixels[index] = new Color(new Vector4(value));
		                starsAdded++;
	                }
                }
        SetData(pixels);
        }        

    }
}


I read through some of the documentation about the Texture2D class and I know that it changed significantly in XNA 4.0 but I do not know what I should do to correct this error.
Thanks to everyone for your help so far.
Was This Post Helpful? 0
  • +
  • -

#13 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Space Invaders

Posted 09 December 2010 - 11:19 AM

It appears that TextureUsage was removed from the Texture2D class in 4.0. Try the following:
// Change
: base(graphics, width, height, 0, TextureUsage.None, SurfaceFormat.Color)

// To
: base(graphics, width, height)



and see if that helps at all. As I've said in other threads, I still haven't made the migration to 4.0, so some of the changes are still new to me.

This post has been edited by Kilorn: 09 December 2010 - 11:19 AM

Was This Post Helpful? 1
  • +
  • -

#14 SimonSays  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 10

Re: Space Invaders

Posted 09 December 2010 - 06:46 PM

Well that did the trick, but the frustration doesn't go away!
I have 2 errors regarding "Inconsistent Accessibility".

Error 1 Inconsistent accessibility: base class 'SpaceInvaders.Ship' is less accessible than class 'SpaceInvaders.AlienShip'
Error 2 Inconsistent accessibility: base class 'SpaceInvaders.Ship' is less accessible than class 'SpaceInvaders.PlayerShip'

My understanding of this error is that it is caused by an inherited class trying to access private data from the base class. But there is no private data in the "Ship" class or its base class.
So what should I be looking at instead?
Thanks again.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#15 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Space Invaders

Posted 10 December 2010 - 06:52 AM

The issue here is that the AlienShip class, and the PlayerShip class are both public, but the class they inherit from, the Ship class, is not public. Make the Ship class public and it should take care of the issue. If any child classes are public, then the parents that they inherit from need to be public as well.

This post has been edited by Kilorn: 10 December 2010 - 06:54 AM

Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2