MonoGame | open source implementation of the Microsoft XNA | Game Engine library
kandi X-RAY | MonoGame Summary
kandi X-RAY | MonoGame Summary
MonoGame is an open source implementation of the Microsoft XNA 4.x Framework. Our goal is to make it easy for XNA developers to create cross-platform games with extremely high code reuse.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of MonoGame
MonoGame Key Features
MonoGame Examples and Code Snippets
Community Discussions
Trending Discussions on MonoGame
QUESTION
I have been trying for a while to get this fixed but I haven't seen any solutions online on this topic yet.
The problem is when using MonoGame with the Platform DesktopGL, the Window.Handle seems invalid. As attempting to get a Window/Form from this Handle returns null, further supporting this would be BASS.Net Not being able to play audio on this Window Handle,
Here's part of my code that's attempting to use the Handle (Uses Bass.Net for Audio Playback):
...ANSWER
Answered 2021-Jun-02 at 01:47"Window.Handle" is only valid on WindowsDX platform.
OpenGL, no matter the platform(including Windows), can satisfy this request.
If you are looking for a cross platform solution, look elsewhere.
QUESTION
This is my shader for 2d polygons. For some reason, even though the vertex shader is running through all the walls, the compiler still treats this as an unused variable and will optimize it away, meaning that when I try to actually set the parameter from monogame, the parameter is null and there doesn't set. I don't understand why the shader thinks the 'walls' variable is not being used when it clearly is.
...ANSWER
Answered 2021-May-05 at 02:25Was able to get rid of the compiler optimizing by adding an [unroll] before the loop which allowed the setting of the walls variable and subsequent parsing of the array in the vertex shader.
QUESTION
I have been making a physics simulation of a ball for the past couple of days with MonoGame and C#. The ball bounces with gravity fine, but when the bouncing of the ball gets too low, the ball just goes into the floor. Is there any way I can stop this from happening? I have already tried lowering the gravity constant, changing how the collision works, etc. but nothing seems to work. (I am fairly new to working with graphics so a simple explanation would be most helpful)
...ANSWER
Answered 2021-Apr-12 at 04:01This is one of those classic problems with collision detection, where the collision occurs at some point along the object's path but the object moves far enough that the next tick doesn't fix the problem, leaving the object - your ball in this case - to fall forever outside of the viewport.
To solve this you need to not only change the vertical velocity but also have the ball reflect off the collision point. You're already bouncing the velocity vector, you just need to add position reflection. The simple way is to just take the amount of overshoot and subtract it from the limit, putting the ball back in bounds:
QUESTION
I've been working on a C# MonoGame project for a few days now and so far it has been building and running fine. I left it alone for a while and, when I came back, the window would no longer display (running as a console application displays a blank console window, but not the application itself).
I don't think it's due to the code itself because the issue started happening without any changes to it.
When building, the program exits with code -1, as shown below in the output:
...ANSWER
Answered 2021-Apr-11 at 09:30Looks like I've solved it myself - I simply needed to update Visual Studio to the latest version, which I was apparently not using. Once I did that, all programs worked again.
QUESTION
I'm using command dotnet build
in order to build a game in the MonoGame framework in Ubuntu 20.04 using .NET 5.0
.
It was fine in Windows, but now that I'm using it here, it gives me this error:
error CS1069: The type name 'PrivateFontCollection' could not be found in the namespace 'System.Drawing.Text'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. [/home/mrwoto/Ali/Programming/csharp/SAO/SAO/SAO.csproj]
So, is there anyway to resolve it? How can I add a reference to it in .csproj
file?
ANSWER
Answered 2021-Apr-06 at 06:42One option is to add it from the terminal with
QUESTION
I'm wanting to have a "news" tab in a game that would just pull and display tweets from a twitter account. Is this possible in monogame? Should I use the Twitter API?
...ANSWER
Answered 2021-Mar-12 at 10:18I'm wanting to have a "news" tab in a game that would just pull and display tweets from a twitter account. Is this possible in monogame?
It is possible in .NET as long as you have an internet connection and use the correct API. Monogame being a game framework is just another dependency of your .NET application.
Should I use the Twitter API?
Yes, I would recommend using the Twitter REST API for the same. You can get the text data (in JSON) of the content you need.
The hard part would be to render the tweets in Monogame. You cannot render HTML or run javascript inside Monogame, so you will have to implement your own UI for "Twitter News Feed" from scratch for displaying the tweets.
QUESTION
I'm currently programming my own 2d engine with monogame and can't get any further because I want to create a list of sprite pointers. My idea is that every time a sprite is initialized it is added to the list and when the draw function is called, every sprite in the list is rendered with a foreach loop. The problem is if I change the properties of the sprite, like position or color, then I have to refresh the list, and that's not the best way. My new idea is to make a list of pointers that point to the respective sprites.So that when you render you have access to the variable and not to a reference.Or maybe there is also a list object that does the work for me? Thanks in advance!
...ANSWER
Answered 2021-Mar-12 at 10:02My idea is that every time a sprite is initialized it is added to the list and when the draw function is called, every sprite in the list is rendered with a foreach loop.
The need for having common objects that need to be updated and drawn along with the Game
object is very frequent. You can have multiple approaches for implementing it. Monogame even has it's own implementation of it using the abstract class GameComponents
and I have mentioned it in the end.
The problem is if I change the properties of the sprite, like position or color, then I have to refresh the list, and that's not the best way.
I believe this problem is due to the fact that the objects in your list are value types and not reference types (equivalent to pointers in C#). In this case, you have the following approaches to try:
- Instead of using the generic type
List
, use aLinkedList
inSystem.Collections.Generic
, and you should use it as follows:
QUESTION
Im trying to write some simple 2d physics in monogame. I release a ball from a given start position with a given velocity and I want it to bounce back up when it is colliding with the floor.
My problem is that I seem to give the ball more energi for each bounce i.e. it bounces higher and higher for each collision with the floor. It should be the other way around.
I have:
...ANSWER
Answered 2021-Mar-11 at 09:33I went through your logic and have prepared a sample code. Please read the following before you go through it.
In order to simulate real-life motion, you need to implement the physics accurately. Although your implemented velocity and position seems mostly correct, the gravity needs to be treated as acceleration, and therefore adding its value to the position (as done in your code) is incorrect. I assume that this is the reason why you aren't getting your expected result since the value of increment on the Y-component of position is far greater than it should be.
Instead of keeping
PosX
,PosY
for the position,Velocity_X..()
,Velocity_Y..()
for velocity, I would advise you to usestruct Vector2
as shown below in my code, which is included in the Monogame framework and has a lot more helping functions built-in. This will help in making your code shorter and cleaner.I did not understand why you used the Cosine of the given angle in your implementation of Velocity for both its X and Y components. My code below is ignoring this.
You can see my code below. Here the bouncing object Box
is of the type struct PhyObj
with all the needed Physics of motion implemented within it.
QUESTION
My Android app fails to install on some “random”, older API devices (anything less than API level 25) with the error:
...ANSWER
Answered 2021-Feb-27 at 05:46Solved and posted the answer here:
https://community.monogame.net/t/install-parse-failed-manifest-malformed-only-on-some-devices
In short the answer is:
On older api versions (<25 and therefore you should ALWAYS do this to support them?) it seems Android requires that:
the fully qualified Namespace of the Activity Name property must be lowercase.
QUESTION
I want to procedurally generate a texture2D
by pasting smaller textures as tiles, I've done similar things in Python and MatLab, but do not know how to do that in MonoGame.
This question is similar to what I need to do, but it generates the texture in the Draw()
method, which in my case could be a performance hit.
Like this question, I want to have something that generates the texture and returns it, so I can initialize it as a field instead of re-generating the texture again every time in Draw()
.
But I do not know how to edit a texture2D
, the SetData()
method for Texture2D
is rather confusing, the new data is of type T[]
, how do I pass in another Texture2D
as T[]
? And what are the Int32
parameters doing?
ANSWER
Answered 2021-Feb-24 at 02:38The T
parameter is a convenience in which say, you may pass raw bytes instead of colors.
In short, just stick to Color[]
for T[]
, the framework will handle all the details such as computing the stride/pitch and so on when using raw bytes.
In your case you could just do the following:
- use
GetData
to get colors from source tile - use
SetData
to set a region rectangle the size of source tile in the target texture
To initalize it outside Draw
, I suppose LoadContent
could be a good place since GraphicsDevice
should be not be null at this point.
And if somehow you have to do it in Draw
, use a simple bool NeedsRefresh
as a guard, check if it's true, if yes then generate your stuff and set it to false; the code block would run only once.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install MonoGame
Download the current stable release from our website.
Download the latest "unstable" installer from our build server.
Download the latest source code.
Fork and clone the repo: https://github.com/mono/MonoGame.git.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page