Skip to content

Instantly share code, notes, and snippets.

@w0wca7a
Created August 16, 2025 20:27
Show Gist options
  • Select an option

  • Save w0wca7a/a9cfa1f356d7c09f7e3fe3d3751d0a5c to your computer and use it in GitHub Desktop.

Select an option

Save w0wca7a/a9cfa1f356d7c09f7e3fe3d3751d0a5c to your computer and use it in GitHub Desktop.
Renderer for cursor image in Stride game engine
/// 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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment