74 Commits

Author SHA1 Message Date
Katie Broida
8f007c0986 Only check local position against mosaic effect transform if it falls within the drawable's space 2019-03-18 15:25:40 -04:00
Chris Willis-Ford
f2d457a827
Revert "Adjust CPU isTouchingColor to match GPU results" 2019-02-07 13:00:15 -08:00
Christopher Willis-Ford
1db67a474e Adjust CPU isTouchingColor to match GPU results 2019-02-04 11:20:59 -08:00
DD
5f38cd1ee1 Always use nearest for raster textures 2019-01-03 12:00:28 -05:00
Katie Broida
770ae92b25 Align the bounding box to the center of the pixel instead of top left 2018-12-21 16:51:36 -05:00
Michael "Z" Goddard
b901c1ac75
round drawable position
Scratch 2 rendered sprite position is at whole numbers, while its vm
position may be rational numbers.
2018-08-24 18:19:19 -04:00
Mx Corey Frang
c54a928f0a
Touching color implementation (#312)
* Touching color draft implementation

* New constant for CPU/GPU render split determined, removing query param

* Small fix for pick tests
2018-08-08 14:20:35 -04:00
Michael "Z" Goddard
c08b853519 add uniformName to ShaderManager EFFECT_INFO entries (#328) 2018-08-08 14:04:37 -04:00
Mx Corey Frang
6863613d20
Optimizing isTouching while creating a drawableTouches for sensing mouse pointer (#325)
* Allow 'isTouching' and 'pick' to still work on invisible drawables.

* Always ignore visibility for isTouching on drawable

* Filter invisble drawbles in isTouchingDrawable per rules of collision

* polish up some docs/get logic 👍

* leftover line from deleted comment

* revert to ghosted pick behavior

* Add clientSpaceToScratchBounds method

* fix lint

* add some pick tests
2018-08-07 10:56:28 -04:00
Mx Corey Frang
2b8371e5af
Rewrite isTouchingDrawables on CPU (#263)
* avoid gl.readPixels at all costs
2018-04-27 16:19:25 -04:00
Paul Kaplan
e02cc5ae03
Merge pull request #248 from paulkaplan/fix-bubble-bounds
Add "get bounds for bubble" method.
2018-03-23 14:35:52 -04:00
Paul Kaplan
0b731b92a6 Add "get bounds for bubble" method.
Note there was an inconsequential coordinate flip in the original
transformation code, which was fixed in order for the sliced bounds to
work. The change is at line 388
2018-03-23 10:58:21 -04:00
Michael "Z" Goddard
b59b5a3075
Put Drawable skin scale updating behind dirty flag
- Clean out "showing your work" in calculate transform
- Add comments on inline math blocks from twgl
2018-01-23 14:15:59 -05:00
Michael "Z" Goddard
46bc30e4ee
Inline most calculateTransform math 2018-01-23 14:14:38 -05:00
Michael "Z" Goddard
40ab1bd59d
Cache drawable's rotation matrix and rotation center vector
Building a rotation matrix needs to call trigonometry functions. Cache the
resulting matrix to save future time on non-rotation motion.
2018-01-23 14:14:01 -05:00
Christopher Willis-Ford
a38c74c2c1 Fix Drawable's use of m4 for TWGL 4.x
The `create` method of `m4` has disappeared; call `identity` instead.
2018-01-10 18:22:57 -08:00
Michael "Z" Goddard
8bdf56705e
Add Drawable.isTouching
Use EffectTransform and Skin.isTouching to implement
Drawable.isTouching.

Drawable.isTouching takes a world coordinate.
2017-11-20 13:46:34 -05:00
Christopher Willis-Ford
737a94b04b Lint fixes 2017-09-06 15:50:01 -06:00
john
ada1902fa6 fix the rotation center bug
fix the bug #131 Rotation center is incorrect while sprite is scaled by "changeSize" block or "setSize" block

the "rotationAdjusted" should be scaled while the drawable target is scaled.
2017-04-22 11:46:02 +08:00
Andrew Sliwinski
e67d8a2126 Merge pull request #94 from CSnap/getBounds
Fix getBounds for Hidden Sprites
2017-03-02 11:31:45 -05:00
Ray Schamp
3c6511d94e Generate docs from src, publish to gh-pages
Fix any broken JSDoc syntax. Unfortunately there is no way to document tuples like `{[int, int]}` for a `[width, height]` array. We could possibly fix this and make the code more readable with `{width: number, height: number}` instead of tuples.

Remove single `@fileoverview` from Rectangle.js, since it was the only file with one and was weird to have that one module show up on the docs home page.

Add a `docs` script to `package.json`, run it from `npm test`, so invalid docs will cause tests to fail (eventually we may want to start using eslint-plugin-jsdoc to catch these errors with the linter alone).
2017-02-21 14:46:24 -05:00
SillyInventor
9c51cf0a04 Switch to getFastBounds from get bounds, and add check for if the hull points are empty. 2017-02-14 19:58:22 -05:00
Christopher Willis-Ford
140c0fbf37 Merge skin classes, convert PenDrawable to PenSkin
Merge the "skin classes" work from another branch and move/convert the
pen work from `PenDrawable` to `PenSkin`.
2017-01-05 16:25:53 -08:00
Christopher Willis-Ford
1f0cd4b61f Fix resource leaks discovered while testing
- `Drawable` now removes its `Skin` on `dispose`, disconnecting events.
- Creating a new `Drawable` doesn't always create a new `Skin` any more:
  now it can share an existing skin.
- Don't throw when asked to update the properties of a `Drawable` that
  has already been destroyed. This seems like a VM bug but was causing
  overwhelming output in the browser for some projects.
2016-12-29 13:42:58 -08:00
Christopher Willis-Ford
6a0798062b Make a Skin emit an event when it is altered
This allows any `Drawable` using the `Skin` to update its transform as
necessary.
2016-12-29 10:46:12 -08:00
Christopher Willis-Ford
ba5deb9936 Minor cleanup after Drawable/Skin refactor
- Add & correct a few comments
- Make `Drawable` IDs work like `Skin` IDs
- Remove some dead code
- Fix costume resolution in `BitmapSkin` before first `setBitmap` call
- Rename `Drawable` & `Skin` management variables in `RenderWebGL` to
  clarify their purpose and better distinguish them from each other
- Remove problematic premature optimization in `_drawThese`
- Fix missing return statement in `Skin`'s `setRotationCenter`
- Fix mismatch between getTexture & getUniforms in the `Skin` class
2016-12-28 14:38:48 -08:00
Christopher Willis-Ford
64c5991486 Split Skin functionality out of Drawable
There is now a `Skin` base class along with `SVGSkin` and `BitmapSkin`
classes for vector and bitmap skin support. Loading a skin by URL is in
the process of being deprecated. In the future skin data should be
downloaded outside the renderer and supplied through new `create*Skin`
API calls.
2016-12-28 12:17:45 -08:00
Christopher Willis-Ford
4730a057ff Move Drawable.NONE into new RenderConstants
This constant will soon be shared with another class.
2016-12-22 12:58:58 -08:00
Christopher Willis-Ford
e3a05743b0 Handle changing the stage's native size, tell pen
The `setStageSize` wasn't working correctly. This change fixes that and
also notifies active `PenDrawable` instances about the resize. This was
implemented by making the renderer an `EventEmitter`.
2016-12-21 16:13:57 -08:00
Christopher Willis-Ford
2a64c1dd18 Convert pen to subclass of Drawable: PenDrawable
To test, load the playground and type `renderer.createPenDrawable()`
into the JS console. Note that the pen layer is now just another
drawable object, so it can move and use effects.
2016-12-21 11:36:29 -08:00
Christopher Willis-Ford
c6356f71ff Move uniforms, skins, transform back to Drawable
It turns out that it might make sense for the pen to share these
features. Splitting them out would likely work too, but would introduce
unnecessary complexity.
2016-12-20 15:29:22 -08:00
Christopher Willis-Ford
8164fef77e Split Drawable into interface & implementation
The skin-based implementation of `Drawable` has been moved into a new
class called `SkinnedDrawable`. This makes room for `PenLayer` to become
a new type of `Drawable`.
2016-12-15 15:51:56 -08:00
Christopher Willis-Ford
b18ddadbe6 Rename color4bToID to color3bToID
A recent change made this function take only RGB instead of RGBA, so the
name might as well change to match.
2016-12-15 10:26:24 -08:00
Christopher Willis-Ford
4afbba3657 Respond to review feedback
- Remove unused alpha parameter from `color4bToID`
- Don't wrap URLs for default skins in `Drawable`
2016-12-14 13:38:43 -08:00
Christopher Willis-Ford
d1ea82b2bf Use this inside => callbacks
Some callbacks used a variable called `instance` to stash `this` for use
inside the callback. Now that those callbacks have been converted from
`function` to `=>`, they can just use `this` instead.
2016-12-13 15:51:46 -08:00
Christopher Willis-Ford
b700560198 Convert class methods to ES6 style
Also un-wrap lines which were originally written for an 80-column limit
but don't need to wrap now that the limit is 120 columns.
2016-12-13 15:32:07 -08:00
Christopher Willis-Ford
3c80ed73a7 Fix lint warnings 2016-12-12 12:06:19 -08:00
Christopher Willis-Ford
5db860efed Use eslint-config-scratch, fix linting errors 2016-12-12 12:06:19 -08:00
Tim Mickel
b35f684478 A start on SVG "quirks mode" (#56)
* Start of an SVG rendering quirks mode

* Provide font defaults in SVG quirks mode

* Remove svg-to-image dependency

* Remove fonts and use package fonts instead.

* try/finally for getBBox
2016-11-07 17:40:59 -05:00
Tim Mickel
be6d2dc4e4 Bounding-box optimizations for touching color, touching drawables (#55)
* Add Rectangle utility and use it in Drawable.getBounds

* Add `getAABB`, `getFastBounds`.

* Add width and height getters to Rectangle

* Add rectangle clamp

* Optimized isTouchingColor

* Optimized isTouchingDrawables

* Rectangle.ceil -> Rectangle.snapToInt

* Refactor to common _touchingQueryCandidates

* Split helper into two
2016-10-24 13:19:20 -04:00
Tim Mickel
2cffa7b643 Add rotation center and bitmap/costume resolution (#51) 2016-10-19 17:02:04 -04:00
Tim Mickel
85c8b599a0 Update dirty transform before calculating bounds (#47) 2016-10-12 15:20:40 -04:00
Tim Mickel
8e7a85d1a6 Fix y coordinates of bounding box (#46) 2016-10-12 14:32:14 -04:00
Tim Mickel
1fa97d248b Expose skin/costume size (#45)
* Expose skin/costume size

* Return skin size as a copy
2016-10-11 18:43:57 -04:00
Tim Mickel
a62d52a2d0 Calculating tight bounding boxes for Drawables (#42) 2016-10-11 18:14:14 -04:00
Tim Mickel
2b81b791b3 Use the right skin format in playground demo (#33) 2016-09-12 12:08:56 -04:00
Tim Mickel
042f0f0353 Fix asset URL handling from #27 (#32)
* Fix URL handling of assets

* Recompile 2 Sept 12
2016-09-12 11:55:08 -04:00
TheBrokenRail
3277584da9 Offline Sprites (#27)
* Added Scratch Cat SVG

* Offline Scratch Cat

* Moved To SRC

* Update README.md

* Delete Travis

* Add Travis YML

* Recompile

* Add files via upload

* Recompile Part 1

* Recompile Part 1

* Recompile Part 1

* Recompile Part 1

* Recompile!

* Not Needed

* Recompile For Real

* Update README.md

* Added Stage Offline

* Less Hacky Offline

* Recompile

* Fixed Line Length
2016-09-12 11:03:57 -04:00
Andrew Sliwinski
92fc916b86 Synchronize with master branch 2016-08-08 14:58:35 -04:00
Christopher Willis-Ford
ad94df4afe Use ES6 class definitions 2016-06-15 15:21:58 -07:00