-
Notifications
You must be signed in to change notification settings - Fork 558
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
Motion tweaking #923
Motion tweaking #923
Conversation
- Fixes a rounding issue when calculating the sign of negative fractions - Triggers NewDirection in the frame where the direction changes, instead of the next frame - Renames NewRotation to NewAngularDirection and fixes the same issues - Adds/fixes related tests
As mentioned, this does have a breaking change: it changes speeds from pixels per frame to pixels per second. I think this is a more natural definition in most cases -- I often had to choose very small speeds or accelerations with the old units. Any arguments to keep it as is, though? |
A quick note about tests: lots of tests are certainly way better than none! But I wanted to give a few recommendations. (I'm not trying to pick on the tests for Motion, they just happened to be what I happened to interface with on this patch! And the thorough testing definitely let me feel good about making the changes! :) )
|
equal(newRevolutionEvents, 3); | ||
equal(movedEvents, 6); | ||
equal(rotatedEvents, 2); | ||
equal(motionEvents, 17); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this checks shouldn't be removed, as we can not guarantee that all event callbacks fired as we wanted
I have looked over the PR, good job! The only thing I would like to nitpick is the order of the |
Another possibility would just be to trigger this when the velocity is actually changed. (So in the setter for the velocity properties.) That way it wouldn't matter how the velocity was changed. |
I think there are enough breaking changes since the last version that pretty much any game will require a bit of work to update, so I'm not too worried about this. I find it makes it easier to reason about how speeds and accelerations, so it should be worth it. |
It also plays nicely with tweening. Ok then, I suggest you readd some test checks, as well as update the default values for movement and their respective documentation ( |
Yes, that would be great! Note that it will introduce some overhead probably. |
Add some in-line documentaiton, and tweak the wording of the API docs for the Motion component
3f52c06
to
da56d20
Compare
Ok, I re-added those tests. (A better fix would be to break up that long litany of tests into several isolated ones, and then check that each event was called individually, but I think this is fine for now.) I also adjusted the default speeds/accelerations to match the new time-scale. |
@@ -450,13 +451,13 @@ Crafty.c("Jumpway", { | |||
* | |||
* @example | |||
* ~~~ | |||
* this.jumpway(6, ['UP_ARROW', 'W']); | |||
* this.jumpway(['UP_ARROW', 'W']); | |||
* this.jumper(6, ['UP_ARROW', 'W']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update speed here, e.g. 300
Great, I noticed some minor things that should be updated in documentation.
Should this be in current or seperate PR? |
Good catch with the examples.
If we do that, it'll be a separate PR. Since there's an event any time the velocity changes, I'm not sure how important it is to have a separate one that occurs for a particular type of change. |
Instead of adjusting the speed based on the frame rate, try to saty in sync with the game clock by using frame.dt. Note that speeds are in pixels per second. This is a breaking change, because it changes how we interpret speeds. (Pixels per second instead of pixels per frame.)
"Jumpway" is probably a bit confusing, even though it kind of makes sense in the context of Twoway and Fourway.
Ok, all the examples should be updated now. |
I just noticed this since I use the nightlies: I think to make the transition easier it would good to provide some rough formula to get from pixels per frame to pixels per second, assuming some common framerates like 60fps. |
To go from old
Good idea, we should probably add this to the changelog |
Yep, that worked. Thanks |
Several small issues with Motion/Control components