New Features
More Pattern Formats
EasyPattern now supports four pattern specification formats. Provide any of these for the pattern property to define your pattern, or call the overloaded setPattern() function:
- Bit pattern. An array of 8 numbers representing the bit pattern for each row. (previously supported)
- Dither pattern. A table containing a
ditherTypeconstant, and optionalalphaandcolor. (revised, see breaking changes) - Image. An 8x8
playdate.graphics.image. (new) - ImageTable. An 8x8
playdate.graphics.imagetable. (new)
Pattern Composition
Set the new bgPattern property to provide a pattern that appears behind your partially transparent EasyPattern. This property supports static patterns or another EasyPattern instance, allowing recursive composition of animated patterns and enabling more nuanced effects. See an example.
Dynamic phase shifts
Set xShift and yShift to additively adjust the displayed X and Y phases of your pattern. This feature enables your patterns to respond dynamically to inputs or game conditions. For instance, you could use it to scroll a pattern with the crank or create a parallax background effect as the player moves. See an example.
Reflection & Rotation
Apply reflection and rotation transformations to your patterns to change their orientation with the xReflected, yReflected, and rotated properties. This simplifies the process, as both pattern and animation properties automatically adjust, eliminating the need for manual adjustments of individual properties. See an example.
Inverted Patterns
Set the inverted flag to render a pattern with inverted colors, so that black pixels appear white, and white pixels appear black. See an example.
Animated Patterns
The pattern property now accepts a playdate.graphics.imagetable. This enables patterns themselves to animate, in addition to the animated easing of the overall pattern that EasyPattern applies. Set the tickDuration property to indicate how long each image in the sequence should be shown. See an example.
Variable Opacity
Set the opacity of your pattern with the alpha property, and optionally specify a ditherType for the opacity effect. This will cause the pattern to render in a similar manner to playdate.graphics.image:drawFaded(), allowing anything behind the pattern—even in otherwise opaque areas—to show through. See an example.
Loop Duration and Callbacks
New getters provide convenient access to the X, Y, and total pattern loop duration. The returned values account for all animation properties including duration, speed, and offset, as well as those of any background pattern. New callbacks which trigger when looping enable you to modify the pattern itself over time, or trigger other events in sync with your pattern. See an example.
Update Callback
Dynamic behaviors, such as adjusting the phase offset of a pattern based on crank input or character position, can now be encapsulated within the EasyPattern declaration via the update(pattern, time) callback. This function gets called immediately before every phase computation, allowing you to modify the pattern as needed. See an example.
Bug Fixes
isDirty()now reports accurately even when called multiple times per frame before callingapply(). This makes it much easier to use the same pattern with multiple sprites, which can be marked dirty in theirupdate()functions without needing to cache a dirty bit.
Breaking Changes
- Legacy parameter names. Previously deprecated legacy parameter names have been removed. See the list of supported parameters.
- Dithered patterns. Patterns constructed with
ditherTypeandalphaare no longer defined using individual properties. Instead, provide a table containing the values (and optionalcolor) to thepatternproperty. (ditherTypeandalphaproperties remain, but are now reserved for setting the opacity effect of the pattern itself.)setDitherPattern(alpha, ditherType)is still supported, althoughsetColor()is removed in favor of a third, optional argument tosetPattern(ditherType, [alpha], [color]). See an example.
Full Changelog: v1.3.0...v2.0.0