C# 为什么我不能';我找不到Spritebatch类?
我一直试图找到microsoft.xna.framework,该内容Spritebatch类定义对象,并通过AutoInitialize方法传递,但没有任何帮助,这是我的类:C# 为什么我不能';我找不到Spritebatch类?,c#,xna,C#,Xna,我一直试图找到microsoft.xna.framework,该内容Spritebatch类定义对象,并通过AutoInitialize方法传递,但没有任何帮助,这是我的类: #region Using Statements using System; using DPSF; using Microsoft.Xna.Framework; using System.Collections.Generic; using Microsoft.Xna.Framework.Content; using M
#region Using Statements
using System;
using DPSF;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.GamerServices;
#endregion
namespace Scientifical_Calculations
{
#if (WINDOWS)
[Serializable]
#endif
class SphereParticle : DefaultTexturedQuadParticle
{
/// <summary>
/// The position of the particle on the sphere, independent of the emitter's position.
/// </summary>
public Vector3 sEmitterIndependentPosition;
/// <summary>
/// How fast the particle is rotating around the sphere's origin.
/// </summary>
public Vector3 sPivotRotationVelocity;
public override void Reset()
{
base.Reset();
sEmitterIndependentPosition = Vector3.Zero;
sPivotRotationVelocity = Vector3.Zero;
}
public override void CopyFrom(DPSFParticle ParticleToCopy)
{
base.CopyFrom(ParticleToCopy);
SphereParticle cParticle = (SphereParticle)ParticleToCopy;
sEmitterIndependentPosition = cParticle.sEmitterIndependentPosition;
sPivotRotationVelocity = cParticle.sPivotRotationVelocity;
}
}
/// <summary>
/// Create a new Particle System class that inherits from a Default DPSF Particle System.
/// </summary>
#if (WINDOWS)
[Serializable]
#endif
class SphereParticleSystem : DPSFDefaultTexturedQuadParticleSystem<SphereParticle, DefaultTexturedQuadParticleVertex>
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="cGame">Handle to the Game object being used. Pass in null for this
/// parameter if not using a Game object.</param>
public SphereParticleSystem(Game cGame) : base(cGame) { }
//===========================================================
// Structures and Variables
//===========================================================
int miNumberOfParticles = 100;
float mfSphereRadius = 50;
float mfParticlePivotRotationMaxSpeed = MathHelper.PiOver2;
Vector3 mfParticlePivotRotationDirection = DPSFHelper.RandomNormalizedVector();
//===========================================================
// Overridden Particle System Functions
//===========================================================
/// <summary>
/// Function to setup the Render Properties (i.e. BlendState, DepthStencilState, RasterizerState, and SamplerState)
/// which will be applied to the Graphics Device before drawing the Particle System's Particles.
/// <para>This function is called when initializing the particle system.</para>
/// </summary>
protected override void InitializeRenderProperties()
{
base.InitializeRenderProperties();
// Use additive blending
RenderProperties.BlendState = BlendState.Additive;
}
//===========================================================
// Initialization Functions
//===========================================================
/// <summary>
/// Function to Initialize the Particle System with default values
/// </summary>
/// <param name="cGraphicsDevice">The Graphics Device to draw to</param>
/// <param name="cContentManager">The Content Manager to use to load Textures and Effect files</param>
public override void AutoInitialize(GraphicsDevice cGraphicsDevice, ContentManager cContentManager, SpriteBatch cSpriteBatch)
{
// Initialize the Particle System before doing anything else
InitializeTexturedQuadParticleSystem(cGraphicsDevice, cContentManager, miNumberOfParticles, miNumberOfParticles,
UpdateVertexProperties, "Textures/Particle");
// Set the Name of the Particle System
Name = "Sphere";
// Finish loading the Particle System in a separate function call, so if
// we want to reset the Particle System later we don't need to completely
// re-initialize it, we can just call this function to reset it.
LoadParticleSystem();
}
/// <summary>
/// Load the Particle System Events and any other settings
/// </summary>
public void LoadParticleSystem()
{
ParticleInitializationFunction = InitializeParticleProperties;
// Remove all Events first so that none are added twice if this function is called again
ParticleEvents.RemoveAllEvents();
ParticleSystemEvents.RemoveAllEvents();
// Allow the Particle's Velocity, Rotational Velocity, Width and Height, Color, Transparency, and Orientation to be updated each frame
ParticleEvents.AddEveryTimeEvent(UpdateParticlePositionAndVelocityUsingAcceleration);
ParticleEvents.AddEveryTimeEvent(UpdateParticleRotationUsingRotationalVelocity);
ParticleEvents.AddEveryTimeEvent(UpdateParticlePositionToRotateAroundEmitter);
// This function must be executed after the Color Lerp function as the Color Lerp will overwrite the Color's
// Transparency value, so we give this function an Execution Order of 100 to make sure it is executed last.
ParticleEvents.AddEveryTimeEvent(UpdateParticleTransparencyToFadeOutUsingLerp, 100);
ParticleEvents.AddEveryTimeEvent(UpdateParticleToFaceTheCamera, 200);
// Setup the Emitter
Emitter.ParticlesPerSecond = 100;
Emitter.PositionData.Position = new Vector3(0, 60, 0);
MaxNumberOfParticlesAllowed = miNumberOfParticles;
}
/// <summary>
/// Example of how to create a Particle Initialization Function
/// </summary>
/// <param name="cParticle">The Particle to be Initialized</param>
public void InitializeParticleProperties(SphereParticle cParticle)
{
//-----------------------------------------------------------
// TODO: Initialize all of the Particle's properties here.
// If you plan on simply using the default InitializeParticleUsingInitialProperties
// Particle Initialization Function (see the LoadParticleSystem() function above),
// then you may delete this function all together.
//-----------------------------------------------------------
cParticle.Lifetime = 0.0f;
// Set the Particle's initial Position to be wherever the Emitter is
cParticle.Position = Emitter.PositionData.Position;
// Set the Particle to be Radius amount away from the Emitter
cParticle.sEmitterIndependentPosition.X = mfSphereRadius;
// Rotate the Particle to start somewhere on the surface of the sphere
cParticle.sEmitterIndependentPosition = DPSFHelper.PointOnSphere(DPSFHelper.RandomNumberBetween(0, MathHelper.TwoPi), DPSFHelper.RandomNumberBetween(0, MathHelper.TwoPi), mfSphereRadius);
cParticle.Size = 20;
// Give the Particle a random Color
// Since we have Color Lerp enabled we must also set the Start and End Color
cParticle.Color = DPSFHelper.RandomColor();
cParticle.sPivotRotationVelocity = DPSFHelper.RandomNormalizedVector() * mfParticlePivotRotationMaxSpeed * RandomNumber.NextFloat();
}
//===========================================================
// Particle Update Functions
//===========================================================
/// <summary>
/// Rotate a Particle around the Emitter
/// </summary>
/// <param name="cParticle">The Particle to update</param>
/// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
protected void UpdateParticlePositionToRotateAroundEmitter(SphereParticle cParticle, float fElapsedTimeInSeconds)
{
// Calculate how much to rotate this frame and Rotate the Particle's Position
Vector3 sRotationAmount = cParticle.sPivotRotationVelocity * fElapsedTimeInSeconds;
Matrix sRotation = Matrix.CreateFromYawPitchRoll(sRotationAmount.Y, sRotationAmount.X, sRotationAmount.Z);
// Rotate the particle around the Emitter
cParticle.sEmitterIndependentPosition = PivotPoint3D.RotatePosition(sRotation, Vector3.Zero, cParticle.sEmitterIndependentPosition);
cParticle.Position = cParticle.sEmitterIndependentPosition + Emitter.PositionData.Position;
}
protected void UpdateParticleDistanceFromEmitter(SphereParticle cParticle, float fElapsedTimeInSeconds)
{
Vector3 sDirectionToParticle = cParticle.sEmitterIndependentPosition;
sDirectionToParticle.Normalize();
cParticle.sEmitterIndependentPosition = sDirectionToParticle * mfSphereRadius;
}
protected void UpdateParticlePivotRotationVelocityRandomly(SphereParticle cParticle, float fElapsedTimeInSeconds)
{
cParticle.sPivotRotationVelocity = DPSFHelper.RandomNormalizedVector() * mfParticlePivotRotationMaxSpeed * RandomNumber.NextFloat();
}
protected void UpdateParticlePivotRotationVelocityToBeTheSame(SphereParticle cParticle, float fElapsedTimeInSeconds)
{
cParticle.sPivotRotationVelocity = mfParticlePivotRotationDirection * mfParticlePivotRotationMaxSpeed * RandomNumber.NextFloat();
}
//===========================================================
// Particle System Update Functions
//===========================================================
//===========================================================
// Other Particle System Functions
//===========================================================
public void ChangeSphereRadius(float fAmountToChange)
{
mfSphereRadius += fAmountToChange;
if (mfSphereRadius < 20)
{
mfSphereRadius = 20;
}
ParticleEvents.AddOneTimeEvent(UpdateParticleDistanceFromEmitter);
}
public void MakeParticlesTravelInTheSameDirection()
{
mfParticlePivotRotationDirection = DPSFHelper.RandomNormalizedVector();
ParticleEvents.AddOneTimeEvent(UpdateParticlePivotRotationVelocityToBeTheSame);
}
public void MakeParticlesTravelInRandomDirections()
{
ParticleEvents.AddOneTimeEvent(UpdateParticlePivotRotationVelocityRandomly);
}
public void ChangeNumberOfParticles(int iAmountToChange)
{
MaxNumberOfParticlesAllowed += iAmountToChange;
if (MaxNumberOfParticlesAllowed < 50)
{
MaxNumberOfParticlesAllowed = 50;
}
NumberOfParticlesAllocatedInMemory = MaxNumberOfParticlesAllowed;
}
}
}
#使用语句的区域
使用制度;
使用DPSF;
使用Microsoft.Xna.Framework;
使用System.Collections.Generic;
使用Microsoft.Xna.Framework.Content;
使用Microsoft.Xna.Framework.Graphics;
使用Microsoft.Xna.Framework.GamerServices;
#端区
名称空间科学计算
{
#如果(WINDOWS)
[可序列化]
#恩迪夫
类SphereParticle:DefaultTexturedQuadParticle
{
///
///粒子在球体上的位置,与发射器的位置无关。
///
公共矢量3;独立位置;
///
///粒子围绕球体原点旋转的速度。
///
公共矢量3旋转速度;
公共覆盖无效重置()
{
base.Reset();
SemiterIndependentPosition=Vector3.0;
sPivotRotationVelocity=Vector3.0;
}
公共覆盖无效复制自(DPSFParticle ParticleToCopy)
{
base.CopyFrom(ParticleToCopy);
SphereParticle cParticle=(SphereParticle)粒子复制;
sEmitterIndependentPosition=cParticle.sEmitterIndependentPosition;
SpivotionVelocity=cParticle.SpivotionVelocity;
}
}
///
///创建从默认DPSF粒子系统继承的新粒子系统类。
///
#如果(WINDOWS)
[可序列化]
#恩迪夫
类SphereParticleSystem:DPSFDefaultTexturedQuadParticleSystem
{
///
///建造师
///
///正在使用的游戏对象的句柄。为此传入null
///参数,如果不使用游戏对象。
公共SphereParticleSystem(游戏cGame):基本(cGame){}
//===========================================================
//结构和变量
//===========================================================
int miNumberOfParticles=100;
浮球半径=50;
float mfParticlePivotRotationMaxSpeed=MathHelper.PiOver2;
Vector3 mfParticlePivotRotationDirection=DPSFHelper.RandomNormalizedVector();
//===========================================================
//覆盖粒子系统函数
//===========================================================
///
///函数设置渲染属性(即BlendState、DepthStencilState、光栅化状态和SamplerState)
///将在绘制粒子系统的粒子之前应用于图形设备。
///初始化粒子系统时调用此函数。
///
受保护的重写void initializenderProperties()
{
base.InitializeRenderProperties();
//使用添加剂混合
RenderProperties.BlendState=BlendState.Additional;
}
//===========================================================
//初始化函数
//===========================================================
///
///函数以使用默认值初始化粒子系统
///
///要绘制到的图形设备
///用于加载纹理和效果文件的内容管理器
公共覆盖无效自动初始化(GraphicsDevice cGraphicsDevice、ContentManager cContentManager、SpriteBatch cSpriteBatch)
{
//在执行任何其他操作之前初始化粒子系统
初始化TexturedQuadparticles系统(cGraphicsDevice、cContentManager、miNumberOfParticles、miNumberOfParticles、,
UpdateVertexProperties,“纹理/粒子”);
//设置粒子系统的名称
Name=“Sphere”;
//在单独的函数调用中完成粒子系统的加载,如果
//我们想稍后重置粒子系统,不需要完全重置
//重新初始化它,我们可以调用这个函数来重置它。
LoadParticleSystem();
}
///
///加载粒子系统事件和任何其他设置
///
公共无效LoadParticleSystem()
{
ParticleInitializationFunction=初始化ParticleProperties;
//首先删除所有事件,以便在再次调用此函数时不会两次添加任何事件
ParticleEvents.RemoveAllEvents();
ParticleSystemEvents.RemoveAllEvents();
//允许每帧更新粒子的速度、旋转速度、宽度和高度、颜色、透明度和方向
ParticleEvents.AdderyTimeEvent(更新ParticlePositionandVelocityu加速度);
ParticleEvents.AddEveryTimeEvent(使用旋转速度更新particleRotation);
ParticleEvents.AddEveryTimeEvent(更新ParticlePositionToRotateAroundEmitter);
//此功能必须在颜色Lerp功能之后执行,因为颜色Lerp将覆盖颜色的
//透明度值,所以我们给这个函数一个100的执行顺序,以确保它最后执行。
ParticleEvents.AddEveryTimeEvent(更新ParticleTransparencyCytoFadeOutsingleRP,100);
ParticleEvents.AddEveryTimeEvent(更新部分至AcetheCamera,200);
//设置发射器
发射器。粒子秒=100;
Emitter.PositionData.Position=新矢量3(0,60,0);
MaxNumberOfParticlesAllowed=粒子的分钟数;
}
///
///如何创建粒子初始化函数的示例
///
///要初始化的粒子
public void initializeparticleproperty