-
Notifications
You must be signed in to change notification settings - Fork 2
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
Testing corner cases with ball animation and input events #188
Comments
There is some buggy behavior here. Testing with the query params 'slowAnimation' and 'sameSpot' to make it easier to see animation and input issues. Since the code is starting to get complicated with listeners and callbacks, I think we should lay out the desired behavior before discussing a solution @samreid @marlitas. Here are some of the scenarios we will need to account for, to confirm UX:
We may want to set aside some design time to discuss the UX here. Thoughts? |
Here's a patch that has an interesting floating ball bug. Subject: [PATCH] clearAnimation
---
Index: js/common/model/SoccerBall.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/model/SoccerBall.ts b/js/common/model/SoccerBall.ts
--- a/js/common/model/SoccerBall.ts (revision f14888a75f80e32c7ea6cce2980eca109f03ad81)
+++ b/js/common/model/SoccerBall.ts (date 1684255978237)
@@ -109,6 +109,12 @@
} );
}
+ public clearAnimation(): void {
+ if ( this.animation ) {
+ this.animation.stop();
+ this.animation = null;
+ }
+ }
public step( dt: number ): void {
if ( this.animationModeProperty.value === AnimationMode.FLYING ) {
Index: js/common/model/CAVSceneModel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/model/CAVSceneModel.ts b/js/common/model/CAVSceneModel.ts
--- a/js/common/model/CAVSceneModel.ts (revision f14888a75f80e32c7ea6cce2980eca109f03ad81)
+++ b/js/common/model/CAVSceneModel.ts (date 1684256111146)
@@ -158,6 +158,7 @@
const oldStack = this.getStackAtLocation( oldValue );
if ( oldStack.length > 0 ) {
this.reorganizeStack( oldStack );
+ this.clearAnimationsInStack( oldStack );
}
const objectsAtTarget = this.soccerBalls.filter( otherSoccerBall => {
@@ -166,7 +167,9 @@
// Sort from bottom to top, so they can be re-stacked. The specified object will appear at the top.
const sortedOthers = _.sortBy( objectsAtTarget, object => object.positionProperty.value.y );
- this.reorganizeStack( [ ...sortedOthers, soccerBall ] );
+ const newStack = [ ...sortedOthers, soccerBall ];
+ this.reorganizeStack( newStack );
+ this.clearAnimationsInStack( newStack );
}
} );
@@ -298,6 +301,11 @@
} );
}
+ // Cancel out all animations in the soccer ball stack.
+ private clearAnimationsInStack( stack: SoccerBall[] ): void {
+ stack.forEach( soccerBall => soccerBall.clearAnimation() );
+ }
+
protected updateDataMeasures(): void {
const sortedObjects = this.getSortedLandedObjects();
const medianObjects = CAVSceneModel.getMedianObjectsFromSortedArray( sortedObjects );
@@ -345,13 +353,6 @@
// collapse the rest of the stack. NOTE: This assumes the radii are the same.
let position = CAVObjectType.SOCCER_BALL.radius;
soccerBallStack.forEach( soccerBall => {
-
- // If a ball was animating to the top of the stack, stop it. This prevents a floating ball if a lower ball
- // is moved out from underneath
- if ( soccerBall.animation ) {
- soccerBall.animation.stop();
- soccerBall.animation = null;
- }
soccerBall.positionProperty.value = new Vector2( soccerBall.valueProperty.value!, position );
position += CAVObjectType.SOCCER_BALL.radius * 2 * ( 1 - CAVConstants.SOCCER_BALL_OVERLAP );
} );
@@ -492,7 +493,7 @@
}
/**
- * When a ball lands on the ground, animate all other balls that were at this location above the landed ball.
+ * When a ball lands on the ground, animate the ball to the top of the stack.
*/
private animateSoccerBallStack( soccerBall: SoccerBall, value: number ): void {
const otherObjectsInStack = this.getActiveSoccerBalls().filter( x => x.valueProperty.value === value && x !== soccerBall );
@@ -505,9 +506,7 @@
const animationSlowdownFactor = CAVQueryParameters.slowAnimation ? 10 : 1;
const animationTime = animationSlowdownFactor * 0.06 * this.getStackAtLocation( value ).length;
- if ( soccerBall.animation ) {
- soccerBall.animation.stop();
- }
+ soccerBall.clearAnimation();
soccerBall.animation = new Animation( {
duration: animationTime,
targets: [ { |
Pushed commit to wrong issue: |
Improvements to soccerBall animationModeProperty from above commit:
@samreid and I discussed a plan to centralize the soccer ball “state” into the soccerBallPhaseProperty, to make it more maintainable to find out which part of the motion each soccer ball is currently in. There are still z-ordering issues to resolve, but this is looking much better! |
Screen recording showing z-index issues with balls landing out-of-order: |
Patch with working copy changes for fixing z-order rearranging of soccer balls, removing median highligh from SoccerBallNode, adding median highlight to DataPointNode
|
…ataPointNode and remove median highlight from SoccerBallNode - see #188
The above commits address the scenario of while one or more balls are animating to the top of a stack, the user clicks on that stack. 74fc119 cancels animations in a stack on drag start 06f85bc fixes an issue where the landed balls were occluding click events for the stack, even though they could not be dragged themselves. |
Screen recording: hitting 'reset all' while a ball is animating reset.mp4 |
Commit c8b518d resolves the 'reset' and 'clear' issue in the screen recording above. |
'If a ball lands on a stack that is currently being dragged, what should we do?' Right now a stack that is being clicked/held behaves like a stack that is not being clicked. If the drag event updates the value of a ball, the animations of the old and new stacks are cancelled as described above. This seems good behavior to me, but warrants a design review to confirm. |
Is this a design question? From the comment above it seems like it might be, so marking it as such. Just quickly playing with the sim in that use case it seems like good natural behavior. |
Today in design meeting, we reviewed the behavior where dragging a ball across an animating stack, and the animations jump to their destinations, and we agreed it seems OK. Nice work everyone, closing. |
Reopening because there is a TODO marked for this issue. |
I addressed the two remaining TODOs in this issue. The median highlight and all arrows appear to be working nicely. Labeling as ready-for-review. |
@matthew-blackman and I reviewed the latter commits and also made another improvement by removing SoccerBall.isActiveProperty. Closing. |
Since the sim uses animation on objects that have input enabled, we feel that it will be helpful to test out the following to confirm the desired behavior:
This is a continuation of the work done in #165
The text was updated successfully, but these errors were encountered: