exporting.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. .. _doc_exporting_dtc:
  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. $Collision.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. $Trail.emitting = true
  76. else:
  77. $AnimatedSprite.stop()
  78. $Trail.emitting = false
  79. position += velocity * delta
  80. # We don't need to clamp the player's position
  81. # because you can't click outside the screen
  82. # position.x = clamp(position.x, 0, screensize.x)
  83. # position.y = clamp(position.y, 0, screensize.y)
  84. if velocity.x != 0:
  85. $AnimatedSprite.animation = "right"
  86. $AnimatedSprite.flip_v = false
  87. $AnimatedSprite.flip_h = velocity.x < 0
  88. elif velocity.y != 0:
  89. $AnimatedSprite.animation = "up"
  90. $AnimatedSprite.flip_v = velocity.y > 0
  91. func _on_Player_body_entered( body ):
  92. $Collision.disabled = true
  93. hide()
  94. emit_signal("hit")
  95. Export Templates
  96. ----------------
  97. In order to export, you need to download the *export templates* from the
  98. http://godotengine.org/download. These templates are optimized versions of the engine
  99. without the editor pre-compiled for each platform . You can also
  100. download them in Godot by clicking on *Editor -> Manage Export Templates*:
  101. .. image:: img/export_template_menu.png
  102. In the window that appears, you can click "Download" to get the template
  103. version that matches your version of Godot.
  104. .. image:: img/export_template_manager.png
  105. .. note:: If you upgrade Godot, you must download templates that match the new version
  106. or your exported projects may not work correctly.
  107. Export Presets
  108. --------------
  109. Next, you can configure the export settings by clicking on *Project -> Export*:
  110. .. image:: img/export_presets_window.png
  111. Create a new export preset by clicking "Add..." and selecting a platform. You
  112. can make as many presets as you like with different settings.
  113. At the bottom of the window are two buttons. "Export PCK/ZIP" only creates
  114. a packed version of your project's data. This doesn't include an executable
  115. so the project can't be run on its own.
  116. The second button, "Export Project", creates a complete executable version
  117. of your game, such as an `.apk` for Android or an `.exe` for Windows.
  118. In the "Resources" and "Features" tabs you can customize how the game is
  119. exported for each platform. We can leave those settings alone for now.
  120. Exporting by Platform
  121. ---------------------
  122. In this section, we'll walk through the process for each platform,
  123. including any additional software or requirements you'll need.
  124. PC (Linux/MacOS/Windows)
  125. ~~~~~~~~~~~~~~~~~~~~~~~~
  126. Exporting PC platforms works the same across the three supported operating
  127. systems. Open the export window and click "Add.." to create the preset(s) you
  128. want to make. Then click "Export Project" and choose a name and destination
  129. folder. Choose a location *outside* of your project folder.
  130. Click "Save" and the engine will build the export files.
  131. .. note:: When exporting for MacOS, if you export on a MacOS computer, you'll
  132. end up with a `.dmg` file, while using Linux or Windows
  133. produces a `.zip`. In either case, the compressed file contains
  134. a MacOS `.app` that you can double-click and run.
  135. .. note:: On Windows, if you want your exported executable to have a different
  136. icon than the default one, you need to change it manually. See:
  137. :ref:`doc_changing_application_icon_for_windows`.
  138. Android
  139. ~~~~~~~
  140. .. tip:: Mobile devices come with a wide variety of capabilities.
  141. In most cases, Godot's default settings will work, but mobile
  142. development is sometimes more art than science, and you may
  143. need to do some experimenting and searching for help in order
  144. to get everything working.
  145. Before you can export your project for Android, you must download the following
  146. software:
  147. * Android SDK: https://developer.android.com/studio/
  148. * Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html
  149. When you run Android Studio for the first time, click on *Configure -> SDK Manager*
  150. and install "Android SDK Platform Tools". This installs the `adb` command-line
  151. tool that Godot uses to communicate with your device.
  152. Next, create a debug keystore with by running the following command on your
  153. system's command line:
  154. ::
  155. keytool -keyalg RSA -genkeypair -alias androiddebugkey -keypass android -keystore debug.keystore -storepass android -dname "CN=Android Debug,O=Android,C=US" -validity 9999
  156. Click on *Editor -> Editor Settings* in Godot and select the *Export/Android*
  157. section. Here, you need to set the paths to the Android SDK applications on
  158. your system and the location of the keystore you just created.
  159. .. image:: img/export_editor_android_settings.png
  160. Now you're ready to export. Click on *Project -> Export* and add a preset
  161. for Android (see above).
  162. Click the "Export Project" button and Godot will build an APK you can download
  163. on your device. To do this on the command line, use the following:
  164. ::
  165. adb install dodge.apk
  166. .. note:: Your device may need to be in *developer mode*. Consult your
  167. device's documentation for details.
  168. If your system supports it, connecting a compatible Android device will cause
  169. a "One-click Deploy" button to appear in Godot's playtest button area:
  170. .. image:: img/export_android_oneclick.png
  171. Clicking this button builds the APK and copies it onto your device in one step.
  172. iOS
  173. ~~~
  174. .. note:: In order to build your game for iOS, you must have a computer running
  175. MacOS with Xcode installed.
  176. Before exporting, there are some settings that you *must* complete for the project
  177. to export successfully. First, the "App Store Team Id", which you can find by
  178. logging in to your Apple developer account and looking in the "Membership" section.
  179. You must also provide icons and splash screen images as shown below:
  180. .. image:: img/export_ios_settings.png
  181. Click "Export Project" and select a destination folder.
  182. Once you have successfully exported the project, you'll find the following
  183. folders and files have been created in your selected location:
  184. .. image:: img/export_xcode_project_folders.png
  185. You can now open the project in Xcode and build the project for iOS. Xcode
  186. build procedure is beyond the scope of this tutorial. See
  187. https://help.apple.com/xcode/mac/current/#/devc8c2a6be1 for
  188. more information.
  189. HTML5 (web)
  190. ~~~~~~~~~~~
  191. Click "Export Project" on the HTML5 preset. We don't need to change any
  192. of the default settings.
  193. When the export is complete, you'll have a folder containing the following
  194. files:
  195. .. image:: img/export_web_files.png
  196. Viewing the `.html` file in your browser lets you play the game. However, you
  197. can't open the file directly, it neds to be served by a web server. If you don't
  198. have one set up on your computer, you can use Google to find suggestions for
  199. your specific OS.
  200. Point your browser at the URL where you've placed the html file. You may have
  201. to wait a few moments while the game loads before you see the start screen.
  202. .. image:: img/export_web_example.png
  203. The console window beneath the game tells you if anything goes wrong. You can
  204. disable it by setting "Export With Debug" off when you export the project.
  205. .. note:: Browser support for WASM is not very widespread. Firefox and Chrome
  206. both support it, but you may still find some things that don't work.
  207. Make sure you have updated your browser to the most recent version,
  208. and report any bugs you find at the `Godot Github repository <https://github.com/godotengine/godot/issues>`_.