标签: monogame

使用 Monogame 绘制平铺地图

我一直在尝试实现一个函数,让我可以在平铺文件(.tmx)中绘制平铺。我环顾四周,发现了一种有效的代码,但它拉伸了瓷砖
这是我找到并编辑了一下的代码:

private void DrawLayer(int index, SpriteBatch batch) {
        for (var i = 0; i < Map.Layers[index].Tiles.Count; i++) {
            //Get the identification of the tile
            int gid = Map.Layers[index].Tiles[i].Gid;

            // Empty tile, do nothing
            if (gid == 0) { }
            else {
                int tileFrame = gid - 1 ;
                int column = tileFrame % (tileset.Width / tileWidth);
                int row = tileFrame / (tileset.Height / tileHeight);

                float x = (i % Map.Width) * Map.TileWidth;
                float y = (float)Math.Floor(i / …
Run Code Online (Sandbox Code Playgroud)

c# monogame

3
推荐指数
1
解决办法
1万
查看次数

无边框窗口monogame

我正在尝试将XNA游戏移植到MonoGame.我只想针对Windows平台.我想在无边框窗口中显示游戏.我这样做,在我的XNA游戏中:

private void SetForm()
    {
        Form myForm = (Form)Form.FromHandle(this.Window.Handle);
        myForm.Name = "WIPForm";            
        int width = 1024;
        int height = 768;           
        IntPtr auxptr = (this.Window.Handle);
        SafeNativeMethods.MoveWindow(
            (int)auxptr,
            0,
            0,
            Properties.Settings.Default.width,
            Properties.Settings.Default.height,
            1);
        myForm.FormBorderStyle = FormBorderStyle.None;
        myForm.SetBounds(0, 0, width, height);
    }
Run Code Online (Sandbox Code Playgroud)

当我在monogame版本myForm = null中测试此代码时.有没有办法在monogame版本中绘制无边框窗口?

xna borderless monogame

2
推荐指数
1
解决办法
2512
查看次数

GameTime.ElapsedGameTime不变

我想弄清楚如何在我的XNA游戏中创建一个Timer.我正在使用MonoGame并开发用于Windows 8 RT.当我使用以下方法检查GameTime.ElapsedGameTime时:

    protected override void Update(GameTime gameTime)
    {
        TimeSpan mean = gameTime.ElapsedGameTime - last;
        Debug.WriteLine(gameTime.ElapsedGameTime.ToString());
        ...
Run Code Online (Sandbox Code Playgroud)

ElapsedGameTime始终为00:00:00.0166666.它不会改变这个值.为什么会这样?

c# xna monogame microsoft-metro windows-runtime

2
推荐指数
1
解决办法
969
查看次数

如何在Monogame Windows Phone 8 Game项目上设置xnb文件?

我从来没有找到任何教程来使xnb文件工作.他们都使用非Windows Phone 8(Win 8 metro等)的方式.

有人可以指导我让我的xnb文件在MonoGame Windows Phone 8游戏项目中可行吗?因为我用Google搜索没有任何好处.

另外,我可以使用XNA Windows游戏项目(使用VS 2010)创建XNB,还是需要将项目作为Windows Phone游戏(我没有安装WPhoneSDK 7.1,但已在VS2012中安装了第8个)

到目前为止,我使用了几种方法并继续导致Microsoft.Xna.Framework.ContentLoadException

谢谢

xna windows-phone-7 monogame windows-phone-8

2
推荐指数
1
解决办法
2704
查看次数

透明度问题从Monogame中的PNG加载纹理

我试图在Windows上的MonoGame GL中完成我认为非常简单的事情.那就是从PNG文件加载纹理并将其作为精灵渲染到屏幕上.到目前为止,我遇到了很多麻烦.我正在使用以下代码(F#)将PNG加载到Texture2D:

    use file = System.IO.File.OpenRead("testTexture.png")
    this.texture <- Texture2D.FromStream(this.GraphicsDevice, file)
Run Code Online (Sandbox Code Playgroud)

然后渲染:

    this.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
    this.spriteBatch.Draw(this.texture, Vector2.Zero, Color.White)
    this.spriteBatch.End()
Run Code Online (Sandbox Code Playgroud)

这个问题是对alpha通道有一些奇怪的影响,好像有些东西没有通过alpha预乘或某些东西,但我无法准确确定发生了什么.值得注意的是,完全相同的代码使用官方XNA库完美呈现.这个问题只出现在MonoGame中,我使用3.0和3.2版进行了测试,两者都有相同的问题.

这是在MonoGame中渲染测试PNG来说明问题:

http://i.imgur.com/Dny26gI.png

每个图像中的背景是矢车菊蓝色,然后分别是纯红色,绿色和蓝色.请注意,在带有红色背景的图像中,您可以看到纹理中红色线条周围的黑色轮廓.由于线条和背景都是纯红色,因此不应该出现此轮廓.请注意,具有蓝色背景的图像中的蓝线周围会出现相同的情况,但绿色背景的图像中则不会出现相同的情况.在该图像中,绿线与绿色背景融为一体.

下面是使用官方XNA库完全相同的文件呈现方式.

http://i.imgur.com/2Rtqhuk.png

注意当背景颜色相同时,蓝色,绿色和红色线如何融入背景.这是正确的行为.

鉴于相同的代码在XNA和MonoGame中表现不同,我相信框架中必定存在错误.任何人都可以对这个错误的位置和性质有什么好的猜测吗?如果这是一个简单的解决方案,那么最好的解决方案可能就是自己解决这个问题.

除此之外,我真的只是想学习一种方法,我可以简单地加载PNG并将其正确地渲染到MonoGame的屏幕上.我敢肯定,我不能成为第一个想要这样做的人.我想尽可能避免使用内容管道,只是为了简单起见.

更新

我已经做了一些挖掘,试图弄清楚这个问题的本质.我已经更改了testTexture.png文件,以便更多地揭示alpha混合问题.使用这个新的纹理文件后,我拍摄了不正确的MonoGame渲染的截图,并在其单独的颜色通道中查看.发生的事情让我非常困惑.我最初虽然可能是一个BlendState.NonPremultiplied被忽略的简单案例,但我所看到的看起来更复杂.除此之外,绿色通道似乎与蓝色和红色通道的混合方式不同.这是一个相当大的PNG图像,它是关于我正在谈论的截图和解释的汇编:

i.imgur.com/CEUQqm0.png

显然,MonoGame for Windows GL中存在某种错误,可能还有其他版本我没试过这个版本(虽然我有兴趣看看已经验证过).如果有人认为他们知道这里可能会发生什么,请告诉我.

最后,这是重现我遇到的问题的项目文件:

mega.co.nz/#!llFxBbrb!OrpPIn4Tu2UaHHuoSPL03nqOtAJFK59cfxI5TDzLyYI

graphics rendering sprite monogame

2
推荐指数
1
解决办法
2658
查看次数

MonoGame无法正常工作

我刚刚开始使用MonoGame(以及一般的游戏编程)并且无法运行任何程序.我一直收到这条异常消息

MonoGame.Framework.dll中发生未处理的"System.DllNotFoundException"类型异常

其他信息:无法加载DLL'openal32.dll':找不到指定的模块.(来自HRESULT的异常:0x8007007E)

有谁知道我怎么解决这个问题?

c# monogame

2
推荐指数
1
解决办法
4466
查看次数

Visual Studio无法识别我的构造函数?

我最近开始使用monogame,一切都很顺利,直到发生这种情况.我不是很有经验,所以这可能只是看起来很愚蠢,但我已经尝试了一切,这是我唯一的选择,所以这是我的构造函数:

public void qlayer(Vector2 position, Texture2D texture)
{
    this.position = position;
    this.texture = texture;
}
Run Code Online (Sandbox Code Playgroud)

"qlayer"是我的类的名称,但它一直说:"成员名称不能与它们的封闭类型相同",如果我不想构建一个构造函数,这将是有意义的!

为了安全起见,这是全班:

class qlayer
{
    Vector2 position;
    Point speed;
    Rectangle hitbox;
    Texture2D texture;
    Point currentFrame;
    int timeSinceLastFrame = 0;
    int millisecondsPerFrame;
    bool isFront = true;
    Point sheetSize = new Point(2,3);

    public void qlayer(Vector2 position, Texture2D texture, SpriteBatch spritebatch)
    {
        this.position = position;
        this.texture = texture;

    }

    enum PlayerAni
    {
        left, front, right
    };

    PlayerAni currentAni = PlayerAni.front;

    public void Update(GameTime gameTime)
    {
        timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; …
Run Code Online (Sandbox Code Playgroud)

c# xna constructor monogame

2
推荐指数
1
解决办法
444
查看次数

MonoGame/XNA旋转图像

这段代码是为了绘制塔.广场位置是广场的左上角.TILE_SIZE只是方形的尺寸.

SpriteBatch.Draw(TowerImage, new Rectangle(square.X * TILE_SIZE, square.Y * TILE_SIZE, TILE_SIZE, TILE_SIZE), null, Color.White, myTower.Rotation, 
    new Vector2(TILE_SIZE - 35, TILE_SIZE - 35), SpriteEffects.None, (float)0.0);
Run Code Online (Sandbox Code Playgroud)

这段代码是我确定旋转的方式

public void FaceTarget(Vector2 center, Vector2 enemyCenter)
        {
            Vector2 direction = center - enemyCenter;
            direction.Normalize();

            this.Rotation = (float)Math.Atan2(-direction.X, direction.Y);
        }
Run Code Online (Sandbox Code Playgroud)

我这样做基于:

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Rotation.php

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Direction_to_Angle.php

旋转真的很奇怪,这是它看起来如何正常:

http://puu.sh/bkd0E.png

但是当它旋转时它会像这样:

http://puu.sh/bkd6K.png

最后,当它往下看时,它完全离开路径,它不是由它的中心旋转,但整个图像正在移动它为什么这样做?

http://i.stack.imgur.com/4PuiZ.jpg

只有第一张图像实际上是正确位置的塔

看起来它是左上角的旋转,我不知道为什么.有人可以帮忙吗?

c# xna sprite image-rotation monogame

2
推荐指数
1
解决办法
1827
查看次数

错误 - SpriteFont未实现

我正试图在Monogame程序中绘制文本.我想使用SpriteFont来执行此操作,但在尝试加载SpriteFont时出现以下错误.

//Here I try to load the SpriteFont
//It is kept in the "Content/fonts" folder, with "Content" as the Content.RootDirectory
Font = Content.Load<SpriteFont>("fonts/SpriteFont1");

//I then get this error
An unhandled exception of type 'System.NotImplementedException' occurred in MonoGame.Framework.dll
Additional information: The method or operation is not implemented.
Run Code Online (Sandbox Code Playgroud)

SpriteFont1构建操作设置为"内容",复制到输出目录为"始终复制".SpriteFont1.xnb文件位于Content文件夹中,具有相同的设置.如何修复错误以便我可以加载SpriteFont?

c# monogame spritefont

2
推荐指数
1
解决办法
1711
查看次数

Monogame - 更改精灵的大小

我为一个300x135像素的游戏创建了一个背景图像.当加载到我的游戏中时,我需要它从点(0,0)开始,它执行:

position = new Vector2(0, 0);
Run Code Online (Sandbox Code Playgroud)

但是我想放大这个图像,所以它扩展到1200x540像素,但是我不太清楚如何做到这一点,虽然我知道我的意思是使用Rectangle或类似的东西.

以下是我的背景图片的组件:

Vector2 position;
Texture2D texture;
Run Code Online (Sandbox Code Playgroud)

c# xna monogame

2
推荐指数
1
解决办法
3089
查看次数