Skip to content

Instantly share code, notes, and snippets.

@w0wca7a
Created August 16, 2025 20:27
Show Gist options
  • Save w0wca7a/a9cfa1f356d7c09f7e3fe3d3751d0a5c to your computer and use it in GitHub Desktop.
Save w0wca7a/a9cfa1f356d7c09f7e3fe3d3751d0a5c to your computer and use it in GitHub Desktop.

Revisions

  1. w0wca7a created this gist Aug 16, 2025.
    47 changes: 47 additions & 0 deletions CursorRender.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    /// https://forums.stride3d.net/t/change-mouse-cursor-graphic/1281/5
    using Stride.Games;
    using Stride.Graphics;
    using Stride.Core;
    using Stride.Input;
    using Stride.Rendering;
    using Stride.Rendering.Compositing;


    [Display("Demo: Sprite Cursor Renderer")]
    public class SpriteCursorRenderer : SceneRendererBase
    {
    private SpriteBatch spriteBatch;
    private InputManager inputManager;

    public Texture Cursor { get; set; }

    protected override void InitializeCore()
    {
    base.InitializeCore();

    spriteBatch = new SpriteBatch(GraphicsDevice);

    inputManager = Services.GetService<InputManager>();

    Services.GetService<IGame>().IsMouseVisible = false;
    }

    protected override void DrawCore(RenderContext context, RenderDrawContext drawContext)
    {
    if (Cursor != null)
    {
    spriteBatch.Begin(drawContext.GraphicsContext, depthStencilState: DepthStencilStates.None);

    spriteBatch.Draw(Cursor, inputManager.MousePosition * context.ViewportState.Viewport0.Size);

    spriteBatch.End();
    }
    }

    protected override void Destroy()
    {
    base.Destroy();

    spriteBatch.Dispose();
    }
    }