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 8331191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:20:29+00:00 2026-06-09T02:20:29+00:00

Im using Xna and C#. Im trying to have specific objects in my list

  • 0

Im using Xna and C#.

Im trying to have specific objects in my list doing different things.

The way ive written it out at the moment it selects all the textures in my list and all of them do the same thing, if i try and select a certain texture all of them still do the same thing:

if (planet.Load("planet0")) { if (planet.Bounds.Contains((int)tl.Position.X, (int)tl.Position.Y)) { changeScreenDelegate(ScreenState.Menu); } }

Im basically trying to make each selection go to a different screen.

Heres the rest of my class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Input.Touch;
using Microsoft.Xna.Framework.Media;


namespace PlanetDrill2
{
    class StarSystemUrsa : Screen
    {
        Texture2D starSystemTexture;

    List<Planet> planets;

    Texture2D star;
    Vector2 position;
    Texture2D previousButton;


    public StarSystemUrsa(Game game, SpriteBatch spriteBatch, ChangeScreen changeScreen)
        : base(game, batch, changeScreen)
    {

        position = new Vector2((480 - 295) / 2, (800 - 295) / 2);



        planets = new List<Planet>();

        Planet planet = new Planet(content, spriteBatch);
        planet.Load("planet0");
        planet.velocity = 0.04f;
        planet.radius = 80;
        planet.angle = MathHelper.ToRadians(90);
        planets.Add(planet);

        planet = new Planet(content, spriteBatch);
        planet.Load("planet4");
        planet.velocity = 0.02f;
        planet.radius = 135;
        planet.angle = MathHelper.ToRadians(120);
        planets.Add(planet);

        planet = new Planet(content, spriteBatch);
        planet.Load("planet2");
        planet.velocity = 0.009f;
        planet.radius = 180;
        planet.angle = MathHelper.ToRadians(160);
        planets.Add(planet);

    }




    protected override void SetupInputs()
    {

        base.SetupInputs();
    }


    public override void Activate()
    {
        base.Activate();
    }

    protected override void LoadScreenContent(ContentManager content)
    {
        starSystemTexture = content.Load<Texture2D>("levelSelectMenu");
        star = content.Load<Texture2D>("ursaeMajorisStar");
        previousButton = content.Load<Texture2D>("previousButton2");



        base.LoadScreenContent(content);
    }

    protected override void UpdateScreen(GameTime gameTime, DisplayOrientation screenOrientation)
    {

        TouchCollection touchCollection = TouchPanel.GetState();

    foreach(TouchLocation tl in touchCollection)
        {
            if(tl.State == TouchLocationState.Pressed) // Moved? Is that right?
            {  
                foreach(Planet planet in planets)
                {

                    // Alternately: if(GetPlanetRectangle(planet).Contains(...))
                    if(planet.Bounds.Contains((int)tl.Position.X, (int)tl.Position.Y))
                    {
                        changeScreenDelegate(ScreenState.Menu);
                    }

                }

            }

            TouchPanel.EnabledGestures = GestureType.DoubleTap | GestureType.VerticalDrag;

            while (TouchPanel.IsGestureAvailable)
            {


                GestureSample gesture = TouchPanel.ReadGesture();

                switch (gesture.GestureType)
                {
                    case GestureType.DoubleTap:
                        changeScreenDelegate(ScreenState.launchScreen);
                        break;
                    case GestureType.VerticalDrag:

                        break;
                    default:
                        break;
                }
            }
        }







        foreach (Planet planet in planets)
        {
            planet.angle += planet.velocity;
            float orbitx = (float)(Math.Cos(planet.angle) * planet.radius);
            float orbity = (float)(Math.Sin(planet.angle) * planet.radius);

            float x = (game.GraphicsDevice.Viewport.Width - planet.image.Width) / 2 + orbitx;
            float y = (game.GraphicsDevice.Viewport.Height - planet.image.Height) / 2 + orbity;

            planet.position = new Vector2(x, y);


        }



        base.UpdateScreen(gameTime, screenOrientation);


    }

    protected override void DrawScreen(SpriteBatch batch, DisplayOrientation screenOrientation)
    {


        batch.Draw(starSystemTexture, Vector2.Zero, Color.White);

        foreach (Planet planet in planets)
        {
            planet.Draw();
        }

        batch.Draw(star,position, Color.White);
        batch.Draw(previousButton, new Vector2(240, 750), Color.White);
        base.DrawScreen(batch, screenOrientation);
    }





      protected override void SaveScreenState()
        {
            base.SaveScreenState();
        }
    }
}
  • 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-09T02:20:31+00:00Added an answer on June 9, 2026 at 2:20 am

    Give your planet class another property called ID, then give each planet a different ID when initialising them. Then in your foreach planet in planets loop, you can say

    if(planet.ID == 0)
    { if (planet.Bounds.Contains((int)tl.Position.X, (int)tl.Position.Y)) { changeScreenDelegate(ScreenState.Menu); } }

    Do this for each possible ID number, and change the screenstate to whatever screen state you want it to switch to.

    Plus you could enumerate the ID numbers to make it clear as to which planet is being referenced.

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

Sidebar

Related Questions

I am trying to draw a rectangle shape in XNA using spritebatch. I have
I'm trying to draw grid using the XNA framework, this grid should have a
I'm trying to develop an app using XNA and for state management I'm using
I am trying to make my first app using XNA, and I am having
Creating a simple RPG game, first time using XNA. Trying to get my character
I am currently developing a C# .net xna game engine. I have been trying
I'm trying to host an XNA game inside a WPF window using the Windows
I am using XNA 4.0 and trying to take a Vector3 and turn it
I'm trying to create a 2D array in XNA which I'll be using as
I'm trying to draw on the screen pixel-by-pixel using XNA, but am having problems

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.