Created
August 16, 2025 20:27
-
-
Save w0wca7a/a9cfa1f356d7c09f7e3fe3d3751d0a5c to your computer and use it in GitHub Desktop.
Renderer for cursor image in Stride game engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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