stride3d / stride3d/stride

How about improve usability of the SpriteComponent a little bit?

Open
#1,347 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
7.8k
Forks
1.2k
Avg merge
2d 17h
Merged PRs (30d)
49

Description

Is your feature request related to a problem? Please describe.
More than "fixing a problem" is "making the code more readible, clean, intuitive and aproachable without really changing anything but just adding a couple of methods".

Describe the solution you'd like
Right now to change a sprite at runtime you need to do something like this:

SpriteFromSheet sprite = SomeEntityWithSpriteComponent.Get<SpriteComponent>().SpriteProvider as SpriteFromSheet;
sprite.CurrentFrame += 1;

Which it's fine and work ok, but make the newcomers (specially but not limited to those who come from unity) guess than this is aproach is somehow counter-intuitive, specially when you can add in the SpriteComponent class some methods like:

        public void Set(int currentFrame)
        {
            SpriteFromSheet sprite = this.SpriteProvider as SpriteFromSheet; //Being "this" the SpriteComponent
            sprite.CurrentFrame = currentFrame;

            //Or something like that.
        }

        public void Set(SpriteFromSheet sprite)
        {
            //Some logic than allow to change the relevant SpriteFromSheet in the SpriteComponent, probably something like
            this.SpriteProvider = (ISpriteProvider)sprite ; //Being "this" the SpriteComponent

             //Or something like that.
        } 

NOTE: The "Set" methods do not currently exist.

That way the code to change sprites will see something like this:

SomeEntityWithSpriteComponent.Get<SpriteComponent>().Set(1);

Instead of the one we use today, that is:

SpriteFromSheet sprite = SomeEntityWithSpriteComponent.Get<SpriteComponent>().SpriteProvider as SpriteFromSheet;
sprite.CurrentFrame += 1;

The first way, the way to solve it suggested here is intuitive, you can guess it navigating the SpriteComponent and reading a little in intellicence, the second one requires you to know a class than is not obvious that exist, and for something than is not documented either, that means than you need to ask about it to know or go to read the API (i assume) because in documentation there is nothing about this, that's why i suggest this, i think a more intuitive aproach can do wonders specially for newcomers, but also for readibiliy.

And that's it, thats all the suggestion, a couple more methods really, not really a huge lot of job to do or implement.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating SpriteComponent and SpriteFromSheet, then inspect SpriteProvider and current-frame usage. Compare the proposed Set(int) and Set(SpriteFromSheet) APIs with existing component conventions; done means the runtime sprite-change behavior and API shape have been agreed and implemented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-graphics, game-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.