所以我正在制作太空入侵者游戏。我想要从different/random locations on the entire 0 coordinate of X
产生流星。我应该怎么办?我见过使用Lists
和Random()
s的人,但我需要我的meteorGenerator
类的代码。然后我将其称为Game1中的方法C#XNA - 随机在顶部X轴上绘制纹理
当流星被绘制时,它们应该落在屏幕的底部并消失。 我在这里看到了SO答案,它实现我的课:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Storage;
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 Microsoft.Xna.Framework.Net;
namespace SpaceInvaders
{
class meteorGenerator
{
public static Vector2 m_Pos;
public Vector2 m_Position
{
get { return m_Pos; }
set { m_Pos = value; }
}
Texture2D m_Texture { get; set; }
Texture2D m_MeteorsTex;
public meteorGenerator(Texture2D m_Tex, Vector2 m_Pos)
{
m_Position = m_Pos;
m_Texture = m_Tex;
}
List<meteorGenerator> m_MeteorsList = new List<meteorGenerator>();
static readonly Random rnd = new Random();
public void LoadContent(ContentManager Content)
{
m_MeteorsTex = Content.Load<Texture2D>(".\\gameGraphics\\gameSprites\\thePlan\\meteorSpawn");
}
public void Update(GameTime gameTime)
{
if (m_MeteorsList.Count() < 4)
{
m_MeteorsList.Add(new meteorGenerator(m_MeteorsTex, new Vector2(rnd.Next(30, 610), rnd.Next(30, 450))));
}
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (meteorGenerator m_Meteor in m_MeteorsList)
{
spriteBatch.Draw(m_Meteor.m_Texture, m_Meteor.m_Position, Color.White);
}
}
}
}
但是,当我尝试实例中的Game1类的构造函数,我得到一个错误:
meteorGenerator m_MeteorGenerator;
protected override void Initialize()
{
// TODO: Add your initialization logic here.
m_MeteorGenerator = new meteorGenerator(meteorGenerator.m_Tex, meteorGenerator.m_Pos);
}
Error 1 'SpaceInvaders.meteorGenerator' does not contain a definition for 'm_Tex'
这是SO过于宽泛。如果您有关于该技术的*特定*问题或者您拥有的某些代码;请缩小这个问题的范围。 – BradleyDotNET 2014-11-14 18:42:51
我需要的是一种方法/指南,以遵循并贯彻到我的游戏中。我的meteorGenerator类中没有任何代码,这就是为什么我问。 – PowerUser 2014-11-14 18:49:13
好的;但你说你已经看过使用'List'和'Random'的代码。这确实是正确的做法。什么让你感到困惑? *这个问题是你应该在这里问的。 – BradleyDotNET 2014-11-14 18:50:49