Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all 6821 articles
Browse latest View live

Visual Studio for mac "Could not copy sdl2.dll because it was not found"

$
0
0

@beagle wrote:

I'm running into this error when creating a new cross platform solution in VS for mac 2017, with monogame 3.6. I create a new "Monogame Cross Platform Desktop Applicaton" solution, and try to build it. I get these errors:

/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/SDL2.dll" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/SDL2.dll" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/soft_oal.dll" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/soft_oal.dll" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/libSDL2-2.0.so.0" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/libSDL2-2.0.so.0" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/libopenal.so.1" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)
/Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB3030: Could not copy the file "/Library/Frameworks/Mono.framework/External/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/libopenal.so.1" because it was not found. (MSB3030) (TerrainGeneratorMono.Desktop)

I've tried installing the nuget Monogame DesktopGL package and maybe a few others, to no effect. Google hasn't returned anything helpful from these errors. Building a mac-only monogame solution works fine. I'd like to have this project be crossplatform though, so any help would be appreciated

Posts: 2

Participants: 1

Read full topic


How to write text with keyboard

$
0
0

@sebx29 wrote:

Hello,
sorry for my bad anglish ...
I'm new user of Monogame and it's ... Fantastic!

I started to develop a little C# game with Monogame and I need some help for writing texte.

I would like enter the name of player. For that, I can use KeyboardState.GetPressedKeys() and add char by char ... but it's very long.

Exists it an other class for that ? Like Console.readline() in C# ?

Posts: 4

Participants: 3

Read full topic

Arrays in shader (.fx) not working for OpenGL

$
0
0

@YTN wrote:

I have an OpenGL project and am currently working on the lighting system.

I am trying to add support for multiple lights by supporting passing an of array of light parameters to my shader.

However, when passing any array, my shader seems to get messed up and everything renders as red. It doesn't matter which attribute I try setting as an array (light color, light position etc). The end result is always a red scene.

Here's an example of how I am declaring the array in the shader:

        float  LightRange[10];

And this is how I am setting it in my c# code:

        float[] LightRange = new float[10];
        LightRange[0] = 50.0f;
        _effect.Parameters["LightRange"].SetValue(LightRange);

Referencing the indexed value in the shader is pretty standard:

         x = LightRange[index] * y;

Any ideas as to what the issue might be?

FYI, I am using build 3.7.0.1441.

Thanks.

Posts: 2

Participants: 2

Read full topic

Visual Studio 2017 Odd GPU Performance Profiler Behavior

$
0
0

@Kimimaru wrote:

I'm running Windows 10 on an Alienware 15 R3, which has an Nvidia GeForce GTX 1070. I'm trying to check GPU usage for a simple engine I'm building on top of MonoGame; the build platform is DesktopGL. I'm not running into any performance issues, but I'd like to see what most of the time rendering is being spent on. However, I'm getting weird results in the Visual Studio debugger. Regardless if I'm rendering 5 or 100,000 objects, it never shows me any information I find a use out of whether it's a Debug or Release build. Is this normal?

I've read that it might have something to do with Nvidia Optimus, but in the threads I've seen, they mention Visual Studio crashing or giving them an error; I get nothing of the sort, and as far as I know, my laptop model doesn't support Optimus.

Here are pictures of what the windows look like for me:
GPU Profile Window
Detailed GPU Profile Window

I'd appreciate any insight or advice. Thanks in advance!

Posts: 2

Participants: 2

Read full topic

Unable to build known working game after updates

$
0
0

@ChipzAh0i wrote:

I have been working on a game for a little over a year now using the MonoGame Mac Application template.
I originally created the project in Xamarin with Monogame 3.5 installed.
Eventually, I upgraded to Visual Studio for Mac, and still everything was working swimmingly.
A few weeks ago, I installed some updates when VS prompted, and since then, I have been unable to get the solution to build.
I have installed multiple different Monogame versions and even fully uninstalled Xamarin, Visual Studio, and any references to MonoGame that I could find.
I made no changes to the project between when it worked and when it didn't

When building the project, I get the following two errors:

Error: linker command failed with exit code 1 (use -v to see invocation)
Error MM5109: Native linking failed with error code 1. Check build log for details. (MM5109)

I'm at the point where I'm trying to manually move classes to a fresh project, a MonoGame Cross Platform Desktop Application this time.
But I'm unable to run even the empty template.

It builds fine, but the Application Output shows:
Cannot open assembly './test.Desktop.exe': No such file or directory.

I've been googling for about 3 weeks now and have tried everything I can find.
Any suggestions would be more than welcome.
I'm starting to go bald from pulling my hair out

Posts: 1

Participants: 1

Read full topic

Linux keyboard and sound problems

$
0
0

@Stephan_Goldenberg wrote:

Hi,

I'm at the final stage of the project from DrT's course at coursera.

First: The autofire does not work as intended using the keyboard.

It did work using the mouse, I'm reusing the same logic. You should be able to spam the space bar for rapid fire and when you keep it pressed there should be a constant fire rate. It does shoot in weird bursts then and another burst when the space bar is released.

// shoot if appropriate
if (keyState.IsKeyDown(Keys.Space) && health > 0){
if (canShoot){
canShoot = false;
Projectile projectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries), drawRectangle.X + drawRectangle.Width / 2, drawRectangle.Y + drawRectangle.Height + GameConstants.FrenchFriesProjectileOffset, GameConstants.FrenchFriesProjectileSpeed);
Game1.AddProjectile(projectile);
shootSound.Play();
} else{
elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
}
}
if (elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds || keyState.IsKeyUp(Keys.Space)){
canShoot = true;
elapsedCooldownMilliseconds = 0;
}

Second: Sound does just produce terrible noise. There are several shoot and bounce sounds, which were provided as .wav files. The pipeline tool did not complain. It worked for the shooting sounds but after adding the bouncing sounds it just a high pitched noise.

[oppa@oppa-hex-ssd ~]$ uname -a
Linux oppa-hex-ssd.oppator 4.15.12-301.fc27.x86_64 #1 SMP Thu Mar 22 19:25:27

UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Any ideas, esp. with the keyboard issue ? I guess the sound problem is down to some problems with converting from .wav to .xnb. In a first exercise I had a 'boing' sound which was just some weird sound after converting.

Happy Easter,
Stephan

Edit: Yep, there is one very short 'tick' sound for the bounce effect which is corrupted by the "translation" from .wav to .xnb. When I remove these from the project the rest of the sound effects are fine. Still the auto fire problem.

Posts: 1

Participants: 1

Read full topic

Deserialize XML to object for game editor

$
0
0

@mgtaa wrote:

Hello! I'm trying to write a game editor. I can already load my Map class from my game project with Content.Load<>.

I'm running into issues trying to find a way to deserialize the XML file. I'm not too sure which method to use, but every one I try runs into one problem or another.

If I try to use the IntermediateSerializer.Deserialize method, it says it doesn't support multi-dimentional arrays.

Trying to use the deserialize method of an XmlSerializer returns errors reflecting the type(Map)

This is the code for the Map class:
public class Map
{
#region Variables/Properties

        public string BGpath { get; set; }        

        public string collisionMaskFile;   


        [XmlArray("Events")]
        public List<Scene> Events;

        [XmlArray("Entities")]
        [XmlArrayItem("NPC", typeof(NPC))]
        public List<Entity> Entities;

        [XmlArray("MapObjects")]
        public List<MapObject> MapObjects;
        #endregion

        //public List<MapLayer> Layers { get; set; }

        //public CollisionLayer collisionLayer;

    }

Example of one of the XML files without much data in it:

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:Practice_RPG="Practice_RPG">
  <Asset Type="Practice_RPG:Map">
    <BGpath>C:\STUFF</BGpath>
    <collisionMaskFile>TestText</collisionMaskFile>
    <Events>    </Events>
    <Entities></Entities>
    <MapObjects> </MapObjects>
  </Asset>
</XnaContent>

Any help would be appreciated.

Posts: 6

Participants: 3

Read full topic

Can't get normals to properly work.

$
0
0

@Optmisitic_Peach wrote:

Hi there, I'm very new to shading and I was trying to create some terrain. I calculate all the positions and then I get the normals, but then when I render them, it all appears like a flat and shiny surface.

Edit: Gif doesn't show sometimes, if it doesn't, click on it.


Here is my drawing code:
protected void DrawPrimitivesUserDefined(VertexPositionColorNormal[] vertices)
{

    Utils.PrimitivesEffect.CurrentTechnique = Utils.PrimitivesEffect.Techniques["BasicEffect_VertexLighting_VertexColor"];

    Utils.PrimitivesEffect.World = SmartGardenCamera.worldMatrix;
    Utils.PrimitivesEffect.View = SmartGardenCamera.viewMatrix;
    Utils.PrimitivesEffect.Projection = SmartGardenCamera.projectionMatrix;

    Utils.PrimitivesEffect.EnableDefaultLighting();

    Utils.PrimitivesEffect.LightingEnabled = true; // turn on the lighting subsystem

    Utils.PrimitivesEffect.VertexColorEnabled = true;
    Utils.PrimitivesEffect.DiffuseColor = new Vector3(1, 0, 0);

    Utils.PrimitivesEffect.AmbientLightColor = new Vector3(0, .25f, .75f);
    Utils.PrimitivesEffect.EmissiveColor = new Vector3(0, 0, 1);

    RasterizerState rasterizerState = new RasterizerState();
    rasterizerState.CullMode = CullMode.CullClockwiseFace;
    rasterizerState.FillMode = FillMode.Solid;
    GraphicsDevice.RasterizerState = rasterizerState;



    foreach (EffectPass pass in Utils.PrimitivesEffect.CurrentTechnique.Passes)
    {
       pass.Apply();
       GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip,vertices, 0, (Consts.TerrainWidth * 2) - 2);
    }

    GraphicsDevice.RasterizerState = SolidState; //SolidState is set to FillMode.Solid; Resetting the rasterizer state.
}

And more importantly, here I calculate my normals:

    for (int i = 0; i < Terrain.Count; i++)
        {
            for (int j = 0; j < Terrain[i].Count - 2; j += 3)
            {
                Vector3 p1 = Terrain[i][j].Position;
                Vector3 p2 = Terrain[i][j + 1].Position;
                Vector3 p3 = Terrain[i][j + 2].Position;

                Vector3 v1 = p2 - p1;
                Vector3 v2 = p3 - p1;
                Vector3 normal = Vector3.Cross(v1, v2);

                normal = new Vector3(1, 1, 1);

                normal.Normalize();

                VertexPositionColorNormal vpcn1 = Terrain[i][j];
                VertexPositionColorNormal vpcn2 = Terrain[i][j + 1];
                VertexPositionColorNormal vpcn3 = Terrain[i][j + 2];

                vpcn1.Normal = normal;
                vpcn2.Normal = normal;
                vpcn3.Normal = normal;

                Terrain[i][j] = vpcn1;
                Terrain[i][j + 1] = vpcn2;
                Terrain[i][j + 2] = vpcn3;
            }
        }
        //Terrain is a List<List<VertexPositionColorNormal>>. 
        //Each List<VertexPositionColorNormal> is a strip of terrain

Mainly taken from here.

Any guidance is very much appreciated.
I apologize for my shallow understanding of shaders and normals. :frowning:

Posts: 2

Participants: 2

Read full topic


Sound related crashing

$
0
0

@Pixelsalt wrote:

Playing a sound appears to have a small chance of causing an IndexOutOfRange exception.
All my SoundEffect.Play() calls are in a try/catch block but it still happens and the stacktrace points to Game.Run().
Happens both on android and pc but on pc its exceedingly rare.

I have some users affected by this.
Anyone know anything about this problem?

Posts: 1

Participants: 1

Read full topic

Variance shadow Maps - Gaussian blur not working

$
0
0

@YTN wrote:

Anyone have a working sample of VSMs?

I have been trying to get this working, but am hitting a roadblock. My Gaussian blur seems to render my shadowmap empty / blank.

Here's how I am creating the blur render target:

            _blurMap = new RenderTarget2D(AxisGame.Instance.GraphicsDevice, 2048, 2048, false, SurfaceFormat.Color, DepthFormat.Depth24);

And here's the actual blur shader... this is straight out of the book "3D Graphics with XNA Game Studio 4.0" by Sean James (great book!).

texture Texture;

sampler2D TextureSampler = sampler_state
{
	texture = <Texture>;
	minfilter = point;
	magfilter = point;
	mipfilter = point;
};

// precalculated weights and offsets
float weights[15] =
{
	0.1061154, 0.1028506, 0.1028506, 0.09364651, 0.09364651,
	0.0801001, 0.0801001, 0.06436224, 0.06436224, 0.04858317,
	0.04858317, 0.03445063, 0.03445063, 0.02294906, 0.02294906
};

float offsets[15] =
{
	0, 0.00125, -0.00125, 0.002916667, -0.002916667,
	0.004583334, -0.004583334,0.00625, -0.00625, 0.007916667,
	-0.007916667, 0.009583334, -0.009583334, 0.01125, -0.01125
};


float4 BlurHorizontal(float4 position : POSITION0, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : Color0
{
	float4 output = float4(0, 0, 0, 1);

	for (int i = 0; i < 15; i++)
	{
		output += tex2D(TextureSampler, texCoord + float2(offsets[i], 0)) * weights[i];
	}

	return output;
}


float4 BlurVertical(float4 position : POSITION0, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : Color0
{
	float4 output = float4(0, 0, 0, 1);

	for (int i = 0; i < 15; i++)
	{
		output += tex2D(TextureSampler, texCoord + float2(0, offsets[i])) * weights[i];
	}

	return output;
}


technique Blur
{
	pass Horizontal
	{
#if SM4	
		PixelShader = compile ps_4_0 BlurHorizontal();
#else
		PixelShader = compile ps_3_0 BlurHorizontal();
#endif
	}

	pass Vertical
	{
#if SM4	
		PixelShader = compile ps_4_0 BlurVertical();
#else
		PixelShader = compile ps_3_0 BlurVertical();
#endif
	}
}

Here's my draw code... note, _shadowMap has already been created (with the models already rendered to it), and it works perfectly without VSM. This code was added and uses _shadowMap as the source to blur it per VSM:

    // blur shadow
    var blurEffect = GaussianBlurEffect;
    blurEffect.CurrentTechnique = blurEffect.Techniques["Blur"];

    GraphicsDevice.SetRenderTarget(_blurMap);
    GraphicsDevice.Clear(Color.White);

    // horizontal
    SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
    blurEffect.CurrentTechnique.Passes[0].Apply();
    SpriteBatch.Draw(_shadowMap, Vector2.Zero, Color.White);
    SpriteBatch.End();

    GraphicsDevice.SetRenderTarget(_shadowMap);
    GraphicsDevice.Clear(Color.White);

    // vertical
    SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
    blurEffect.CurrentTechnique.Passes[1].Apply();
    SpriteBatch.Draw(_blurMap, Vector2.Zero, Color.White);
    SpriteBatch.End();

    GraphicsDevice.SetRenderTarget(null);
    GraphicsDevice.BlendState = BlendState.Opaque;
    GraphicsDevice.DepthStencilState = DepthStencilState.Default;

Anyone have any ideas as to why this isn't working? The final shadowmap ends up black...

Thanks!

Posts: 1

Participants: 1

Read full topic

[Code Sample] - Sharing screenshots in game to Social Media (iOS and Android).

$
0
0

@rtroe wrote:

I've got another code sample/tutorial here for you all.

This one is for sharing a screenshot from in game to social media. Its implemented in our latest game Space Esc8bit to share scores to twitter or facebook. It works on both iOS and Android and can share it to whatever sharing apps you have on your mobile (iMessage, Twitter, SnapChat, Facebook etc...).

It's pretty small bit of code, but I hope this helps! I'm going to continue sharing bits of code like this, so if you like it give Virtex Edges blog a follow or follow us on twitter and I'll try to post more things like this!

-RT

Posts: 1

Participants: 1

Read full topic

UWP Page in Monogame App, hides content behind the AppBar

$
0
0

@hypodyne wrote:

I have a UWP page in a MonoGame app. The contents of which go behind the appBar. I would like to restrict it to the Red Rectangle.
The page has no MonoGame related content in it. I created a normal UWP application and it does not have this behavior.

Thing.png

Even on the games main page I don't want this behavior. Is there a way to prevent it.

Posts: 1

Participants: 1

Read full topic

Help with my match3 game

$
0
0

@Konstantin_Mads_Y wrote:

Hello from Russia, friends!
A can't understand how i can realized
algorithm to find neighboring pieces and replacing them for another pieces

this example very simillar
But i dont understand anything
Here my code

using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace match3_game_test1
{ {GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

    Vector2 Centerposition = Vector2.Zero;

    Texture2D gridTexture;
    Texture2D boxTexture0;
    Texture2D boxTexture1;
    Texture2D boxTexture2;
    Texture2D boxTexture3;
    Texture2D boxTexture4;
    Texture2D boxTexture5;
    
    List<Box> piecesList;
    List<Box> backgroundbox;
    

    int tlsizeX = 50;
    int tlsizeY = 50;
    
    int[,] map = new int[,]{ {0,0,1,1,1,1,0,0},{0,1,1,1,1,1,1,0},{1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1},{0,1,1,1,1,1,1,0},{0,0,1,1,1,1,0,0}};

    #region //WINDOW RESOLUTION
    int screenWidth = 612;
    int screenHeight = 612;
    
    #endregion
    #region Private variables
    private MouseState _previousMouse, _currentMouse;
    private SpriteBatch _spriteBatch;
    private List<Tile> _tiles = new List<Tile>();
    private Random _rnd = new Random();
    private Box _currentlyDraggedTile, _tileUnderMouse;
    private Vector2 _startingPositionForCurrentlyDraggedTile, _currentMousePosition;
    private SpriteFont _bigFont;
    #endregion


    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";


    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here
        graphics.PreferredBackBufferWidth = screenWidth;
        graphics.PreferredBackBufferHeight = screenHeight;
        graphics.ApplyChanges();
        
        
        IsMouseVisible = true;
        
        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
     
        gridTexture = Content.Load<Texture2D>("maps");
        boxTexture0 = Content.Load<Texture2D>("cude");
        boxTexture1 = Content.Load<Texture2D>("round");
        boxTexture2 = Content.Load<Texture2D>("triangle");
        boxTexture3 = Content.Load<Texture2D>("cude_purple");
        boxTexture4 = Content.Load<Texture2D>("round_purple");
        boxTexture5 = Content.Load<Texture2D>("triangle_purple");
     
        _spriteBatch = new SpriteBatch(GraphicsDevice);
        _bigFont = Content.Load<SpriteFont>("BigFont");

    Backgroundtiles();
     CreateTileswithTextures();
      


    }
 

 
    public void CreateTileswithTextures()
    {
        
        Random rnd = new Random();
        
        string[] texturelist;
        texturelist = new string[] { "triangle_purple", "round_purple", "triangle", "cude_purple", "round", "cude"};

        
        piecesList = new List<Box>();
       

        int x = 0;
        int y = 0;
        for (int i = 0; i < map.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(1); j++)
            {
                Vector2 topRightCorner = new Vector2(103,103);
                Texture2D texture = Content.Load<Texture2D>(texturelist[rnd.Next(texturelist.GetLength(0))]);
                Vector2 pos = new Vector2(x , y) + topRightCorner ;
                int a = map[i, j];
                if (a == 1)
                {
                    Box piece = new Box { Texture = texture, Position = pos };
                    piecesList.Add(piece);
                }

                x += tlsizeX;
            }
            x = 0;
            y += tlsizeY;
        }


       
    }
    void Backgroundtiles() 
    {
        backgroundbox = new List<Box>();
    
        int x = 0;
        int y = 0;
        for (int i = 0; i < map.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(1); j++)
            {
                Vector2 topRightCorner = new Vector2(103, 103);
                Vector2 pos = new Vector2(x, y) + topRightCorner;
               
                int a = map[i, j];
                if (a == 1)
                {
                    Box bpiece = new Box { Texture = gridTexture, Position = pos };
                    backgroundbox.Add(bpiece);
                }
                x += tlsizeX;

            }
            x = 0;
            y += tlsizeY;
        }


    
    }


   
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            Exit();
        // TODO: Add your update logic here

        UpdateMouseStates();
        CheckForTileRelease();
        CheckForNewDrag();
        UpdateDraggedTilePosition();
    }

    private void CheckForTileRelease()
    {
        if (_currentMouse.LeftButton == ButtonState.Released)
        {
            if (_currentlyDraggedTile != null)
            {

                if (_tileUnderMouse != null)
                {
                    _currentlyDraggedTile.Position = _tileUnderMouse.Position;
                    _tileUnderMouse.Position = _startingPositionForCurrentlyDraggedTile;
                }
                else
                {
                    _currentlyDraggedTile.Position = _startingPositionForCurrentlyDraggedTile;
                }
            }
            _currentlyDraggedTile = null;
        }
    }
    private void CheckForNewDrag()
    {
        if (_previousMouse.LeftButton == ButtonState.Released && _currentMouse.LeftButton == ButtonState.Pressed)
        {
            _currentlyDraggedTile = GetTileUnderMouse();
            if (_currentlyDraggedTile != null)
            {
                _startingPositionForCurrentlyDraggedTile = _currentlyDraggedTile.Position;
            }
        }
    }
 
    private Box GetTileUnderMouse()
    {
        return piecesList.FirstOrDefault(piece =>
            piece.GetBounds().Contains((int)_currentMousePosition.X, (int)_currentMousePosition.Y)
            && piece != _currentlyDraggedTile);
    }
    private void UpdateDraggedTilePosition()
    {
        if (_currentlyDraggedTile != null)
        {
            _currentlyDraggedTile.Position = _currentMousePosition - Vector2.One * _currentlyDraggedTile.Texture.Width / 2;
        }
    }
    private void UpdateMouseStates()
    {
        _previousMouse = _currentMouse;
        _currentMouse = Mouse.GetState();
        _currentMousePosition = new Vector2(_currentMouse.X, _currentMouse.Y);
        _tileUnderMouse = GetTileUnderMouse();
    }


    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.DarkViolet);

        // TODO: Add your drawing code here
        spriteBatch.Begin();

        DrawText();

        DrawbackgroundTiles();

        DrawPiecesAndSelection();

        spriteBatch.End();
       
      
        base.Draw(gameTime);
    }

    private void DrawbackgroundTiles()
    {
        foreach (Box bpiece in backgroundbox)
        {
            MouseState mouseState = Mouse.GetState();
            if (bpiece.Bounds.Contains(mouseState.Position))
            {

                // TODO: Code to handle node being clicked...
                Texture2D select = Content.Load<Texture2D>("select");
                Rectangle rect = bpiece.Bounds;
                spriteBatch.Draw(select, rect, Color.WhiteSmoke);
            }

            bpiece.Draw(spriteBatch);
        }

    }
    private void DrawPiecesAndSelection()
    {

       
        foreach (Box piece in piecesList)
        {



            piece.Draw(spriteBatch);


        }
    }

    
    private void DrawText()
    {
        spriteBatch.DrawString(_bigFont, "Developer MaDcat413", new Vector2(50, 10), Color.White);
        
    }
     
    }
}

Posts: 2

Participants: 2

Read full topic

DesktopGL Graphics Device Information and Set Adapter

$
0
0

@Kimimaru wrote:

  1. DesktopGL projects are missing a lot of properties and methods that Windows projects have for GraphicsAdapter, including DeviceId and DeviceName. Is there a reason this information isn't available? I'd think that DirectX and OpenGL have the means of obtaining this information. Furthermore, the GraphicsCapabilities class is internal and thus not exposed, and I think it would be great to have this information to adjust your game based on the capabilities of the device.
  2. I have both Intel HD Graphics and a discrete GPU. No matter what UseDriverType I set, I can't get MonoGame to use my Intel HD Graphics. Am I missing something?

Thanks a lot in advance!

Posts: 2

Participants: 2

Read full topic

New Updates


Setting effect on model mesh causes Exception

$
0
0

@Optmisitic_Peach wrote:

I made terrain using vertices, normals and colour, and it looks just fine. I'm trying to make this a bit more universal; I'm trying to turn these vertices and indices into a model for easier drawing later. Here is my function to make a model:

    public static Model toModel(VertexBuffer vb, IndexBuffer ib, Effect effect, GraphicsDevice gd)
    {
        ModelMeshPart meshPart = new ModelMeshPart();
        meshPart.IndexBuffer = ib;
        meshPart.Effect = effect;
        meshPart.NumVertices = vb.VertexCount;
        meshPart.PrimitiveCount = vb.VertexCount / 3;
        meshPart.StartIndex = 0;
        meshPart.VertexBuffer = vb;
        meshPart.VertexOffset = 0;

        ModelMesh modelMesh = new ModelMesh(gd, new ModelMeshPart[] { meshPart }.ToList());

        Model returnval = new Model(gd, new List<ModelBone>(), new ModelMesh[] { modelMesh }.ToList());

        return returnval;
    }

And the call to it:

Tiles[x, y].TerrainModel = Utils.toModel(vertexBuffer, indexBuffer, new BasicEffect(this.GraphicsDevice), this.GraphicsDevice);

I don't actually create a new effect for each one, I use a static one for all of my terrain models that I generate. I get an exception when I try to set meshPart.Effect saying (In exact words...) "System.NullReferenceException: 'Object reference not set to an instance of an object.'". The static effect is initialized like so: = new BasicEffect(this.GraphicsDevice) and in the debugger, the effect is set afterwards and null beforehand. Also, my function isn't receiving null either.

Posts: 4

Participants: 2

Read full topic

DesktopGL - Linux Errors

$
0
0

@Kimimaru wrote:

I'm deploying a DesktopGL project built in Windows to Linux with MonoKickstart, and I'm running into a couple of problems. I want to start by mentioning that I'm running Ubuntu on a VM, but the same errors occurred on hardware running Ubuntu when I had someone else test.

  • SDL 2.0.4 does not support changing resizable parameter of the window after it's already been created, please use a newer version of it.

This occurs because I allow window resizing in the Game constructor. MonoGame's fork of MonoKickstart hasn't been updated to the latest binaries; how would I go about updating the Linux ones?

If I comment out the window resizing line, I get a different error.

  • Failed to create graphics device!
    Microsoft.Xna.Framework.GraphicsDeviceManager.CreateDevice () [0x00000] in :0
    atMicrosoft.Xna.Framework.GraphicsDeviceManager.Microsoft.Xna.Framework.IGraphicsDeviceManager.CreateDevice () [0x00000] in :0 at Microsoft.Xna.Framework.Game.DoInitialize () [0x00000] in :0 at Microsoft.Xna.Framework.Game.Run (GameRunBehavior runBehavior) [0x00000] in :0 at Microsoft.Xna.Framework.Game.Run () [0x00000] in :0

To clarify, these both occur when the game runs and gets into my code. I've consistently had issues getting Linux builds to run, so I'm unsure what I need to do to fix things. You can see my Game1 class (called Engine.cs in my engine) here:

All help is greatly appreciated in advance!

Posts: 2

Participants: 2

Read full topic

MonoGame Pipeline - Linux Deepin

$
0
0

@TheAstroKnight wrote:

Hello community,

I have installed MonoGame today, and I started to follow a tutorial series. For the tutorial, you need to use the Pipeline, but there's a problem with it. Whenever I start it from the start menu, it doesn't do anything. Then I tried executing monogame-pipeline-tool in the terminal, which threw me the following error:
Unhandled Exception:
System.TypeLoadException: Could not load type 'MonoGame.Tools.Pipeline.Styles' from assembly 'Pipeline, Version=3.6.0.1625, Culture=neutral, PublicKeyToken=null'.

Any help?
- TheAstroKnight

Posts: 1

Participants: 1

Read full topic

Different errors

$
0
0

@TheAstroKnight wrote:

Hello community,

I'm following a tutorial series on youtube. I have got the following two errors:
Error: } expected, on this line: public Type Type = { private set; get; }.
I also have this error:
Error: A namespace cannot directly contain members such as fields or methods for this function:

public T Load(string path) {
	T instance;
       	using (TextReader reader = new StreamReader(path)) {
		XmlSerializer xml = new XmlSerializer(type);
		instance = (T)xml.Deserialize(reader);
	}
	return instance;
}

I'm using these namespaces:

using System;
using System.Collections.Generic; <-- Unnecessary, according to MonoDevelop
using System.Linq; <-- Unnecessary, according to MonoDevelop
using System.Text; <-- Unnecessary, according to MonoDevelop

using System.Xml.Serialization;
using System.IO;

If you need any extra information, tell me.

Posts: 10

Participants: 4

Read full topic

Accuracy of game.TargetElapsedTime on laptops (affects Beam Racing)

$
0
0

@Mark_Rejhon wrote:

(Founder of Blur Busters here)

Short Question:

How do I make TargetTimeElapsed microsecond-accurate as possible?
...Making the next Update()/Draw() cycle called right exactly on time, not too early, not too late, better-than-millisecond granularity.

Long Form Explanation:

I have a special beam-racing application that I created in MonoGame (see YouTube of mouse arrow dragging the exact position of a VSYNC OFF tearline) -- and I'm trying to create the world's first cross-platform beam racing demo for Blur Busters using the MonoGame engine.

On the PC, the game.TargetElapsedTime is very microsecond accurate. Once I set it, the next Update/Draw cycles are called right on the dot, almost to the exact microsecond. Fantastic. Beam racing success.

...Look at that! Mouse dragging the exact position of a VSYNC OFF tearline! Old skool beam racing... (using 100% pure MonoGame APIs to simulate raster interrupts, with no raster register -- just precision clock math as an offset from VSYNC timestamps).

MonoGame retweeted this recently, see https://twitter.com/BlurBusters/status/975646569528811520

However, on my laptop, game.TargetElapsedTime is only millisecond accurate. If I do huge hacks and directly Present() / Flush() on QueryPerformanceCounter(), it works. But I'd rather MonoGame do an optional ultra precision microsecond-accurate frame pacing mode (even at more battery consumption) -- where TargetElapsedTime precisely schedules the next Update/Draw to within approximately a 10-microsecond accuracy like I can do via other laptop hacks (direct polls of QueryPerformanceCounter() instead) -- that's not very MonoGamey.

How can I make MonoGame trigger the next Update() call to better-than-millisecond granularity? I need to do this for beam-racing on more platforms (laptops, Linux, Mac with beamsync OFF / VSYNC OFF, etc).

This is some current research work towards lagless VSYNC ON modes being added to some emulators recently (synchronizing emulator rasters to real-world raster -- now successfully implemented in WinUAE and GroovyMAME)

Help?

Thanks so much,
Mark Rejhon
Founder, Blur Busters

Posts: 1

Participants: 1

Read full topic

Viewing all 6821 articles
Browse latest View live