coronalabs / framework-composer

Corona composer.* framework
https://docs.coronalabs.com/api/library/composer/
2 stars 4 forks source link

Clean code & fix screen resize/orientation events #3

Open XeduR opened 3 years ago

XeduR commented 3 years ago

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

XeduR commented 3 years ago

For reviewing the changes for lines 70-570, it'll probably be easier to download the revised file and look at that. It takes the original table of effects and recreates it within a function. This extra indentation makes the GitHub code changes view show a bit too much red.

IlSui commented 3 years ago

Just to give a little contribute, I've tested these 3 apps on the simulator and 2 different devices (Android 11), and I confirm the issues are fixed.

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.