Exporting

Overview

Now that you have a working game, you probably want to share your success withothers. However, it's not practical to ask your friends to download Godotjust so they can open your project. Instead, you canexport your project,converting it into a "package" that can be run by anyone.

The way you export your game depends on what platform you are targeting. Inthis tutorial, you'll learn how to export theDodge the Creeps game for avariety of platforms. First, however, we need to make some changes to theway the game works.

Note

If you haven't made "Dodge the Creeps" yourself yet, please readYour first 2D game before continuing with this tutorial.

Preparing the project

InDodge the Creeps, we used keyboard controls to move the player's character.This is fine if your game is being played on a PC platform, but on a phoneor tablet, you need to support touchscreen input. Because a click event canbe treated the same as a touch event, we'll convert the game to a click-and-moveinput style.

By default, Godot emulates mouse input from touch input. That means that ifanything is coded to happen on a mouse event, touch will trigger it as well.Godot can also emulate touch input from mouse clicks, which we will need to beable to keep playing our game on our computer after we switch to touch input.

InProject > Project Settings, underInput Devices > Pointing, enableEmulate Touch From Mouse.

../../_images/export_touchsettings.png

We also want to ensure that the game scales consistently on different-sized screens,so in the project settings go toDisplay, then click onWindow. In theStretchoptions, setMode to2d andAspect tokeep.

Since we are already in theWindow settings, we should also set underHandheldtheOrientation toportrait.

../../_images/export_handheld_stretchsettings.png

Next, we need to modify thePlayer.gd script to change the input method.We'll remove the key inputs and make the player move towards a "target" that'sset by the touch (or click) event.

Here is the full script for the player, with comments noting what we'vechanged:

extendsArea2Dsignalhitexportvarspeed=400varscreen_size# Add this variable to hold the clicked position.vartarget=Vector2()func_ready():hide()screen_size=get_viewport_rect().sizefuncstart(pos):position=pos# Initial target is the start position.target=posshow()$CollisionShape2D.disabled=false# Change the target whenever a touch event happens.func_input(event):ifeventisInputEventScreenTouchandevent.pressed:target=event.positionfunc_process(delta):varvelocity=Vector2()# Move towards the target and stop when close.ifposition.distance_to(target)>10:velocity=target-position# Remove keyboard controls.#    if Input.is_action_pressed("ui_right"):#       velocity.x += 1#    if Input.is_action_pressed("ui_left"):#        velocity.x -= 1#    if Input.is_action_pressed("ui_down"):#        velocity.y += 1#    if Input.is_action_pressed("ui_up"):#        velocity.y -= 1ifvelocity.length()>0:velocity=velocity.normalized()*speed$AnimatedSprite.play()else:$AnimatedSprite.stop()position+=velocity*delta# We still need to clamp the player's position here because on devices that don't# match your game's aspect ratio, Godot will try to maintain it as much as possible# by creating black borders, if necessary.# Without clamp(), the player would be able to move under those borders.position.x=clamp(position.x,0,screen_size.x)position.y=clamp(position.y,0,screen_size.y)ifvelocity.x!=0:$AnimatedSprite.animation="walk"$AnimatedSprite.flip_v=false$AnimatedSprite.flip_h=velocity.x<0elifvelocity.y!=0:$AnimatedSprite.animation="up"$AnimatedSprite.flip_v=velocity.y>0func_on_Player_body_entered(body):hide()emit_signal("hit")$CollisionShape2D.set_deferred("disabled",true)

Setting a main scene

The main scene is the one that your game will start in. For thisDodge the Creeps example, inProject -> Project Settings -> Application -> Run, setMain ScenetoMain.tscn by clicking the folder icon and selecting it.

Export templates

To export the project, you need to download theexport templates from thehttp://godotengine.org/download. These templates are optimized versions of the enginewithout the editor pre-compiled for each platform. You can alsodownload them in Godot by clicking onEditor -> Manage Export Templates:

../../_images/export_template_menu.png

Note

If you've downloaded Godot fromSteam,export templates are already included. Therefore, you don't need to downloadthem using theManage Export Templates dialog.

In the window that appears, you can clickDownload to get the templateversion that matches your version of Godot.

../../_images/export_template_manager.png

Note

Export templates are bound to a specific Godot version. If you upgradeGodot, you must download templates that match the new version.

Export presets

Next, you can configure the export settings by clicking onProject -> Export.

Create a new export preset by clickingAdd... and selecting a platform. Youcan make as many presets as you like with different settings.

../../_images/export_presets_window.png

At the bottom of the window are two buttons.Export PCK/ZIP only createsa packed version of your project's data. This doesn't include an executableso the project can't be run on its own.

The second button,Export Project, creates a complete executable versionof your game, such as an.apk for Android or an.exe for Windows.

In theResources andFeatures tabs, you can customize how the game isexported for each platform. We can leave those settings alone for now.

Exporting by platform

In this section, we'll walk through the process for each platform,including any additional software or requirements you'll need.

PC (Linux/macOS/Windows)

Exporting PC platforms works the same across the three supported operatingsystems. Open the export window and clickAdd... to create the preset(s) youwant to make. Then clickExport Project and choose a name and destinationfolder. Choose a locationoutside of your project folder.

ClickSave and the engine will build the export files.

Note

When exporting for macOS, if you export from a macOS computer, you'll end upwith a.dmg file, while using Linux or Windows produces a.zip. Ineither case, the compressed file contains a macOS.app that you candouble-click and run.

Note

On Windows, if you want your exported executable to have a different iconthan the default one, you need to change it manually. SeeChanging application icon for Windows.

Android

Tip

Mobile devices come with a wide variety of capabilities. In most cases,Godot's default settings will work, but mobile development is sometimes moreart than science, and you may need to do some experimenting and searchingfor help in order to get everything working.

Before you can export your project for Android, you must download the followingsoftware:

When you run Android Studio for the first time, click onConfigure -> SDK Managerand installAndroid SDK Platform Tools. This installs theadbcommand-line tool that Godot uses to communicate with your device.

Next, create a debug keystore by running the following command on yoursystem's command line:

keytool-keyalgRSA-genkeypair-aliasandroiddebugkey-keypassandroid-keystoredebug.keystore-storepassandroid-dname"CN=Android Debug,O=Android,C=US"-validity9999

Click onEditor -> Editor Settings in Godot and select theExport/Androidsection. Here, you need to set the paths to the Android SDK applications onyour system and the location of the keystore you just created.

../../_images/export_editor_android_settings.png

Now you're ready to export. Click onProject -> Export and add a presetfor Android (see above). Select the newly added Android preset. UnderOptions,go toScreen and setOrientation toPortrait. If your game is inlandscape mode (i.e. the window width in pixels is greater than the window height),leave this onLandscape.

Click theExport Project button and Godot will build an APK you can downloadon your device. To do this on the command line, use the following:

adbinstalldodge.apk

Note

Your device may need to be indeveloper mode. Consult yourdevice's documentation for details.

If your system supports it, connecting a compatible Android device will causeaOne-click Deploy button to appear in Godot's playtest button area:

../../_images/export_android_oneclick.png

Clicking this button builds the APK and copies it onto your device in one step.

iOS

Note

To build your game for iOS, you must have a computer running macOS withXcode installed.

Before exporting, there are some settings that youmust complete for the projectto export successfully. First, theApp Store Team Id, which you can find bylogging in to your Apple developer account and looking in theMembership section.

You must also provide icons and splash screen images as shown below:

../../_images/export_ios_settings.png

ClickExport Project and select a destination folder.

Once you have successfully exported the project, you'll find the followingfolders and files have been created in your selected location:

../../_images/export_xcode_project_folders.png

You can now open the project in Xcode and build the project for iOS.The Xcode build procedure is beyond the scope of this tutorial.Seehttps://help.apple.com/xcode/mac/current/#/devc8c2a6be1for more information.

HTML5 (web)

ClickExport Project on the HTML5 preset. We don't need to change anyof the default settings.

When the export is complete, you'll have a folder containing the followingfiles:

../../_images/export_web_files.png

Viewing the.html file in your browser lets you play the game. However, youcan't open the file directly. Instead, it needs to be served by a web server. Ifyou don't have one set up on your computer, you can search online to findsuggestions for your specific OS.

Point your browser at the URL where you've placed the HTML file. You may haveto wait a few moments while the game loads before you see the start screen.

../../_images/export_web_example.png

The console window beneath the game tells you if anything goes wrong. You candisable it by disablingExport With Debug in the final file dialog that appearswhen you export the project.

../../_images/export_web_export_with_debug_disabled.png

Note

While WebAssembly is supported in all major browsers, it is still anemerging technology and you may find some things that don't work. Make sureyou have updated your browser to the most recent version, and report anybugs you find on theGodot GitHub repository.