x-skeww•

Aw. So retro. :D

Reminds me of Gradius.

Some random tips and pointers:

  • I'd move "tick" into the main loop. For each frame, tick then render.

  • Thanks to the wonders of hardware acceleration, simply clearing the entire thing is actually much cheaper than overdrawing the stars individually.

  • Since you aren't removing stars in tick, iterating in reverse isn't necessary. You can use a nicer-looking for-in there, too.

  • For grayscale colors, hsl() is a bit more convenient. You only have to set the lightness (0%-100%) instead of all 3 channels.

  • Instead of that "init" method, you could use the List.generate constructor. It's really convenient for things like this.

1
falsoOP•

Thanks!!

Heres an updated one with your hints!

https://dartpad.dartlang.org/1d8dab7e049a0f9c36b6

2
x-skeww•

Got another rather unimportant detail which, I think, is still worth mentioning.

If you don't use an argument of a callback, you can use an underscore as parameter name to mark it (by convention) as unused:

(int index) => new Star(/* not using index here */)

(_) => new Star(/* not using index here */)

You'll often see this in other people's Dart code. Using the "yea, whatever" parameter name tells the reader that you only put it there for arity reasons, but you aren't actually going to use it for anything.

In languages like JavaScript, where arity doesn't matter, many people simply omit the unused parameters.

Personally, I prefer being explicit about it. Calling a function with the wrong number of arguments might as well have been a mistake.

1