Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mobile support with Capacitor #12

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

mlynch
Copy link

@mlynch mlynch commented Jan 24, 2023

This PR adds mobile support for the Phaser template using Capacitor. This also makes a change that needs to be reviewed which is to set the game dimensions to window.innerWidth * window.devicePixelRatio and similarly for height, to enable fullscreen mobile apps (might need a different approach for desktop). This forces landscape mode for iOS and Android as well.

Open to feedback to make this a good fit!

@yandeu
Copy link
Owner

yandeu commented Jan 24, 2023

Hey @mlynch,

Thanks for you commit.

  • I would not add the window.devicePixelRatio as default. New users will be confused if suddenly their game look x2, x3 more more times smaller on a mobile device.
  • I would not set the default to landscape. It also leads to confusions the first time someone looks at the mobile version of the game.
  • Wouldn't it be better to provide a script that wraps (trapeze.dev or similar) and not to add all the android/ios file into the repo?

I would prefere a 1000 time a config based setup instead of adding all files to the repo.


I have never used trapeze.dev before, but in my html2app.dev I use the following. I'm sure there is an equivalent for trapeze?

const isPortrait = options.includes('--portrait')
const isLandscape = options.includes('--landscape')

if (!isLandscape && !isPortrait) return

// https://capacitorjs.com/docs/guides/screen-orientation
// https://developer.apple.com/documentation/bundleresources/information_property_list/uisupportedinterfaceorientations
const config = {
  platforms: {
    ios: {
      targets: {
        App: {
          plist: {
            replace: true,
            entries: [
              {
                UISupportedInterfaceOrientations: isPortrait
                  ? ['UIInterfaceOrientationPortrait']
                  : ['UIInterfaceOrientationLandscapeRight', 'UIInterfaceOrientationLandscapeLeft']
              }
            ]
          }
        }
      }
    },
    android: {
      manifest: [
        {
          file: 'AndroidManifest.xml',
          target: 'manifest/application/activity',
          attrs: {
            'android:screenOrientation': isPortrait ? 'portrait' : 'landscape'
          }
        }
      ]
    }
  }
}

and for fullscreen I do:

await RUN('npm install --ignore-scripts @yandeu/capacitor-fullscreen --force')

// status bar hidden (https://stackoverflow.com/a/20536695)
const config = {
  platforms: {
    ios: {
      targets: {
        App: {
          plist: {
            replace: true,
            entries: [
              {
                UIStatusBarHidden: true
              },
              {
                UIViewControllerBasedStatusBarAppearance: false
              }
            ]
          }
        }
      }
    }
  }
}

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