Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ operator to create sequence of actions #172

Closed
jcornaz opened this issue Dec 7, 2018 · 6 comments
Closed

+ operator to create sequence of actions #172

jcornaz opened this issue Dec 7, 2018 · 6 comments
Labels
actors Issues of the ktx-actors module good first issue Simple tasks that do not require advanced knowledge of KTX or LibGDX
Milestone

Comments

@jcornaz
Copy link
Contributor

jcornaz commented Dec 7, 2018

I think a + operator to easily create a sequence of actions would be nice

Example:

val sequence = moveTo(200f, 200f, 0.5f) + rotateTo(90f, 0.5f) + fadeOut(0.5f) + remove()
@czyzby czyzby added actors Issues of the ktx-actors module good first issue Simple tasks that do not require advanced knowledge of KTX or LibGDX labels Dec 7, 2018
@czyzby czyzby added this to the 1.9.9 milestone Dec 7, 2018
@czyzby
Copy link
Member

czyzby commented Dec 7, 2018

It could be similar to then infix method, but it should not mutate sequence actions.

@jcornaz
Copy link
Contributor Author

jcornaz commented Dec 7, 2018

It could be similar to then infix method, but it should not mutate sequence actions.

Ooops, indeed I forgot about then.

However I personally think that + and then should do exactly the same. (and not mutate the receiver)

Using then or + would only be a style choice (like using crs or x with vectors)

But a += may mutate the receiver.

val sequence1 = moveTo(200f, 200f, 0.5f) + rotateTo(90f, 0.5f) + fadeOut(0.5f) 
val sequence2 = moveTo(200f, 200f, 0.5f) then rotateTo(90f, 0.5f) then fadeOut(0.5f) // should produce the same result as above

sequence2 += remove() // One could still mutate a sequence like this

EDIT: Let me also argue that the then infix functions overload is currently inconsistant:

  • Action.then(action: Action) does not mutate the action
  • SequenceAction.then(action: Action): SequenceAction does mutate the sequence

@czyzby
Copy link
Member

czyzby commented Dec 7, 2018

These are valid points. I believe when I was implementing this, I was in the LibGDX mindset of trying to go easy on the garbage collector, but I agree that idiomatic Kotlin approach is better in this case.

@czyzby
Copy link
Member

czyzby commented Dec 8, 2018

Thanks for your contribution @jcornaz. I just realized parallelTo has the same mutability issue. I'll change it similarly to then. Do you think it makes sense to add an operator for parallel actions? I'm afraid it would be less obvious than in case of sequences, but % or / could work.

@jcornaz
Copy link
Contributor Author

jcornaz commented Dec 8, 2018

Do you think it makes sense to add an operator for parallel actions? I'm afraid it would be less obvious than in case of sequences, but % or / could work.

No. I don't see the point of a non-obvious operator for parallel actions. In this case parallelTo is fairly enough.

@czyzby
Copy link
Member

czyzby commented Dec 8, 2018

| would be more obvious, but it's not available in Kotlin 1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actors Issues of the ktx-actors module good first issue Simple tasks that do not require advanced knowledge of KTX or LibGDX
Projects
None yet
Development

No branches or pull requests

2 participants