我一直在做一个侧滚动游戏,我几乎已经完成了游戏,当它为一个猫头鹰制作一个类时,代码与其他类似于我刚刚使用相同的方法,但现在当涉及到绘制猫头鹰主要游戏我没有视觉工作室的错误,游戏将运行,但猫头鹰不存在,我已经通过代码看,它的位置与其他类只是不会绘制
namespace SideScroller
{
class Owl
{
int timeSinceLastFrame, millisecondsPerFrame;
Random rand = new Random();
int randomX;
int ramdomY;
Boolean Capture = false;
//Owl Flying Properties
Texture2D OwlText;
Rectangle OwlRect;
public Vector2 OwlVec;
Point owlFlyingframes = new Point(6, 0);
Point owlFlyingcurrentframe = new Point(0, 0);
Point owlFlyingframesize = new Point(65, 66);
public Owl()
{
}
public void owlIniti()
{
millisecondsPerFrame = 6;
timeSinceLastFrame = 0;
OwlVec = new Vector2(600,600);
//OwlVec = new Vector2(randomX,ramdomY);
OwlRect = new Rectangle((int)OwlVec.X, (int)OwlVec.Y, 32, 32);
}
public void owlLoad(ContentManager content)
{
OwlText = content.Load<Texture2D>("Sprites/Owl");
}
public void owlUpdate()
{
timeSinceLastFrame++;
if (timeSinceLastFrame >= millisecondsPerFrame)
{
timeSinceLastFrame -= millisecondsPerFrame;
owlFlyingcurrentframe.X++;
if (owlFlyingcurrentframe.X == 4)
{
owlFlyingcurrentframe.X = 0;
}
}
}
public void owlMoving()
{
OwlVec.X = OwlVec.X + 3;
OwlRect.X = OwlRect.X + 3;
}
public void resetOwl(int windowswidth)
{
if (OwlVec.X <= 1100)
{
//OwlVec = new Vector2(rand.Next(-3000, -2000), rand.Next(100, 900));
//OwlRect = new Rectangle((int)OwlVec.X, (int)OwlVec.Y, 32, 32);
}
}
public void owlDraw(SpriteBatch spritebatch)
{
spritebatch.Draw(OwlText, OwlVec, new Rectangle(owlFlyingcurrentframe.X * owlFlyingframesize.X, owlFlyingcurrentframe.Y * owlFlyingframesize.Y, owlFlyingframesize.X, owlFlyingframesize.Y), Color.White, 0, Vector2.Zero, 0, SpriteEffects.None, 0);
}
}
这类似于我的龙类以及我的蝙蝠类,它们甚至在主游戏中设置相同,我将变量放在顶部Owl Theowl;以及
protected override void Initialize()
{
// Creating New Insects and passing in parameters Textures,Vector,Rectangle
Fly = new Insects(Content, Content.Load<Texture2D>("Sprites/Fly"), new Vector2(rand.Next(-600, -400), rand.Next(200, 800)), new Rectangle(rand.Next(-200, -100), rand.Next(200, 800), 34, 16));
Butterfly = new Insects(Content, Content.Load<Texture2D>("Sprites/Butterfly"), new Vector2(rand2.Next(-300, -250), rand2.Next(100, 890)), new Rectangle(rand2.Next(-300, -200), rand2.Next(100, 890), 34, 16));
Moth = new Insects(Content, Content.Load<Texture2D>("Sprites/Moth"), new Vector2(rand3.Next(-500, -300), rand3.Next(300, 850)), new Rectangle(rand3.Next(-500, -100), rand3.Next(100, 850), 34, 16));
Mos = new Insects(Content, Content.Load<Texture2D>("Sprites/Mos"), new Vector2(rand4.Next(-200, -50), rand4.Next(0, 900)), new Rectangle(rand4.Next(-200, -50), rand4.Next(0, 900), 34, 16));
// Adjusting The Graphics Windows
windowsHeight = graphics.PreferredBackBufferHeight = 1024;
windowsWidth = graphics.PreferredBackBufferWidth = 1024;
graphics.ApplyChanges();
// Initilize The Background
scrollingBackground = new Background();
scrollingBackground.backgroundIniti();
// Initialize The Bat
UserBat = new Bat();
UserBat.batIniti();
//Initialize The Dragon
enemyDragon = new Dragon();
enemyDragon.dragonIniti();
// Intialize The Owl
TheOwl = new Owl();
TheOwl.owlIniti();
//Initialize The Nesting Tree
Tree1 = new NestingTree();
Tree1.nestingTreeIniti();
base.Initialize();
}
初始化的代码与更新加载和绘制
的代码相同protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
scrollingBackground.assetLoad(Content);
enemyDragon.dragonLoad(Content);
UserBat.batAssetLoad(Content);
Tree1.nestingTreeLoad(Content);
TheOwl.owlLoad(Content);
// TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime)
{
oldKeyBoard1 = Keyboard1;
Keyboard1 = Keyboard.GetState();
if (dead == false)
{
//Scrolling Background
scrollingBackground.backgroundUpdate();
// Bat updates
UserBat.batUpdateAnimation();
UserBat.batMovement(Keyboard1, oldKeyBoard1);
UserBat.batBounds(windowsHeight, windowsWidth);
//Dragon Updates
enemyDragon.resetDragon(windowsWidth);
//Owl Updates
TheOwl.owlUpdate();
//Insect Updates
if (captureFly == false)
{
Fly.insectUpdate();
Fly.insectReset(windowsWidth);
}
if (CaptureButterfly == false)
{
Butterfly.insectUpdate();
Butterfly.insectReset(windowsWidth);
}
if (CaptureMoth == false)
{
Moth.insectUpdate();
Moth.insectReset(windowsWidth);
}
if (CaputreMos == false)
{
Mos.insectUpdate();
Mos.insectReset(windowsWidth);
}
Tree1.nestingTreeUpdate();
}
enemyDragon.dragonUpdate();
allCollisions();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
scrollingBackground.backgroundDraw(spriteBatch);
Tree1.nestingTreeDraw(spriteBatch);
TheOwl.owlDraw(spriteBatch);
UserBat.batDraw(spriteBatch);
enemyDragon.dragonDraw(spriteBatch);
Butterfly.InsectDraw(spriteBatch);
Fly.InsectDraw(spriteBatch);
Moth.InsectDraw(spriteBatch);
Mos.InsectDraw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
我无法绕过它,我改变了纹理我试图画猫头鹰....仍然没有什么似乎工作