Implementing cycling color

(Juan Medina) #1

Hi, I’m a beginner that is just learning rust using amethyst, and at the same time learning how to use ECS for game development since I’ve done more traditional OO game development for years. So sorry if my doubts are really simple.

I was experimenting with the pong tutorial and I decide to do a small change to the game, the ball will be visible but pause in the centre of the screen doing cycling of color, so going from the original color to red and back, like a flashing. I love to add some visual feedback on things like this.

So I decide to use Tint for it but since I need to be changing in cycles a need to create a new component and a system for it.

So first I create this component here

And then a System to handle it here

It works great, the example is here running:

But I’ve some question, and I hope if some of you could answer it.

  • Did I create the right thing? Are the component and system how we should do things in Amethyst?
  • How I can make this more idiomatic? I’m really new in Rust.
  • When I create my entity I need to add the Tint component and my new component, shall I do something that I only need to add my component? If so, how?
  • I used the Tint component since for doing something else I need to do an implementation for the render engine on it, meanwhile tint already change the vertex colors of my sprite. Is that right?

Many thanks if you read till here!!