Skip to content

Discussion on supporting rotatable games #1093

Open
@andykorth

Description

@andykorth

Cocos2D currently has some limited support for games that can change orientation while the game is running. I did a test implementation with Galactic Guardian.

Overall, it was pretty easy to get working. You can change the device orientation on any screen in the game, and most things are currently working. (See below).

Changes required in cocos2d:

  • Fix viewDidResizeTo should use points instead of pixels #1091
  • Content size changes are not recursive. Only direct children are informed of content size changes currently. Here's the quick hack I used to get the project working: andykorth@063b9a8
    • The already-planned event based content size notification system will make this unnecessary. (Subscribing notes with ui transform delegates will receive content size change events if their parent is resized)

User will still be responsible for:

  • Using the correct positionTypes and reference corners of their UI elements.
  • Implement viewDidResizeTo: on events that need to be notified of the new orientation size.
  • Render textures may need to be resized. (When pausing, this game is rendered to a buffer, blurred, and this is shown behind the pause screen. If you rotate while paused, I guess you should re-render the rotated game into the buffer. Do-able, but too much work for the demo.)

Spritebuilder requires:

  • SpriteBuilder needs to expose the CCScreenOrientationAll option, instead of just landscape OR portrait options.

Streamlining the process in v4:

  • You can lay things out in spritebuilder with normalized coordinates, but you can't change their scale when their parent gets smaller. Proportional content sizes are often enough to handle this situation, but sometimes you would rather scale content than reduce the content size. (I can expand on this, if the distinction doesn't make a lot of sense)
    • Labels are one particular case- you might want the font size on some elements to shrink when the game is rotated. The "Adjusts font size to fit" option only triggers when the label is initially added, not when it's resized.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions