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

Custom BlendState: How do Color- and AlphaBlend mix?

$
0
0

@The_Dude wrote:

So, I am playing around with Custom BlendStates.

Color Blending makes sense to me, but Alpha Blending confuses me. I don't understand how Color- and AlphaBlend work together in a custom BlendState.

Imagine the following scenario for example. You have a renderTarget (1,1,1,1) and want to cutout an opaque shape, so the affected area gets transparent. Then draw the renderTarget on top of the world.

It is a specific case but crucial for understanding how that stuff works. So please stick with this example and explain me what is happening. Thank you!

So, I first thought of this custom BlendState:

 BlendState bmSubtract = new BlendState()
    {
    AlphaSourceBlend = Blend.SourceColor,
    AlphaDestinationBlend = Blend.One,
    AlphaBlendFunction = BlendFunction.ReverseSubtract
    };

( destCol x destBlend ) - ( srcCol x srcBlend )

Here already starts the confusion. What is calculated in the AlphaBlendFunction?
Is it the alpha only or also the color. And how is the color of the previous ColorBlendFunction used?
Is srcColor here only a alpha value or (1,1,1,1).

You will get this result if I have not messed up thing:

This is different what I have expected, it is the other way around. Why does it not subtract the white circle from the white destination and creates a circle cutout, so you can see the red game world behind it?

Now, the following BlendState is working the way I want it to. But I don't understand yet.

BlendState bmSubtract = new BlendState()
        {
            ColorSourceBlend = Blend.One,
            ColorDestinationBlend = Blend.One,
            ColorBlendFunction = BlendFunction.ReverseSubtract,

            AlphaSourceBlend = Blend.SourceColor,
            AlphaDestinationBlend = Blend.One,
            AlphaBlendFunction = BlendFunction.ReverseSubtract
        };

Posts: 3

Participants: 2

Read full topic


MonoGame Shader Series - Motion Blur

$
0
0

@rtroe wrote:

Hi All,

I've started a weekly shader series for implementing different post processor effects and model shaders in MonoGame.

The 2nd entry is Camera Motion Blur.

Let me know what you think of these, if I should have more of something or less of something. I'd love some feedback.

Thanks

-RT

Posts: 1

Participants: 1

Read full topic

BackgroundWorker :: GetData() Exception (Operation not called on UI thread.)

$
0
0

@Alias wrote:

Hi,

I'm trying to use BackgroundWorker to preproses my 2D png grapichs. I do this for runtime atlassing based upon GL.MAX_TEXTURE_SIZE and making Pixel coliders. This works on Windows but on Android the RunWorkerCompletedEventHandler() is fired premature because of the following exception.

System.InvalidOperationException: Operation not called on UI thread.
at Microsoft.Xna.Framework.Threading.EnsureUIThread () [0x00007] in <8335ffb25c73411d8c018e841c87a942>:0
at Microsoft.Xna.Framework.Graphics.Texture2D.PlatformGetData[T] (System.Int32 level, System.Int32 arraySlice, Microsoft.Xna.Framework.Rectangle rect, T[] data, System.Int32 startIndex, System.Int32 elementCount) [0x00000] in <8335ffb25c73411d8c018e841c87a942>:0
at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T] (System.Int32 level, System.Int32 arraySlice, System.Nullable
1[T] rect, T[] data, System.Int32 startIndex, System.Int32 elementCount) [0x00011] in <8335ffb25c73411d8c018e841c87a942>:0
at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T] (System.Int32 level, System.Nullable1[T] rect, T[] data, System.Int32 startIndex, System.Int32 elementCount) [0x00000] in <8335ffb25c73411d8c018e841c87a942>:0
at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T] (T[] data) [0x0000e] in <8335ffb25c73411d8c018e841c87a942>:0
...

Notice: Threading.EnsureUIThread, And It is NOT on the UI thread. Yet, LoadFromStream() does not trigger.! (So settings it seems fine, but getting it is a big no-no). Also Windows does mind me doing this. I have not tested Mac or IOS yet.

I'm not drawing or doing anything particular interesting when this happens. Basically I need a way to pre-process my PNG images on runtime. I can do this on the main (UI) thread, but then no cool progress indicator :disappointed:

I'm targeting: Windows, Windows Store, Android, Mac, IOS. System.Drawing - which was my first choice - is not supported everywhere, so i'm using. FromStream, GetData, SetData to play around with the pixels.

Anyone has any ideas on this..? Thanks!

EDIT: Both Mac and IOS give the same behavior. I'm assuming that its a OpenGL directive. So you cant use GetData, and probably not SetData on a separate thread on other targets then Windows or Windows Store.

Posts: 3

Participants: 2

Read full topic

Which method do you use for storing game data in external files?

$
0
0

@DefiniteGoose wrote:

Hello everyone,

I am working on a game that has a large variety of items, and all of these have different stats, such as sell price, etc. My question is, how would I create a system that depends on external files, is importable by the MonoGame Pipeline tool and allows me to change values throughout development without hardcoding them.

Keep in mind that I'm looking for a system that uses just one single class for an object rather than having a ton of different classes that serve the same purpose but have different stats.

I hope you cal help me! Thanks for reading through my topic.

Posts: 1

Participants: 1

Read full topic

How can I use Admob in a MonoGame iOS project?

$
0
0

@Fox9 wrote:

How can I add the Google Mobile Ads SDK to my MonoGame iOS project? I created a new iOS solution in Xamarin but I don't know how to add the SDK to my project.

Google Ads
I found this article but I don't know how to use CocoaPods. How can I add the SDK to my project without using CocoaPods?

I want to use Admob in my project so that I can show interstitial ads in my game.

edit: It works now, I added the Xamarin.Firebase.iOS.AbMob nuget package to my project.
nuget package

Posts: 1

Participants: 1

Read full topic

Anchor/Pivot points

$
0
0

@dryhfth wrote:

Hello!
I' m writing a small game demo, using Monogame.Extended libraries.
I wonder, if pivot data is exported from jsonMap, I was looking for export entries in source code, but couldn't find. :hushed:
For example: I have TextureAtlas & Map created via TexturePacker/SpriteSheetPacker, something like this:

{frames: [
{
    "filename": "Frame1.png",
    "frame": {"x":823,"y":612,"w":76,"h":97},
    "rotated": false,
    "trimmed": true,
    "spriteSourceSize": {"x:":3,"y":0,"w":76,"h":97},
    "sourceSize": {"w":80,"h":97},
    "pivot": {"x":0.523697,"y":0.345168}
},
{
    "filename": "Frame2.png",
    "frame": {"x":823,"y":711,"w":76,"h":96},
    "rotated": false,
    "trimmed": true,
    "spriteSourceSize": {"x:":3,"y":1,"w":76,"h":96},
    "sourceSize": {"w":80,"h":97},
    "pivot": {"x":0.603516,"y":0.411546}
}

//C#
tAtlas = Content.Load<TextureAtlas>(@"textureMap");
SpriteSheetAnimationFactory spaFactory = new SpriteSheetAnimationFactory(tAtlas);
spaFactory.Add("Idle", new SpriteSheetAnimationData(array(0-10), 0.2f));
spaFactory.Add("Attack1", new SpriteSheetAnimationData(array(11-20), 0.04f, false));
spaFactory.Add("Attack2", new SpriteSheetAnimationData(array(21-30), 0.04f, false));
animSprite= new AnimatedSprite(spaFactory, "Idle");

But actually it doesn't work (anchoring) :disappointed_relieved:. Seems like all data is imported except pivot data, which is essential to me, because I'm using SpriteSheet with different-sized frames.
Am I missing something or do I need to create separate wrapper or processor which will read this data??

To illustrate, what I mean: SpriteOrigin
Yellow border is frame size & red square is origin.
The best way it works, when I place origin in center-bottom position, not perfectly though. :neutral_face:

Will appreciate any advice :pensive:

Posts: 1

Participants: 1

Read full topic

MONOGAME ANDROID HYPER-V emulators not loading images

$
0
0

@Paul_Crawley wrote:

Ok, I've tried everything, install, uninstall, wipe drive try again, nothing solves this:

Hyper-V running.
Android Emulators from Microsoft running.
Visual Studio 2017 running.
Windows 10 Pro running.

make a simple android monogame project running.

do a->
texture=Content.Load("picture");
EXCEPTION, file ot found
yes to all your questions that include:-
how big is the file, is in the content manager, have you tried properties = android asset, have you tried properties content, have you tried jumping up and down? have you tried loading the emulator first, does it run everything else, what error are you getting "Java sig error can't find file", have you tried talking nicely?
If anyone can please make a system to the above spec and try it i'd love to see the code, basically it don't work!

I know it's something to do with emulator vs monogame cos it works fine on an actual device, did you guys piss off microsoft or something? anyway, monogame and Hyper-V android dont work, any suggestions?

Posts: 1

Participants: 1

Read full topic

state of sRGB?

$
0
0

@KakCAT wrote:

Hi,

I'd like to test my game renderer with a linear color space and I'd like to query about the state of sRGB in MonoGame.

Supposedly MonoGame already supports sRGB surfaces ( https://github.com/MonoGame/MonoGame/pull/3492 ) but the pipeline tool does not support specifying a sRGB (at least I wasn't able to find it) and you can't load a texture specifying you want an sRGB texture. Am I right?

So unless I'm missing something, the only way to use linear colorspace right now in monogame is just grabbing the texture gamma corrected and convert to linear in the shader ( pow(color, 2.2) ). And be sure to convert back to a gamma corrected value when writing to the screen.

Is this correct?

Posts: 1

Participants: 1

Read full topic


How to share data between threads/cores in a compute shader.

$
0
0

@Optmisitic_Peach wrote:

Hi there, I'm trying to implement a compute shader that acts as a sorting algorithm. I need to get lots of data passed between the cores/threads (I.E. no matter what instance of the function i'm running, I have access to the same data as the rest). I started using a system like so:

RWStructuredBuffer<uint> SharedGlobalParams : register(u0);
RWStructuredBuffer<uint> InWeights : register(u1);
RWStructuredBuffer<uint> OutIndexes : register(u2);
RWStructuredBuffer<bool> SyncSuccesses : register(u3);

This will prove hard as though I would have to initialize each one in c# with appropriate size (Correct me if I'm wrong here please). How would I achieve this? I've read about static and shared and groupshared but I'm not sure which one to use.

Here is the signature of my main function:

[numthreads(1, 1, 1)]
void CSMain(uint3 threadID : SV_DispatchThreadID);

Any help is appreciated!

Posts: 1

Participants: 1

Read full topic

AdMob rewarded video ads in MonoGame?

$
0
0

@Fox9 wrote:

How can I add rewarded video ads to a game(iOS and Android)?
I need a step by step tutorial for beginners.

Posts: 1

Participants: 1

Read full topic

Basic Volumetric Lighting (light shafts, god rays)

$
0
0

@Stephanowicz wrote:

Hi there!

Well after having a real hard time finding a SIMPLE example for casting light shafts I finally managed to port the Volumetric Lighting Tutorial by Nicolas Menzel to monogame.
His turorial is based on the GPUGems 3 article "Volumetric Light Scattering as a Post-Process" by Kenny Mitchell from EA
Surely there are lots of examples, but mostly in XNA4 or too complicated for me as a beginner.
The source by Nicolas isn't that simple, too, as there's lot of unused stuff - but I finally got it running!

So I put the project to gitHub and want to give a quick description, hoping that it may help others desperate like me finding a simple solution. :wink:

I've splitted the project into to parts - the uncleared original port, also containing all the unused original functions and a cleared, basic version with only the necessary stuff inside.
The original consisted of 2 projects I merged into one.
I'm using a different model, as I had problems with the original gears and the cube textures. I found a nice sphere with breakouts at cgtrader

I also added a controls-form for easily manipulating the light shaft parameters.


Project structure:

  • Game1.cs - the main game class
  • Controls... - the control form class
  • PostScreenEffects.cs - class for the post screen effect handling

As a raw order for generating a light shaft effect one could say:

  1. Generate several render targets for the different steps
  2. render the models with textures and other lighting (this step can be anywhere before steps 8,9)
  3. render an occlusion mask of the scene
  4. render the background texture containing the lightsource (the flare) and the occlusion mask to a new render target (blending)
  5. downscale the blended target from step 4 and apply a linear filter
  6. apply the lightshaft effect to this downscaled target
  7. upscale the result
  8. combine the targets (step 2 and step 7) to the final target
  9. draw the final target to screen

So far, for this moment… hope to add some more details next time!

Cheers,

Stephan

Posts: 1

Participants: 1

Read full topic

PMBS 1.0 Released

$
0
0

@Kimimaru wrote:

Hello everyone,

I've been working on PMBS, an open-source Paper Mario battle system, on and off for a couple of years now and just released a 1.0 version!

Features:
* Battle Menus
* Action Commands
* Items and Badges
* Dialogue System
* Move Sequences (what happens during the move)
* Status Effects

The battle can be configured via a config file and is described in more detail in the link.

While working on this, I learned more about not only two of my favorite games, but also MonoGame, and really enjoyed it. The battle system is extensible and supports all types of interactions, including some that the original games did not feature!

I started learning shaders and more about graphics in general for this project, and the community here has been really helpful. I'm not new to MonoGame, but I have never delved into its more advanced features and stuck with what I was familiar with. This project forced me to get out of my comfort zone and learn something new, and I really appreciate all the help!

Posts: 1

Participants: 1

Read full topic

Texture2D Maximum? (MAX_TEXTURE_SIZE)

$
0
0

@Alias wrote:

Hi,

I've created an runtime texture atlas for atlassing tilemaps and animations on runtime. Also I use this for texture sharing. (I push multiple tilesets and animations on one texture!) For Dx I can just use 16384 (Desktop, not ARM) and for GL I want to query MAX_TEXTURE_SIZE.

I have this working on Android:

int t;
GL.GetInteger(GetPName.MaxTextureSize, out t);

But I can't get it to work on Mac or IOS. I probably need a using directive to make it work.!? But I don't know which that would be.

Or is there perhaps an other - more generic MonoGame - way to determine the max size of a Texture2D?

Many thanks on any advice on this!

Posts: 1

Participants: 1

Read full topic

I really don't understand why does MonoGame not show - if I export fbx since MonoGame 3.7

$
0
0

@Jens_Eckervogt wrote:

Hello everyone,

I have tried to understand but why does it happen? box doesn't see in MonoGame.

I am sorry because I still learn more more.....

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace MonoCrraft
{
    /// <summary>
    /// This is the main type for your game.
    /// </summary>
    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Model model;
        BasicEffect effect;

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

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            model = Content.Load<Model>("box");
            effect = new BasicEffect(GraphicsDevice);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f);
            effect.View = Matrix.CreateLookAt(new Vector3(2, 3, 2), Vector3.Zero, Vector3.Up);
        }

        protected override void UnloadContent()
        {
            
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            base.Update(gameTime);
        }

        /**
         *  Model and matrix
         */
        private Matrix GetParentTransform(Model m, ModelBone mb)
        {
            return (mb == m.Root) ? mb.Transform : mb.Transform * GetParentTransform(m, mb.Parent);
        }

        private void DrawModel(Model m, Matrix world, BasicEffect be)
        {
            foreach(ModelMesh mm in model.Meshes)
            {
                foreach(ModelMeshPart mmp in mm.MeshParts)
                {
                    be.World = GetParentTransform(m, mm.ParentBone) * world;
                    GraphicsDevice.SetVertexBuffer(mmp.VertexBuffer, mmp.VertexOffset);
                    GraphicsDevice.Indices = mmp.IndexBuffer;
                    be.CurrentTechnique.Passes[0].Apply();
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, mmp.NumVertices, mmp.StartIndex, mmp.PrimitiveCount);
                }
            }
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            DrawModel(model, Matrix.Identity, effect);

            base.Draw(gameTime);
        }
    }
}

I already exported box.fbx from Blender 2.79x

Result: box doesn't show up.

I have tried to understand with tutorial

How do I fix if model doesn't show in Game.

// EDIT

It seems problem with MonoGame 3.7 because ContentException of fbx, dae, obj etc don't work.

I go back MonoGame 3.6 and it works fine.

Thanks!

Posts: 1

Participants: 1

Read full topic

MonoGame.Extended Tiled Importing and Rendering Issues

$
0
0

@CoryKroll wrote:

I'm in the process of building a UWP game that utilizes MonoGame and MonoGame.Extended.
This game relies heavily on the tile engine.
I've been running into a bunch of things around the Tiled library that I'm hoping to get some help with:

Content Pipeline
When I initially loaded up my project, I got this weird, broken folder. I clicked Content > Properties > References and browsed to the location, but the odd folder icon still remained. The UI also closes/crashes when I try to click it:

Since I'm doing UWP the Pipeline.dll isn't in a subfolder called packages, but is instead found in:
C:\Users\(Username)\.nuget\packages\monogame.extended.content.pipeline\1.1.0\tools\
This may be a part of the issue.

When I tried to add the reference in this location, I also found that is added some paths in the content.mgcp that seemed really odd:

#---------------------------------- Content ---------------------------------#

#begin /build=/build=/build=/reference:..\..\..\..\Users\KrollWare\.nuget\packages\monogame.extended.content.pipeline\0.6.568\tools\MonoGame.Extended.Content.Pipeline.dll
/importer:
/processor:
/build:/build=/build=/build=/reference:..\..\..\..\Users\KrollWare\.nuget\packages\monogame.extended.content.pipeline\0.6.568\tools\MonoGame.Extended.Content.Pipeline.dll

#begin /build=/build=/reference:..\..\..\..\Users\KrollWare\.nuget\packages\monogame.extended.content.pipeline\1.0.617\tools\MonoGame.Extended.Content.Pipeline.dll
/importer:
/processor:
/build:/build=/build=/reference:..\..\..\..\Users\KrollWare\.nuget\packages\monogame.extended.content.pipeline\1.0.617\tools\MonoGame.Extended.Content.Pipeline.dll

I was able to workaround all of this mess by copying the tools directory into a lib sub-folder of my project and referencing that path instead. I know the old path used to work - so all I can guess is that somehow the Content Pipeline broke in that is doesn't like the type of reference path that I have to give it anymore.

Importer/Processor
With this in place, I was again able to build. But I wanted to make sure my importer and processor for the tmx file were OK. When I click on the .tmx file, however, it just says Invalid / Missing Importer. Same for the Processor. Still builds though. I'm pretty sure once I supply the reference to the Pipeline.dll the additional Importers and Processors should appear - but if I'm wrong, please let me know:

Animation Tiles
Now that everything builds and runs, I can see the tile map in my game. The tiled map has animated tiles in it, that show up just fine in Tiled. However, in my UWP project, Monogame.Extended.Tiled seems to render them all wrong in the latest version (1.1.0). I had to revert back to 1.0.617 for them to render properly. In 1.1.0 the tiles used in the animation are incorrect and not the correct size (I figure this might just be a position/size loop bug recently introduced).

Despite all of these details I love Monogame and these libraries, and look forward to continuing to use them in the future! Please let me know if I can add any further details.

I'm running MonoGame 3.7.0.1549.

Posts: 1

Participants: 1

Read full topic


Shader Series - Screen Space Reflections

$
0
0

@rtroe wrote:

Hi all,

I've written up another Shader Tutorial on Screen Space Reflections over at @VirtexEdgeDesign main site. It overviews the meat and potatoes of the shader along with a healthy amount of code samples.

It also highlights some of the in-game editor functionality for our Vertices Engine we're developing.

Let me know what you think, I'd love some feedback. And give the blog a follow or check out our Twitter and Instagram to keep up with our Shader Series and upcoming games.

Thanks,

-RT

Posts: 1

Participants: 1

Read full topic

How does MonoGame work with multiple windows like Blender, 3D Max Studio or Unreal Editor?

$
0
0

@Jens_Eckervogt wrote:

Hello everyone,

I have tried to make multiple windows like any program Blender with Preference Window and Unreal Editor has many child windows like Mesh Editor etc...

like any programs Blender:

Or Max Studio 2017

Or Unreal Editor
( Can't find other :frowning: )

I have made Buttons from youtube

And I would like to know about multiple windows of MonoGame if VERTICES ENGIN would like to expand more childwindows -

How do I implement if I close 2. window than I use back to 1. window.

Do I need to use Thread Class?

Thanks foir explanation!

  1. Button "Setting" If I open SettingWindow of MonoGame Engine.
  2. Button "Change" it changes for background from 1. window But I have tried. no success. How do I know like very old Gtk Window with MonoGame

Do you think that MonoGame 3.6 / 3.7 works for multiple windows too?

Or I need merge with pInvokes with Window.Handle?

// EDIT:

I have tried to Thread like Gtk App and MonoGame.
But It throws exception "NoSuitableGraphicsDeviceException" problem.

How do I fix? I need try catch statement? And it looks crazy if I click button "Setting" than mousecusor will hide. It looks crazy.

How do I fix? Thanks!

Posts: 1

Participants: 1

Read full topic

Point data type seems broken?

$
0
0

@SneakyTactician wrote:

While debugging through a Monogame program I was noticing some weird behaviors in my code.

Whenever I hovered over a XNA Point, I would get the following error instead of seeing the value of the XNA Point.

error CS0103: The name 'DebugDisplayString' does not exist in the current context

I printed the value of the point via the ToString(), and the result was empty AKA "".

Here is my test that I showed in the screenshot:

    static void Main(string[] args)
    {
        Point point = new Point(3, 1);
    }

This started to happen recently.
Any ideas?

Posts: 2

Participants: 2

Read full topic

How to change the Monogame default IOS splash screen to my own?

$
0
0

@Philippe_Guyard wrote:

I know this seems like an obvious question, but I didn't manage to find any adequate answers for it in the net.

My problem: When the game is run on my iPhone 7, there are black borders around the game screen.

Solution found on the net: Change your splash screen to one that has the same resolution as your iPhone 7

Question: How to change my splash screen in a Monogame 3.4, 3.5 or 3.6 IOS project? (I have Visual studio 2017)

Posts: 1

Participants: 1

Read full topic

I can't use IME for Chinese input

$
0
0

@ClEngine wrote:

I want to solve the Chinese input problem for monogame.

Declare the following function

[DllImport("user32.dll",CharSet = CharSet.Unicode)]
static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

Create a static class to complete all message capture tasks:

public static class InputCaputure
{
    delegate IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);

    static bool initialized;
    static IntPtr prevWndProc;
    static WndProc hookProcDelegate;
    static IntPtr hIMC;

     public static void Initialize(GameWindow window)
    {
        if (initialized)
            throw new InvalidOperationException("InputCaputure.Initialize can only be called once!");

        hookProcDelegate = new WndProc(HookProc);
        prevWndProc = (IntPtr)SetWindowLong(window.Handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(hookProcDelegate));
        hIMC = ImmGetContext(window.Handle);
        initialized = true;
    }

    static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
    {
        switch (msg)
        {             
            case WindowMessage.ImeSetContext:
                {
                    //add code here
                    return (IntPtr)1;
                }

            case WindowMessage.ImeStartCompostition:
                //add code here

                return (IntPtr)0;

            case ............

            default:
                return CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam);
        }
    }
}

It will capture and process all the messages we care about, and then pass all the messages to Game.
Although the IME window was successfully activated, the IME does not seem to receive any key messages. Add the following code:

case WM_GETDLGCODE:
    return (IntPtr)DLGC_WANTALLKEYS;

Finally, there are several points:

  1. In addition to capturing WM_IME_END COMPOSITION to get a synthesized string with ImmGetCompositionString, capturing WM_IME_CHAR and WM_CHAR can also achieve the same effect.

  2. GetKeyboardLayout can get the message related to the current keyboard layout.

  3. ImmGetIMEFileName can get the ID of the current input method.

  4. ImmSetConversionStatus can switch half-width full-width status.

  5. Use WM_CHAR to handle normal input instead of using Keyboard in MonoGame. Because the keyboard in MonoGame was not originally designed for input characters, you can't get the Caps Lock state at all, so even ordinary English input is very troublesome.

I hope that MonoGame developers can see this article

Posts: 2

Participants: 2

Read full topic

Viewing all 6822 articles
Browse latest View live