Nullable fixes, use Texture2d resource for rendering directly.
This commit is contained in:
@@ -5,10 +5,10 @@ namespace DaggerFramework.SceneGraph
|
||||
{
|
||||
public class Entity
|
||||
{
|
||||
public EntityLayer Layer { get; set; }
|
||||
public InputHandler Input => Layer.Scene.Input;
|
||||
public AudioBackend Audio => Layer.Scene.Audio;
|
||||
public Renderer Renderer => Layer.Scene.Renderer;
|
||||
public EntityLayer? Layer { get; set; }
|
||||
public InputHandler Input => Layer!.Scene.Input;
|
||||
public AudioBackend Audio => Layer!.Scene.Audio;
|
||||
public Renderer Renderer => Layer!.Scene.Renderer;
|
||||
public int Id { get; set; }
|
||||
|
||||
public void Start() => OnStart();
|
||||
|
||||
@@ -8,19 +8,28 @@ namespace DaggerFramework.SceneGraph
|
||||
public class Particles2d : Drawable2d
|
||||
{
|
||||
public int MaxParticles => _maxParticles;
|
||||
public ParticleSettings Settings => _settings;
|
||||
|
||||
public void BeginEmit(ParticleSettings settings)
|
||||
public Particles2d(ParticleSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
_maxParticles = _settings.MaxParticles;
|
||||
_particleIndex = _maxParticles - 1;
|
||||
InitializeParticles();
|
||||
|
||||
_particles = new Particle[_maxParticles];
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
CleanupParticles();
|
||||
InitializeParticles();
|
||||
|
||||
// Allocate a new particle array if max particles property got changed.
|
||||
if (_maxParticles != _settings.MaxParticles)
|
||||
{
|
||||
_particles = new Particle[_maxParticles];
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDraw(Renderer renderer)
|
||||
{
|
||||
foreach (var particle in _particles)
|
||||
@@ -72,11 +81,6 @@ namespace DaggerFramework.SceneGraph
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeParticles()
|
||||
{
|
||||
_particles = new Particle[_maxParticles];
|
||||
}
|
||||
|
||||
private void Emit()
|
||||
{
|
||||
Particle particle = _particles[_particleIndex];
|
||||
|
||||
@@ -6,20 +6,18 @@ namespace DaggerFramework.SceneGraph
|
||||
{
|
||||
public class Sprite2d : Drawable2d
|
||||
{
|
||||
public Texture2d Texture { get => _texture; set => _texture = value; }
|
||||
public Texture2d Texture { get => _texture ?? Texture2d.Empty; set => _texture = value; }
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
var renderer = Layer.Scene.Renderer;
|
||||
_texId = renderer.LoadTexture(_texture);
|
||||
}
|
||||
|
||||
public override void OnDraw(Renderer renderer)
|
||||
{
|
||||
renderer.DrawTexture(_texId, Color.White);
|
||||
renderer.DrawTexture(_texture!, Color.White);
|
||||
}
|
||||
|
||||
private Texture2d _texture;
|
||||
private int _texId;
|
||||
private Texture2d? _texture;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user