2012-11-29 65 views
1

对于monogame来说很新颖(对于Android来说是单精度的),但是对于一些YouTube教程来说,这个过程相当不痛。 我想重写一些函数(从“XNA库项目”的DLL)我可以覆盖所有的功能就好了。但是,当我尝试去驾驭任何通过在SpriteBatch作为参数,我得到了如下错误:Monogame;不能覆盖任何以SpriteBatch作为参数的方法

Error 5 'Parkour.Screens.EditorScreen.Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch)': no suitable method found to override D:\Data\programming and such\comps\TIGsport\XNA\Parkour\Parkour\Parkour\Screens\EditorScreen.cs 117 30 ParkourAndroid

我绝对肯定的方法是存在的,因为XNA项目工作就好了。 Draw函数也会在android项目的mono中自动更正。但是奇怪的是,在我收到错误消息后,它似乎消失了自动更正。

这里是整个类,它拥有重写功能,所以你们可以肯定没有什么是错的。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Xna.Framework.Graphics; 

namespace SimpleTilebasedLibrary.Utils 
{ 
    public class LoopContainer<T> where T : ILoopable 
    { 
     protected List<T> _items = new List<T>(); 
     private List<T> _addList = new List<T>(); 
     private List<T> _removeList = new List<T>(); 

     public List<T> items 
     { 
      get{return _items;} 
     } 

     public virtual void add(T item) 
     { 
      //if (_addList.Contains(item)) return; 
      //_addList.Add(item); 
      _items.Add(item); 
     } 

     public virtual void remove(T item) 
     { 
      if (_removeList.Contains(item)) return; 
      _removeList.Add(item); 
     } 

     public T get(int index) 
     { 
      return _items[index]; 
     } 

     public T get(string name) 
     { 
      foreach (T item in items) 
      { 
       if (item.getName() == name) 
       { 
        return item; 
       } 
      } 

      return default(T); 
     } 

     public virtual void Update() 
     { 
      items.AddRange(_addList); 
      _addList.Clear(); 

      foreach (T item in items) 
      { 
       if (item.status == Status.DEAD) 
       { 
        _removeList.Add(item); 
        //break; //root of all evil 
        continue; 
       } 

       item.Update(); 
      } 

      //remove 
      foreach (T i in _removeList) 
      { 
       items.Remove(i); 
      } 
      _removeList.Clear(); 

     } 

     public virtual void postUpdate() 
     { 
      foreach (T item in items) 
      { 
       item.postUpdate(); 
      } 
     } 

     public virtual void Draw(SpriteBatch spritebatch) 
     { 
      foreach (T item in items) 
      { 
       item.Draw(spritebatch); 
      } 
     } 
    } 
} 

,这是试图重写它

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using SimpleTilebasedLibrary; 
using SimpleTilebasedLibrary.Entities; 
using SimpleTilebasedLibrary.Tilesystem; 
using SimpleTilebasedLibrary.Services; 
using Microsoft.Xna.Framework.Input; 
using SimpleTilebasedLibrary.Components; 
using SimpleTilebasedLibrary.Utils; 
using SimpleTilebasedLibrary.UI; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Graphics; 

namespace Parkour.Screens 
{ 
    public class EditorScreen : GameScreen //need to couple gamescreens with inputcontexts? 
    { 
     public ParkourWorld world; 
     int currentTile = 0; 
     GameObject tile; 

     Checkbox editorEnabled; 
     Checkbox solidCB; 
     Checkbox autotileCB; 

     public EditorScreen(ParkourWorld world) 
      : base("editorscreen") 
     { 
      this.world = world; 
      tile = new GameObject("tileset", 16, 16); //never actually tested this, doesn't work! 
      tile.GetC<GraphicsC>().setScale(2, 2); 
      //add(tile); //something fucks up the coordinates when you add it... 

      editorEnabled = new Checkbox(Color.White, 10); 
      editorEnabled.GetC<TransformC>().Y = 10; 
      editorEnabled.GetC<TransformC>().X = 100; 

      solidCB = new Checkbox(Color.Red, 10); 
      solidCB.GetC<TransformC>().Y = 10;//30; 
      solidCB.GetC<TransformC>().X = 120; 
      //add(solidCB); 

      autotileCB = new Checkbox(Color.Blue, 10); 
      autotileCB.GetC<TransformC>().Y = 10;//50; 
      autotileCB.GetC<TransformC>().X = 140; 
      //add(autotileCB); 

      editorEnabled.value = false; 
     } 


     public override void Update() 
     { 
      base.Update(); 

      if (GameServices.get<InputManager>().hasScrolledDown() && currentTile > 0) 
      { 
       currentTile--; 
      } 

      if (GameServices.get<InputManager>().hasScrolledUp() && currentTile < tile.GetC<GraphicsC>().totalFrames - 1) 
      { 
       currentTile++; 
       Console.WriteLine(currentTile); 
      } 

      tile.GetC<GraphicsC>().gotoAndStop(currentTile); 

      // 


      if (Mouse.GetState().LeftButton == ButtonState.Pressed && editorEnabled.value) 
      { 
       GameCamera camera = GameServices.get<CameraManager>().getActiveCamera(); 

       int x = TileMath.PixelToTile((Mouse.GetState().X + (camera.GetC<CameraC>().leftX * camera.GetC<CameraC>().zoom))/camera.GetC<CameraC>().zoom, world.tilegrid.tileWidth); 
       int y = TileMath.PixelToTile((Mouse.GetState().Y + (camera.GetC<CameraC>().UpY * camera.GetC<CameraC>().zoom))/camera.GetC<CameraC>().zoom, world.tilegrid.tileHeight); 

       if (Keyboard.GetState().IsKeyDown(Keys.Z)) 
       { 
        world.tilegrid.setTile(x, y, 0, null); 
        //world.tilegrid.getTile(x, y, 0).id = 1; 
        //world.tilegrid.getTile(x, y, 0).solid = false; 
       } 
       else 
       { 
        Tile t = world.tilegrid.setTile(x, y, 0, currentTile); 
        if (t != null) t.solid = solidCB.value; 

        if(autotileCB.value)world.tilegrid.AutoTile(t, 0, x, y, true); 
        //world.tilegrid.setTile(x, y, 0, null); 
       } 
      } 

      // enable and disable cb's // 
      if (GameServices.get<InputManager>().wasKeyPressed(Keys.LeftShift)) 
      { 
       solidCB.value = !solidCB.value; 
      } 

      if (GameServices.get<InputManager>().wasKeyPressed(Keys.Q)) 
      { 
       autotileCB.value = !autotileCB.value; 
      } 

      if (GameServices.get<InputManager>().wasKeyPressed(Keys.E)) 
      { 
       editorEnabled.value = !editorEnabled.value; 
      } 

      solidCB.Update(); 
      autotileCB.Update(); 
     } 

     public override void Draw(SpriteBatch spritebatch) 
     { 
      base.Draw(spritebatch); 
      tile.Draw(spritebatch); 
      editorEnabled.Draw(spritebatch); 
      solidCB.Draw(spritebatch); 
      autotileCB.Draw(spritebatch); 

      CameraC camera = GameServices.get<CameraManager>().getActiveCameraC(); 

      int width = TileMath.PixelToTile(camera.viewrect.Left + camera.viewrect.Width + (world.tilegrid.tileWidth * 2), world.tilegrid.tileWidth); 
      int height = TileMath.PixelToTile(camera.viewrect.Top + camera.viewrect.Height + (world.tilegrid.tileHeight * 2), world.tilegrid.tileHeight); 

      if (editorEnabled.value) 
      { 
       spritebatch.End(); 
       spritebatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, GameServices.get<CameraManager>().getActiveCameraC().getTransformation()); 

       //getTile(width - 1, 0).GetComponent<GraphicsC>().sprite.gotoAndStop(4); 

       Rectangle rect = new Rectangle(); 
       Color trans = new Color(255, 0, 0, 10); 
       for (int x = TileMath.PixelToTile(camera.viewrect.Left, world.tilegrid.tileWidth); x < width; x++) 
       { 
        for (int y = TileMath.PixelToTile(camera.viewrect.Top, world.tilegrid.tileHeight); y < height; y++) 
        { 
         if (world.tilegrid.getTile(x, y, 0) != null) 
         { 
          if (!world.tilegrid.getTile(x, y, 0).solid) continue; 
          rect.X = x * world.tilegrid.tileWidth; 
          rect.Y = y * world.tilegrid.tileHeight; 
          rect.Width = world.tilegrid.tileWidth; 
          rect.Height = world.tilegrid.tileHeight; 
          spritebatch.Draw(GameServices.get<AssetManager>().CreateColoredTexture(trans), rect, Color.White); 
         } 
        } 
       } 

       spritebatch.End(); 
       spritebatch.Begin(); 
      } 
     } 


    } 


} 

有很多没用的东西在那里为你们的课,但我想包括它只是为了完整起见。

我有另一个具有Draw(SpriteBatch)函数需要重写的完全相同的问题。

+0

'GameScreen'是否继承'LoopContainer '一些沿线或包含它自己的'Draw(SpriteBatch spriteBatch)'方法?你不能在另一个类上“覆盖”一个方法,但它们之间没有任何关系。 –

+0

你能否给我包含你的'GameScreen'的代码? –

+0

我意识到我的代码不是很清楚。是的,它继承了GameScreen。 另一方面,我想我可能已经发现了什么问题,但我不完全确定。我正在加载的dll已经使用XNA框架进行了编译。也许我应该首先在一个monogame项目中编译它?我猜基础函数需要一个Microsoft SpriteBatch,而EditorScreen有一个MonoGame SpriteBatch参数? – omgnoseat

回答

0

原来,我传入了一个MonoGame spritebatch,其中库需要一个XNA spritebatch。我用MonoGame在一个单独的项目中重新编译了这个库,所有的问题都被解决了。