exporting.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. .. _doc_exporting:
  2. Exporting
  3. =========
  4. Overview
  5. --------
  6. Now that you have a working game, you probably want to share your success with
  7. others. However, it's not practical to ask your friends to download Godot
  8. just so they can open your project. Instead, you can *export* your project,
  9. converting it into a "package" that can be run by anyone.
  10. The way you export your game depends on what platform you are targeting. In
  11. this tutorial, you'll learn how to export the "Dodge the Creeps" game for a
  12. variety of platforms. First, however, we need to make some changes to the
  13. way the game works.
  14. .. note:: If you haven't made "Dodge the Creeps" yourself yet, please read
  15. :ref:`doc_your_first_game` before continuing with this tutorial.
  16. Preparing the project
  17. ---------------------
  18. In "Dodge the Creeps" we used keyboard controls to move the player's character.
  19. This is fine if your game is being played on a PC platform, but on a phone
  20. or tablet, you need to support touchscreen input. Because a click event can
  21. be treated the same as a touch event, we'll convert the game to a click-and-move
  22. input style.
  23. The first step is to open "Project Settings" and find the *Handheld* section.
  24. Enable the *Emulate Touchscreen* option. This lets you treat mouse click
  25. events the same as touch events, so you can test the game on a computer without
  26. a touchscreen. Also, make sure to select "portrait" under *Orientation*.
  27. In the *Stretch* section, set *Mode* to "2d" and *Aspect* to "keep". This
  28. ensures that the game scales consistently on different sized screens.
  29. .. image:: img/export_touchsettings.png
  30. Next, we need to modify the ``Player.gd`` script to change the input method.
  31. We'll remove the key inputs and make the player move towards a "target" that's
  32. set by the touch (or click) event.
  33. Here is the full script for the player, with comments noting what we've
  34. changed:
  35. .. tabs::
  36. .. code-tab:: gdscript GDScript
  37. extends Area2D
  38. signal hit
  39. export (int) var speed
  40. var velocity = Vector2()
  41. var screensize
  42. # Add this variable to hold the clicked position.
  43. var target = Vector2()
  44. func _ready():
  45. hide()
  46. screensize = get_viewport_rect().size
  47. func start(pos):
  48. position = pos
  49. # Initial target is the start position.
  50. target = pos
  51. show()
  52. $CollisionShape2D.disabled = false
  53. # Change the target whenever a touch event happens.
  54. func _input(event):
  55. if event is InputEventScreenTouch and event.pressed:
  56. target = event.position
  57. func _process(delta):
  58. # Move towards the target and stop when close.
  59. if position.distance_to(target) > 10:
  60. velocity = (target - position).normalized() * speed
  61. else:
  62. velocity = Vector2()
  63. # Remove keyboard controls.
  64. # if Input.is_action_pressed("ui_right"):
  65. # velocity.x += 1
  66. # if Input.is_action_pressed("ui_left"):
  67. # velocity.x -= 1
  68. # if Input.is_action_pressed("ui_down"):
  69. # velocity.y += 1
  70. # if Input.is_action_pressed("ui_up"):
  71. # velocity.y -= 1
  72. if velocity.length() > 0:
  73. velocity = velocity.normalized() * speed
  74. $AnimatedSprite.play()
  75. else:
  76. $AnimatedSprite.stop()
  77. position += velocity * delta
  78. # We don't need to clamp the player's position
  79. # because you can't click outside the screen.
  80. # position.x = clamp(position.x, 0, screensize.x)
  81. # position.y = clamp(position.y, 0, screensize.y)
  82. if velocity.x != 0:
  83. $AnimatedSprite.animation = "right"
  84. $AnimatedSprite.flip_v = false
  85. $AnimatedSprite.flip_h = velocity.x < 0
  86. elif velocity.y != 0:
  87. $AnimatedSprite.animation = "up"
  88. $AnimatedSprite.flip_v = velocity.y > 0
  89. func _on_Player_body_entered( body ):
  90. $Collision.disabled = true
  91. hide()
  92. emit_signal("hit")
  93. Export templates
  94. ----------------
  95. In order to export, you need to download the *export templates* from the
  96. http://godotengine.org/download. These templates are optimized versions of the engine
  97. without the editor pre-compiled for each platform . You can also
  98. download them in Godot by clicking on *Editor -> Manage Export Templates*:
  99. .. image:: img/export_template_menu.png
  100. In the window that appears, you can click "Download" to get the template
  101. version that matches your version of Godot.
  102. .. image:: img/export_template_manager.png
  103. .. note:: If you upgrade Godot, you must download templates that match the new version
  104. or your exported projects may not work correctly.
  105. Export presets
  106. --------------
  107. Next, you can configure the export settings by clicking on *Project -> Export*:
  108. .. image:: img/export_presets_window.png
  109. Create a new export preset by clicking "Add..." and selecting a platform. You
  110. can make as many presets as you like with different settings.
  111. At the bottom of the window are two buttons. "Export PCK/ZIP" only creates
  112. a packed version of your project's data. This doesn't include an executable
  113. so the project can't be run on its own.
  114. The second button, "Export Project", creates a complete executable version
  115. of your game, such as an `.apk` for Android or an `.exe` for Windows.
  116. In the "Resources" and "Features" tabs, you can customize how the game is
  117. exported for each platform. We can leave those settings alone for now.
  118. Exporting by platform
  119. ---------------------
  120. In this section, we'll walk through the process for each platform,
  121. including any additional software or requirements you'll need.
  122. PC (Linux/macOS/Windows)
  123. ~~~~~~~~~~~~~~~~~~~~~~~~
  124. Exporting PC platforms works the same across the three supported operating
  125. systems. Open the export window and click "Add.." to create the preset(s) you
  126. want to make. Then click "Export Project" and choose a name and destination
  127. folder. Choose a location *outside* of your project folder.
  128. Click "Save" and the engine will build the export files.
  129. .. note:: When exporting for macOS, if you export on a macOS computer, you'll
  130. end up with a `.dmg` file, while using Linux or Windows
  131. produces a `.zip`. In either case, the compressed file contains
  132. a macOS `.app` that you can double-click and run.
  133. .. note:: On Windows, if you want your exported executable to have a different
  134. icon than the default one, you need to change it manually. See:
  135. :ref:`doc_changing_application_icon_for_windows`.
  136. Android
  137. ~~~~~~~
  138. .. tip:: Mobile devices come with a wide variety of capabilities.
  139. In most cases, Godot's default settings will work, but mobile
  140. development is sometimes more art than science, and you may
  141. need to do some experimenting and searching for help in order
  142. to get everything working.
  143. Before you can export your project for Android, you must download the following
  144. software:
  145. * Android SDK: https://developer.android.com/studio/
  146. * Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html
  147. When you run Android Studio for the first time, click on *Configure -> SDK Manager*
  148. and install "Android SDK Platform Tools". This installs the `adb` command-line
  149. tool that Godot uses to communicate with your device.
  150. Next, create a debug keystore by running the following command on your
  151. system's command line:
  152. ::
  153. keytool -keyalg RSA -genkeypair -alias androiddebugkey -keypass android -keystore debug.keystore -storepass android -dname "CN=Android Debug,O=Android,C=US" -validity 9999
  154. Click on *Editor -> Editor Settings* in Godot and select the *Export/Android*
  155. section. Here, you need to set the paths to the Android SDK applications on
  156. your system and the location of the keystore you just created.
  157. .. image:: img/export_editor_android_settings.png
  158. Now you're ready to export. Click on *Project -> Export* and add a preset
  159. for Android (see above).
  160. Click the "Export Project" button and Godot will build an APK you can download
  161. on your device. To do this on the command line, use the following:
  162. ::
  163. adb install dodge.apk
  164. .. note:: Your device may need to be in *developer mode*. Consult your
  165. device's documentation for details.
  166. If your system supports it, connecting a compatible Android device will cause
  167. a "One-click Deploy" button to appear in Godot's playtest button area:
  168. .. image:: img/export_android_oneclick.png
  169. Clicking this button builds the APK and copies it onto your device in one step.
  170. iOS
  171. ~~~
  172. .. note:: In order to build your game for iOS, you must have a computer running
  173. macOS with Xcode installed.
  174. Before exporting, there are some settings that you *must* complete for the project
  175. to export successfully. First, the "App Store Team Id", which you can find by
  176. logging in to your Apple developer account and looking in the "Membership" section.
  177. You must also provide icons and splash screen images as shown below:
  178. .. image:: img/export_ios_settings.png
  179. Click "Export Project" and select a destination folder.
  180. Once you have successfully exported the project, you'll find the following
  181. folders and files have been created in your selected location:
  182. .. image:: img/export_xcode_project_folders.png
  183. You can now open the project in Xcode and build the project for iOS. Xcode
  184. build procedure is beyond the scope of this tutorial. See
  185. https://help.apple.com/xcode/mac/current/#/devc8c2a6be1 for
  186. more information.
  187. HTML5 (web)
  188. ~~~~~~~~~~~
  189. Click "Export Project" on the HTML5 preset. We don't need to change any
  190. of the default settings.
  191. When the export is complete, you'll have a folder containing the following
  192. files:
  193. .. image:: img/export_web_files.png
  194. Viewing the `.html` file in your browser lets you play the game. However, you
  195. can't open the file directly, it needs to be served by a web server. If you don't
  196. have one set up on your computer, you can use Google to find suggestions for
  197. your specific OS.
  198. Point your browser at the URL where you've placed the html file. You may have
  199. to wait a few moments while the game loads before you see the start screen.
  200. .. image:: img/export_web_example.png
  201. The console window beneath the game tells you if anything goes wrong. You can
  202. disable it by setting "Export With Debug" off when you export the project.
  203. .. note:: Browser support for WASM is not very widespread. Firefox and Chrome
  204. both support it, but you may still find some things that don't work.
  205. Make sure you have updated your browser to the most recent version,
  206. and report any bugs you find at the `Godot Github repository <https://github.com/godotengine/godot/issues>`_.