Xna と C# を使用しています。
リストに特定のオブジェクトを入れて、さまざまなことをしようとしています。
現時点で書いた方法では、リスト内のすべてのテクスチャが選択され、それらのすべてが同じことを行います。特定のテクスチャを選択しようとすると、それらのすべてが同じことを行います。
if (planet.Load("planet0")) { if (planet.Bounds.Contains((int)tl.Position.X, (int)tl.Position.Y)) { changeScreenDelegate(ScreenState.Menu); } }
基本的に、各選択を別の画面に移動させようとしています。
残りのクラスは次のとおりです。
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();
}
}
}