12. Cross-Platform Deployment

Defold Platformer Framework
# 12. Cross-Platform Deployment When developing games with Defold, one of the major advantages is the ability to deploy your platformer to multiple platforms from a single codebase. This section covers the essentials of preparing your platformer for cross-platform deployment, handling platform-specific considerations, and optimizing your game for different devices. ## Supported Platforms Defold supports deployment to a wide range of platforms: - Desktop: Windows, macOS, Linux - Mobile: iOS, Android - Web: HTML5 - Console: Nintendo Switch (requires special access) ```mermaid graph LR A[Defold Project] --> B[Desktop] A --> C[Mobile] A --> D[Web] A --> E[Console] B --> B1[Windows] B --> B2[macOS] B --> B3[Linux] C --> C1[iOS] C --> C2[Android] D --> D1[HTML5] E --> E1[Nintendo Switch] ``` ## Setting Up Your Project for Cross-Platform Deployment ### Game.project Configuration The `game.project` file is central to configuring your game for different platforms. Here are key sections to pay attention to: #### Display Settings ``` [display] width = 1280 height = 720 high_dpi = 1 ``` Consider how your game will appear on different screen sizes and aspect ratios. For platformers, you may want to: - Use a camera system that adapts to different screen sizes - Design UI elements that scale appropriately - Test on various aspect ratios (16:9, 4:3, 21:9, etc.) #### Platform-Specific Settings ``` [ios] app_icon_120x120 = /assets/app_icons/icon_120.png app_icon_180x180 = /assets/app_icons/icon_180.png [android] package = com.example.mygame version_code = 1 ``` Each platform has its own section in the `game.project` file where you can specify platform-specific requirements. ## Input Handling Across Platforms Platformers require responsive controls, which can vary significantly across devices: ### Input Mapping Strategy ```lua -- Example of adaptive input handling function init(self) -- Detect platform local system_name = sys.get_sys_info().system_name if system_name == "iPhone OS" or system_name == "Android" then -- Mobile controls msg.post(".", "acquire_input_focus") self.using_touch_controls = true else -- Desktop controls self.using_touch_controls = false end end function on_input(self, action_id, action) if self.using_touch_controls then -- Handle touch input else -- Handle keyboard/gamepad input end end ``` ### Input Considerations by Platform | Platform | Primary Input Methods | Considerations | |----------|----------------------|----------------| | Desktop | Keyboard, Gamepad | Support both arrow keys and WASD | | Mobile | Touch screen | Implement virtual buttons or gesture controls | | Web | Keyboard, Touch (on tablets) | Consider browser-specific input handling | | Console | Gamepad | Follow platform-specific controller guidelines | ## Performance Optimization Different platforms have varying hardware capabilities. Here are strategies to ensure your platformer runs well everywhere: ### Adaptive Performance Settings ```lua function init(self) local sys_info = sys.get_sys_info() -- Determine device tier if sys_info.system_name == "Android" or sys_info.system_name == "iPhone OS" then -- Check device capabilities if sys_info.device_model:match("low_end_device") then -- Apply low-end settings self.particle_count = 10 self.max_enemies = 5 else -- Apply high-end settings self.particle_count = 50 self.max_enemies = 15 end else -- Desktop/console settings self.particle_count = 100 self.max_enemies = 20 end end ``` ### Performance Tips 1. **Asset Management**: - Use texture atlases to reduce draw calls - Implement different asset quality levels for different platforms - Consider dynamic asset loading for mobile platforms 2. **Physics Optimization**: - Reduce collision complexity on mobile - Use simplified physics for off-screen objects - Consider using kinematic bodies instead of dynamic ones when possible 3. **Memory Management**: - Be mindful of memory limitations on mobile devices - Implement asset unloading when levels change - Profile memory usage regularly ## Platform-Specific Features ### Mobile-Specific Considerations ```lua -- Example of handling mobile interruptions function on_message(self, message_id, message, sender) if message_id == hash("application_status") then if message.status == "backgrounded" then -- Game is going to background msg.post("main:/sound", "pause_all_sounds") -- Pause game state elseif message.status == "foregrounded" then -- Game is coming back to foreground -- Show "tap to continue" message end end end ``` Mobile platforms require special attention to: - Battery usage - Touch control responsiveness - Application lifecycle (background/foreground transitions) - Screen notches and safe areas ### Web Platform Considerations When deploying to HTML5: - Handle browser back button - Consider loading times and progressive loading - Implement proper sound handling (requires user interaction first) - Test across different browsers ## Building and Testing ### Automated Testing Across Platforms Consider implementing automated testing to ensure your platformer works correctly across platforms: ```mermaid flowchart TD A[Development] --> B[Automated Tests] B --> C{All Tests Pass?} C -->|Yes| D[Build for All Platforms] C -->|No| A D --> E[Platform-Specific Testing] E --> F{Issues Found?} F -->|Yes| A F -->|No| G[Release] ``` ### Build Process For efficient cross-platform deployment, establish a build pipeline: 1. **Set up build variants** in your `game.project` file 2. **Create platform-specific assets** (icons, splash screens) 3. **Configure platform credentials** (signing certificates, API keys) 4. **Use Defold's build server** or set up your own CI/CD pipeline ## Distribution Channels Each platform has its own distribution requirements: | Platform | Distribution Channels | Key Requirements | |----------|----------------------|------------------| | iOS | App Store | App review process, certificates | | Android | Google Play, Alternative stores | Signing, store listings | | Desktop | Steam, Epic, itch.io, direct | Platform-specific builds | | Web | Own website, game portals | Browser compatibility | ## Monetization Across Platforms If your platformer includes monetization, consider platform differences: ```mermaid graph TD A[Monetization Strategy] --> B[Platform-Specific Implementation] B --> C[iOS In-App Purchases] B --> D[Google Play Billing] B --> E[Steam Microtransactions] B --> F[Web Payments] C & D & E & F --> G[Unified Game Economy] ``` - Implement a platform-agnostic virtual currency system - Use conditional compilation for platform-specific payment code - Consider regional pricing and payment method availability ## Conclusion Cross-platform deployment with Defold offers tremendous advantages for your platformer, allowing you to reach players across multiple devices with a single codebase. By planning ahead for platform differences and implementing adaptive strategies for input, performance, and monetization, you can create a seamless experience regardless of where your game is played. Remember to test thoroughly on each target platform and gather feedback from users on different devices to ensure your platformer delivers a consistent, high-quality experience everywhere.