xna – My position changes when dealing with animations

I'm trying to learn Monogames (Old XNA) and how to develop a 2d game.

I'm about to animate my sprites. It works, but there are things that seem strange to me.

For some reason, animating my sprites will "change" the animating position WITHOUT changing the origin. How so


If I have not changed my origin, my character "shifts" his body upwards. Something he should not do.

If I change the origin to the width and height of my frame, this does not happen. How so


It can be seen that the rectangle is still changing, but my character does NOT shift in its position. I can not really understand why he changes and does not change.

The origin is located in the upper left corner of the rectangle.

Why is my character position shifting? I think it's about compensating with the different heights of the frames. I'm not sure. I do not understand how to work with offset.

xna – How can I create a Metroid-like transition between two maps with Monogame Extended?

I want to make a transition like in the Metroid games. I use Monogame Extended and I have two TiledMaps. My idea was to place them right next to each other where the transition takes place, so I only have to move the camera from one card to the next. My problem now is that I have no idea how to put them next to each other. I thought they were in a coordinate system so I could move them, but I can not find a way to do that. Now I even wonder if this is actually the way to do it.

xna content pipeline – Load / Generate new resources when starting in MonoGame

I have a resource loading question at the beginning of my MonoGame game. I have several sprite sheets that I load at the beginning of the game. It takes about 5-10 seconds on my computer, but I have some reports that take up to a minute on other computers … that's far too long.
The reason is not loading the Texture2Ds, but writing new RenderTargets on startup. I have some colored sprite sheets where I generate a black and white version at startup. That costs time.

Now to my question: I was trying to do this later in the game so the game starts faster and I tried to start the color> black and white operation when the player made a new game – that would be a perfect one Situation to do it. However, I have always received two types of errors:

1st operation was not called for UI thread


2. Present can not be called if a render target is active

As you may have guessed, I'm doing the load operation in a separate thread so the UI will not freeze. The real problem, however, seems to be that I can not execute RenderTarget operations when I'm already doing Begin and End SpriteBatch operations.

How can I solve the problem?

Would be happy about any suggestion.


XNA: Classes with Texture2D to be treated as one

Summarized problem:
I have an "animation" class that I can treat as a Texture2D field as needed. I do not want to inherit from the class or their parents. I'd rather not create a parent class of both the animation class and a "container" for a Texture2D, though this is the only way to accomplish what I want.

Context: https://pastebin.com/PTgJuYEU
It's an extremely simple class that can change. His goal is to use a Texture2D for the external processing of spreadsheets and so on. It is used in an ECS, but probably not as a component as I have it now.

For example, I would like to use it as a character for a Texture2D in Draw calls (this can be done with the & # 39; texture & #;; property) and also be kept in the same field and converted to it Treat it again as an animation class , (If anyone thinks there is a much better implementation, please let me know.)

Thank you in advance.

EDIT: If there is a way, I could make something perfect:
spriteBatch.Draw (Anim as Texture2D, Vector2.Zero, Color.White);

xna – Simplify Mathecode for Matrix – Sun Billboarding

When trying to set the correct position of my Sun billboard in my 3D game. I tried a long time to get it working right, but I wonder why this code has to be so complicated:

sun.sprite.Position = Vector3.Transform (Vector3.Transform (-sun.lightDir,
Quaternion.Inverse (world.Rotation)), Quaternion.Inverse (myRelativeRotation));

Can I simplify this expression? At least I tried to change it:

sun.sprite.Position = Vector3.Transform (-sun.lightDir,
Quaternion.Inverse (world.Rotation) * Quaternion.Inverse (myRelativeRotation)) 

However, this leads to different results, so that the sun is in the wrong place.

c # – XNA 4.0 To combine triangular vertices in 3D

Preview for the problem:

I'm doing a similar game to Minecraft (a game where the world is made up of dice), but the fps of the game are getting low only by rendering a small number of dice in the world.

So I decided to use the Combine / Margin technique to improve it. I want to combine cubes that are of the same type and whose positions are next to each other.

Suppose I have 4 faces of cubes juxtaposed in this order:

[+] [+]

[+] [+]

Right now: I rendered each face with 2 triangles so that I render all faces with 8 triangles.

Improvement that I would like to make: I want to render these surfaces with only two triangles, but keep the textures where they are. This means that you only use 2 tringles for 2 faces and 4 for this area.

Outside the topic:

Currently I use:

  • Frustum wheezing
  • Cube faces that lie on top of each other are not rendered.

Which fps improvement techniques do you recommend to use?
At the moment I only make 1500 faces at the same time [3000 triangles] My game reaches about 25 ~ fps.

xna – Trying to get vertex shaders to work with Monogame 2D

If I do not use the vertex shader, white textures appear. This is the default color. After adding the vertex shader, the screen is black.

I think there is something wrong with the matrices I give to the shader, but I'm not sure.

                #if OPENGL
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1

Matrix WorldViewProjection;

struct VertexShaderInput
float4 position: SV_POSITION;
float4 color: COLOR0;
float2 texCoord: TEXCOORD0;

struct VertexShaderOutput
float4 position: SV_POSITION;
float4 color: COLOR0;
float2 texCoord: TEXCOORD0;

VertexShaderOutput MainVS (in the input "VertexShaderInput")
VertexShaderOutput output = (VertexShaderOutput) 0;

output.Position = mul (input.Position, WorldViewProjection);
output.Color = input.Color;

Return the output;

float4 MainPS (input VertexShaderOutput): COLOR
Return input. Color;

Technique BasicColorDrawing
Pass P0
VertexShader = Compile VS_SHADERMODEL MainVS ();
PixelShader = PS_SHADERMODEL Compile MainPS ();

My projection matrix (The default that uses sprite batch).

Projection = Matrix.CreateTranslation (-0.5f, -0.5f, 0) * Matrix.CreateOrthographicOffCenter (0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, -1)

Setting my WorldViewProjection matrix.

negEffect.Parameters["WorldViewProjection"].SetValue (projection);

Just the projection because I turned off my camera to make debugging easier.

The drawing code.

GraphicsDevice.SetRenderTarget (renderTarget);
GraphicsDevice.Clear (Color.Black);
var debugMatrix = debugCamera.GetViewMatrix ();

spriteBatch.Begin (SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, negEffect);

spaceObjectManager.Draw (spriteBatch);
spaceEnemyManager.Draw (spriteBatch);
playerShip.projectileManager.Draw (spriteBatch);
playerShip.Draw (spriteBatch);

spriteBatch.End ();

GraphicsDevice.SetRenderTarget (null);

spriteBatch.Begin (SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null);
spriteBatch.Draw (renderTarget, new Rectangle (0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.End ();

physicsDebug.RenderDebugData (ref SimProjection, ref debugMatrix);

VertexShader off.

VertexShader off

VertexShader on.

VertexShader on

Thank you in advance!

XNA – How do I scale sizes and speeds for a minimap?

I'm rebuilding the arcade game StarGate and need to create a mini map. However, I have problems scaling the minimap textures to fit into the radar box and making sure that the speed of scrolling is proportional to the main map and the mini map.

My textures are the size below:

  1. Complete page with scrolling: 4800 x 620
  2. Screen size 960×720

StarGate screenshot below:
Enter the image description here

xna – understand the semantics of the quaternion class

I'm having trouble understanding the semantics of some members of the Quaternion class. The documents are not helpful, and tutorials that try to explain quaternions use a lot of math, which is not helpful to me because I just do not have a proper background for it.

My main questions are currently:

Is there a difference between Multiply and Concatenate?

What is the exact difference between Inverse and Negate?

xna – MonoGame project can not be deployed for BlueStack (ADB0000: closed)

I'm using MonoGame 3.6 with the Visual Studio 2017 community and trying to deploy as an Android emulator on BlueStack. VS can see Bluestack and allow "deploy" to start, but ends with this error:

Severity Code Description Error in the status file of the project file line
ADB0000: Deployment failed. Mono.AndroidTools.AdbException: closed
Mono.AndroidTools.Util.AggregateAsyncResult.CheckError (CancellationToken
token) in
E: A_work 293 s External androidtools Mono.AndroidTools Util AggregateAsyncResult.cs: line
72 at
Mono.AndroidTools.Adb.AdbClient.EndWriteCommandWithStatus (IAsyncResult
asyncResult) in
E: A_work 293 s External androidtools Mono.AndroidTools Adb AdbClient.cs: line
328 at
System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic (IAsyncResult
iar, Func2 endFunction, Action1 endAction, Promise of Task1, Boolean
requiredSynchronization) 0

I can also deploy the same project to other emulators like Google One or Genycom. The problem is with BlueStack

any idea? Many Thanks