-
Hello 😊. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok, after many hours, I've already figured it out. I would like to leave it here for others who will be looking for it. Code preparationAs documentation (https://doc.stride3d.net/4.2/en/manual/graphics/low-level-api/spritebatch.html) states at the top you need a custom public class UglyRendererScript : SceneRendererBase
{
/// <summary>
/// Virtual space where we will be drawing. I've made it a little smaller for my "pixelart".
/// </summary>
private readonly Vector2 _virtualResolution = new Vector2(1920/2, 1080/2);
private SpriteBatch _spriteBatch;
/// <summary>
/// Here provide you SpriteSheet from which we will be drawing.
/// </summary>
[Display("Environment Tile Sprite Sheet", category: "Environment")]
public SpriteSheet EnvironmentTileSprites;
/// <summary>
/// Here index of sprite which will be drawn.
/// </summary>
[Display("Index of Grid sprite", category: "Environment")]
public int SpriteIndex;
protected override void InitializeCore()
{
base.InitializeCore();
_spriteBatch = new SpriteBatch(GraphicsDevice)
{
VirtualResolution = new Vector3(_virtualResolution, 1 /*more than zero, why?*/)
};
}
protected override void DrawCore(RenderContext context, RenderDrawContext drawContext)
{
// Clear it is very important, otherwise you will see nothing
drawContext.CommandList.Clear(drawContext.CommandList.RenderTarget, Color.Green);
drawContext.CommandList.Clear(drawContext.CommandList.DepthStencilBuffer, DepthStencilClearOptions.DepthBuffer);
_spriteBatch.Begin(drawContext.GraphicsContext);
var sprite = EnvironmentTileSprites[SpriteIndex];
sprite.Draw(_spriteBatch, new(_virtualResolution.X * 0.5f, _virtualResolution.Y * 0.5f));
_spriteBatch.End();
}
} Getting something on screenAccording to previous documentation, you should go to this page https://doc.stride3d.net/4.2/en/manual/graphics/graphics-compositor/custom-scene-renderers.html, Where you will see some parts of
Further questions
|
Beta Was this translation helpful? Give feedback.
Ok, after many hours, I've already figured it out. I would like to leave it here for others who will be looking for it.
Code preparation
As documentation (https://doc.stride3d.net/4.2/en/manual/graphics/low-level-api/spritebatch.html) states at the top you need a custom
ScreenRenderer
. Unfortunately none is presented in docs, so I share mine with you below calledUglyRendererScript
. Just write this as a script.