Skip to content

GameLab: Add horizontal and vertical stretch for animations#9546

Merged
caleybrock merged 9 commits into
stagingfrom
animation-sizes
Jul 22, 2016
Merged

GameLab: Add horizontal and vertical stretch for animations#9546
caleybrock merged 9 commits into
stagingfrom
animation-sizes

Conversation

@caleybrock

@caleybrock caleybrock commented Jul 15, 2016

Copy link
Copy Markdown
Contributor

Add the ability to stretch an animation.
screen shot 2016-07-15 at 11 17 57 am

This exposes another known bug with animation width and height: it takes 3 times in the draw loop for width/height to properly set. If we had set width/height outside of the draw loop, the draw loop would have over-ridden our set width and height with the image width and height.

I ran into some weird cases when combining width and height with scale for animations, but I fixed these in p5.play. They aren't technically related, but these bug fixes make this feature usable:

  • setAnimation sets internalWidth and internalHeight immediately instead of waiting for the draw loop
  • when a user sets width or height on an animation it adjusts the size of it's collider

Comment thread apps/lib/p5play/p5.play.js Outdated
if (pInst._angleMode === pInst.RADIANS) {
// This line differs from p5.play upstream because GameLab users
// should be able to change the width and height of their animations.
scale(this.scale*dirX*this._horizontalStretch, this.scale*dirY*this._verticalStretch);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding the _horizontalStretch and _verticalStretch properties in p5.play.js, can we just track these in GameLabSprite (the only place we modify them)? Then if we extract the transform methods here to a helper, and override the helper from GameLabSprite, we should be able to swap in our behavior change.

Sorry if you were already working on this, I know this might be a WIP PR.

Comment thread apps/lib/p5play/p5.play.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the names for modifyScaleX/Y, which are named as verbs but in practice are getters with no side effects. They should also probably be private-named (leading underscore) and have a descriptive comment.

More generally, I wonder if we want to create just one method that we'll override, something like this._applySpriteScaleForRendering. I can't think of a situation where we'd want to override the horizontal scale factor but not the vertical one; and even if we did, it'd be pretty simple to do so with the single override method.

@caleybrock caleybrock force-pushed the animation-sizes branch 2 times, most recently from 21090cb to 5c4f726 Compare July 20, 2016 23:57
@caleybrock caleybrock changed the title GameLab: Add horizontal and vertical stretch for animations GameLab: Add horizontal and vertical stretch for animations - WIP Jul 21, 2016
@caleybrock

Copy link
Copy Markdown
Contributor Author

@islemaster this is ready now - just need to finish the test so I can add a PR to p5.play too.

Comment thread apps/lib/p5play/p5.play.js Outdated
scale(this.scale*dirX, this.scale*dirY);
if (pInst._angleMode === pInst.RADIANS) {
scale(this._getScaleX()*dirX, this._getScaleY()*dirY);
if (pInst._angleMode == pInst.RADIANS) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the switch to soft equality here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unintentional - good catch! fixed.

@islemaster

Copy link
Copy Markdown
Contributor

LGTM!

@caleybrock caleybrock changed the title GameLab: Add horizontal and vertical stretch for animations - WIP GameLab: Add horizontal and vertical stretch for animations Jul 22, 2016
@caleybrock caleybrock merged commit 40e882e into staging Jul 22, 2016
@caleybrock caleybrock deleted the animation-sizes branch July 22, 2016 23:28
deploy-code-org added a commit that referenced this pull request Jul 25, 2016
906f3ad Merge pull request #9559 from code-dot-org/topInstructions-integrate-hints (Elijah Hamovitz)
40e882e Merge pull request #9546 from code-dot-org/animation-sizes (Caley Brock)
b3a9bbb Merge pull request #9660 from code-dot-org/pd-workshop-join-section (Andrew Oberhardt)
ea5c048 Merge branch 'staging' into topInstructions-integrate-hints (Elijah Hamovitz)
de6955d missing semicolon fix (Caley Brock)
6bc0459 PR feedback: renamed unit test variables and added comment (Andrew Oberhardt)
85f27bb code review: fix typo (Caley Brock)
2653697 staging content changes (-Ram) (Continuous Integration)
f0fcf5c Remove not needed comment (Caley Brock)
8fb23f7 Merge pull request #9675 from code-dot-org/levelbuilder (Ram Kandasamy)
ad499a1 Modify p5play to initialize sprite height and width and not change them during update (Caley Brock)
79e2eff levelbuilder content changes (-Ram) (Continuous Integration)
851caa6 Merge pull request #9620 from code-dot-org/photo-credit (Tanya Parker)
0e067b3 Merge pull request #9661 from code-dot-org/peer_review_in_course_ui (Mehal Shah)
df67e16 I am annoyed that this works (Mehal Shah)
ac5bcd1 staging content changes (-Ram) (Continuous Integration)
6043087 Automatically built. (Continuous Integration)
c43f297 remove custom scroll handler, instead hide native scrollbar (Elijah Hamovitz)
islemaster added a commit to code-dot-org/p5.play that referenced this pull request Oct 21, 2016
For some reason this shows up in code-dot-org/code-dot-org#9546 but not in its matching upstream change https://github.com/molleindustria/p5.play/pull/103.  It's necessary for code-dot-org's wrapper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants