'particleEngine'是针对向量绘制的

时间:2012-07-27 16:46:46

标签: c# windows-phone-7 vector xna

我正在使用XNA和C#。

我从particleEmitter调用向量变量时遇到问题。如果静止或不移动,我可以很好地绘制粒子。当我有一个设置为(x,y)固定位置的矢量变量时,它就可以并在屏幕上绘制。但是如果我有一个已设置为在x轴或y轴上移动的矢量变量,它根本不会绘制。

声明变量:

Vector2 shipPos;
float shipMovement;
ParticleEngine particleEngine;

一种加载关于向量应该发生什么的方法以及它应该表现的方式:

public void loadEmitter(GameTime gameTime)
{
    shipMovement = 2f;
    shipPos.Y -= shipMovement;          
    particleEngine.EmitterLocation = new Vector2(shipPos.X,shipPos.Y);
}

我试图让particleEngine追踪船只的移动。我无法做的就是当我把它设置好时,让它画出来。

其他信息: ParticleEngine本身就是一个类,基本上设置了一些关于我将要绘制的粒子应该如何表现的参数。我有spritebatch BeginEnd来电的其他屏幕。除此之外,这是我的主要类的代码:

namespace PlanetDrill2
{
class LaunchScreen : Screen
{
    Texture2D LaunchScreenTexture;
    Texture2D shipLaunch;

    Vector2 shipPos;
    float shipMovement;
    ParticleEngine particleEngine;

    Vector2 smokePos;

    public LaunchScreen(Game game, SpriteBatch batch, ChangeScreen changeScreen)
        : base(game, batch, changeScreen)
    {            
    }

    protected override void SetupInputs()
    {
        base.SetupInputs();
    }

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

    public void LaunchShip()
    {
    }

    public void loadEmitter(GameTime gameTime)
    {
        shipMovement = 2f;
        shipPos.Y -= shipMovement;        
        particleEngine.EmitterLocation = new Vector2(shipPos.X,shipPos.Y);
    }

    protected override void LoadScreenContent(ContentManager content)
    {
        LaunchScreenTexture = content.Load<Texture2D>("launchTest");
        shipLaunch = content.Load<Texture2D>("shipLaunch");

        List<Texture2D> textures = new List<Texture2D>();
        textures.Add(content.Load<Texture2D>("smoketexture"));
        particleEngine = new ParticleEngine(textures, new Vector2(0, 0));
        base.LoadScreenContent(content);
    }

    protected override void UpdateScreen(GameTime gameTime, DisplayOrientation screenOrientation)
    {
        //if (gameTime.TotalGameTime.Seconds>10)
        //{
        //    changeScreenDelegate(ScreenState.UMA);
        //}


        loadEmitter(gameTime);
        particleEngine.Update();
        base.UpdateScreen(gameTime, screenOrientation);
    }

    protected override void DrawScreen(SpriteBatch batch, DisplayOrientation screenOrientation)
    {
        batch.Draw(LaunchScreenTexture, Vector2.Zero, Color.White);
        batch.Draw(shipLaunch, new Vector2(80, 450) +shipPos, Color.White);
        particleEngine.Draw(batch);
        base.DrawScreen(batch, screenOrientation);
    }

    protected override void SaveScreenState()
    {
        base.SaveScreenState();
    }
} // end class LaunchScreen
} // end namespace PlanetDrill2

1 个答案:

答案 0 :(得分:1)

从这里

batch.Draw(shipLaunch, new Vector2(80, 450) +shipPos, Color.White);
particleEngine.Draw(batch);

看起来您正在相对于[80,450]绘制船只,但您没有将此偏移应用于particleEngine。