Clean code & fix screen resize/orientation events #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There were a few localised functions that were never used. There was also a large chunk of code concerning display.capture() and/or screenshot, but none of the calculated variables were actually used for anything, so I removed them.
The larger changes were concerning the touch/tap blocking sensors and the scene transition effects.
The current (old) version of Composer creates touch/tap blocking sensors, but one of them would be mispositioned if the app is using graphics v1 compatibility mode. Also, neither of these sensors move or update in size if the screen orientation or display size change. They were also using display.contentWidth and display.contentHeight, so they didn't block touch/tap events on devices with different display aspect ratios than defined in config.lua.
The current version of Composer also creates a table for scene transition effects when the library gets required for the first time. This means that if the screen size changes due to orientation or resize event, then future scene transition effects will still play out like the screen dimensions hadn't changed. These effects were also not using actual display width and height values, so they jumped in and out of the screen if the display's aspect ratio differed from config.lua's values.
With these changes, Composer library will use the correct values when it is first required. It also adds a new API,
composer.onScreenChange()
, which the user may call at any time during or after orientation and resize events to update Composer's touch sensors and scene transition effects. NB! This does not resize or reposition on-going scene transitions.This commit leaves the composer_scene as is, but there is a known problem that requiring Composer in a project will automatically require physics and json libraries as a part of composer_scene. This is a relic of the old Corona SDK Composer GUI Beta product.
Here are two sample projects that demonstrate the aforementioned issues. The third sample project contains the revised Composer library (this commit), where these issues are fixed.
problem #1 - orientation change.zip
problem #2 - touch issues & scene transitions.zip
solution - test project.zip