Difference between revisions of "Getting Started"

(获得 LÖVE)
m (Don't hardcode link to LOVE wiki. Link to Main Page instead.)
(33 intermediate revisions by 15 users not shown)
Line 1: Line 1:
 
== Get LÖVE ==
 
== Get LÖVE ==
  
You can download the newest edition LÖVE from [http://love2d.org/#download Web sites], and install it. If you use windows, you can not 'install" LÖVE, just download the compressed zip fomat LÖVE,then extract anywhere.
+
Download the latest version of LÖVE from [http://love2d.org/#download the website], and install it. If you're on Windows and don't want to ''install'' LÖVE, you can also just download the zipped executables and extract them anywhere.
  
You can check the edition of LÖVE that installed, use follow command:
+
To find out which version of LÖVE is installed, run the following command:
  
<code>
+
<source lang="bash">
 
love --version
 
love --version
</code>
+
</source>
  
== Make a Game ==
+
== Making a Game ==
  
To make a minimal game, create a folder anywhere, and open up your favorite code editor. Notepad++ is a pretty good one for Windows, and it has Lua support built in. Create a new file in the folder you just created, and name it main.lua. Put the following code in the file, and save it.  
+
To make a minimal game, create a folder anywhere, and open up your favorite text editor. [http://www.sublimetext.com Sublime Text] is a pretty good one for all operating systems, and it has Lua support built in. Create a new file in the folder you just created, and name it <code>main.lua</code>. Put the following code in the file, and save it.
  
 
<source lang="lua">
 
<source lang="lua">
Line 22: Line 22:
  
 
LÖVE can load a game in two ways:
 
LÖVE can load a game in two ways:
* From a folder.  
+
* From a folder that contains a main.lua file.
* From a .love file (a renamed .zip-file).
+
* From a [[LÖVE Game File|.love file]] that has a main.lua file in the top-most directory level (aka root)
+
 
In both cases, there has to be a file called <code>main.lua</code> in the root path. This file will be loaded when LÖVE starts. If this file is missing, LÖVE will not recognize the folder or .love file as game, and it will complain about a wrongly packaged game. A frequently made mistake is zipping the folder rather than its contents. This stems from very old practice (because when you unzip a folder you don't want it to splash out all over your current directory), but for LÖVE doing that doesn't make sense: you need to zip the game folder's contents '''only''', to get a correct .love.
+
For creating .love files see [[Game Distribution]].
  
 +
----
 
===Windows===
 
===Windows===
  
On Windows, the easiest way to run the game is to drag the folder onto love.exe, or a shortcut to love.exe. Remember to drag the folder containing <code>main.lua</code>, and not <code>main.lua</code> itself.
+
[http://studio.zerobrane.com ZeroBrane Studio], [[Sublime Text 2]], [[Notepad++]], and [[SciTE]] allow you to launch the game from within their code editors.
There's also the [[Scite]] option.
 
  
You can also call it from command line:
+
Otherwise, the easiest way to run the game is to drag the folder onto either love.exe or a shortcut to love.exe. Remember to drag the folder containing <code>main.lua</code>, and not <code>main.lua</code> itself.
  
For instance:
+
You can also launch the game from the command line:
<pre>
 
love C:\games\mygame
 
love C:\games\packagedgame.love
 
</pre>
 
  
On Windows, there is a special option which will attach a console to the Window. This allows you to see standard output.
+
<source lang="powershell">
 +
"C:\Program Files\LOVE\love.exe" "C:\games\mygame"
 +
"C:\Program Files\LOVE\love.exe" "C:\games\packagedgame.love"
 +
</source>
  
<code>
+
You can create a shortcut to do this; simply make a shortcut to love.exe, right-click on it and select "Properties", and then put the command line you want in the "Target" box for the shortcut.
love --console
 
</code>
 
  
 +
On Windows, there is a special command-line option which will attach a console to the window, allowing you to see the result of <code>print</code> calls (equivalent to setting <code>t.console=true</code> in [[conf.lua]]):
 +
<source lang="bash">
 +
"C:\Program Files\LOVE\love.exe" --console
 +
</source>
 +
 +
----
 
===Linux===
 
===Linux===
  
On Linux, you can use the command line:
+
On Linux, you can use one of these command lines:
  
<pre>
+
<source lang="bash">
love /home/path/to/game
+
love /home/path/to/gamedir/
 
love /home/path/to/packagedgame.love
 
love /home/path/to/packagedgame.love
</pre>
+
</source>
  
If you have installed the .deb, you can double click on .love files in your file manager as well.
+
If you installed LÖVE system-wide, you can double click on .love files in your file manager as well.
  
===Mac OSX===
+
----
 +
=== Mac OS X ===
  
On Mac OSX, a folder or .love file can be dropped onto the Love.app application bundle. On the Mac OSX Terminal (commandline), you can use love like this (assuming it's installed to the Applications directory):
+
On Mac OS X, a folder or .love file can be dropped onto the love application bundle. On the Mac Terminal (command line), you can use love like this (assuming it's installed to the Applications directory):
  
<code>open -a love mygame</code>
+
<source lang="bash">open -n -a love "~/path/to/mygame"</source>
  
In some cases it may be faster to invoke the love binary inside the application bundle directly via the following:
+
However, the above method will not output printed text to the terminal window. To do that, you will need to execute the love binary inside the application bundle directly:  
  
<code>/Applications/love.app/Contents/MacOS/love mygame</code>
+
<source lang="bash">/Applications/love.app/Contents/MacOS/love ~/path/to/mygame</source>
  
You can setup an alias in your Terminal session to call the binary when you use <code>love</code> by adding an alias to your ~/.bash_profile (<code>open -a TextEdit ~/.bash_profile</code>):
+
You can set up an alias in your Terminal session to call the binary when you use <code>love</code> by adding an alias to your <code>~/.bash_profile</code>.
  
<pre>
+
Open the file with
 +
<source lang="bash">open -a TextEdit ~/.bash_profile</source>
 +
 
 +
You may have to run
 +
<source lang="bash">touch ~/.bash_profile</source>
 +
first if the file does not yet exist.
 +
 
 +
Then paste in the following code and save the file:
 +
<source lang="bash">
 
# alias to love
 
# alias to love
 
alias love="/Applications/love.app/Contents/MacOS/love"
 
alias love="/Applications/love.app/Contents/MacOS/love"
</pre>
+
</source>
 +
 
 +
Now you can call love from the command line like Linux and Windows:
 +
 
 +
<source lang="bash">
 +
love ~/path/to/mygame
 +
</source>
 +
 
 +
----
 +
=== Android ===
 +
As long as you have the love app installed from the playstore or another source the following methods will work:
 +
 
 +
*Method 1 Transfer your game folder to /sdcard/lovegame where main.lua is found at /sdcard/lovegame/main.lua. Then run the app.
 +
 
 +
*Method 2 Transfer a .love of your game to the device and click on it. Most file explorers will run the .love using the love app. If it does not you can install ES File Explorer which will. If you use Dropbox, you can use that to open .love files.
 +
 
 +
 
 +
----
 +
 
 +
=== iOS ===
 +
 
 +
In order to run LÖVE for iOS, it must first be compiled and installed. To do that, you’ll need Mac OS X, [https://developer.apple.com/xcode/ Xcode 7 or newer], and the LÖVE for iOS source code downloadable from the [https://love2d.org home page].
 +
 
 +
* If the <code>include</code> and <code>libraries</code> folders are not present in the <code>love/platform/xcode/ios</code> folder, [https://bitbucket.org/rude/love/downloads/love-0.10.0-ios-libraries.zip download them] and place them there. They contain the third-party library dependencies used by LÖVE.
 +
 
 +
* Open the Xcode project found at <code>love/platform/xcode/love.xcodeproj</code> and select the <code>love-ios</code> target in the dropdown menu at the top of the window.
 +
 
 +
* You may want to change the Build Configuration from Debug to Release for better performance, by opening the "Edit Scheme..." menu from the same dropdown selection.
 +
 
 +
* Choose either an iOS Simulator device or your plugged-in iOS device in the dropdown selection to the right of the previous one, and click the Build-and-Run ▶︎ button to the left, which will install LÖVE on the target device after compiling it.
 +
 
 +
LÖVE on iOS includes a simple list interface of games that are installed (until you [[Game Distribution|fuse]] a .love to it for distribution.)
 +
 
 +
* To put a .love file on the iOS Simulator after LÖVE is installed, drag the file onto the iOS Simulator’s window while it’s open. LÖVE will launch if it’s not running already. If another game is currently active you may need to quit LÖVE for the new game to show up (press Shift-Command-H twice to open the App Switcher menu on the iOS Simulator.)
  
Now you can call love from the commandline like Linux and Windows:
+
* To put a .love file or game folder on your iOS device after LÖVE is installed, you can either download it with the Safari, or transfer it from your computer through iTunes when your device is connected: open iTunes, go to the iOS device which has LÖVE installed, go to the ‘Apps’ section and scroll down and find LÖVE, and add the .love file or game folder to LÖVE’s Documents section.
  
<code>
+
See the [[Game Distribution]] page for creating Fused LÖVE games on iOS and distributing them.
love /home/path/to/game
 
</code>
 
  
 
== Next steps ==
 
== Next steps ==
 
* [[Tutorial:Callback_Functions]] will teach you the basic structure of a love game.
 
* [[Tutorial:Callback_Functions]] will teach you the basic structure of a love game.
* [[:Category:Tutorials]] are the next piece of reading
+
* [[:Category:Tutorials]] are the next piece of reading.
 +
* [[Main Page|Wiki]] The LÖVE wiki.
  
 
== Other Languages ==
 
== Other Languages ==

Revision as of 07:22, 18 December 2018

Get LÖVE

Download the latest version of LÖVE from the website, and install it. If you're on Windows and don't want to install LÖVE, you can also just download the zipped executables and extract them anywhere.

To find out which version of LÖVE is installed, run the following command:

love --version

Making a Game

To make a minimal game, create a folder anywhere, and open up your favorite text editor. Sublime Text is a pretty good one for all operating systems, and it has Lua support built in. Create a new file in the folder you just created, and name it main.lua. Put the following code in the file, and save it.

function love.draw()
    love.graphics.print("Hello World", 400, 300)
end

Running Games

LÖVE can load a game in two ways:

  • From a folder that contains a main.lua file.
  • From a .love file that has a main.lua file in the top-most directory level (aka root)

For creating .love files see Game Distribution.


Windows

ZeroBrane Studio, Sublime Text 2, Notepad++, and SciTE allow you to launch the game from within their code editors.

Otherwise, the easiest way to run the game is to drag the folder onto either love.exe or a shortcut to love.exe. Remember to drag the folder containing main.lua, and not main.lua itself.

You can also launch the game from the command line:

"C:\Program Files\LOVE\love.exe" "C:\games\mygame"
"C:\Program Files\LOVE\love.exe" "C:\games\packagedgame.love"

You can create a shortcut to do this; simply make a shortcut to love.exe, right-click on it and select "Properties", and then put the command line you want in the "Target" box for the shortcut.

On Windows, there is a special command-line option which will attach a console to the window, allowing you to see the result of print calls (equivalent to setting t.console=true in conf.lua):

"C:\Program Files\LOVE\love.exe" --console

Linux

On Linux, you can use one of these command lines:

love /home/path/to/gamedir/
love /home/path/to/packagedgame.love

If you installed LÖVE system-wide, you can double click on .love files in your file manager as well.


Mac OS X

On Mac OS X, a folder or .love file can be dropped onto the love application bundle. On the Mac Terminal (command line), you can use love like this (assuming it's installed to the Applications directory):

open -n -a love "~/path/to/mygame"

However, the above method will not output printed text to the terminal window. To do that, you will need to execute the love binary inside the application bundle directly:

/Applications/love.app/Contents/MacOS/love ~/path/to/mygame

You can set up an alias in your Terminal session to call the binary when you use love by adding an alias to your ~/.bash_profile.

Open the file with

open -a TextEdit ~/.bash_profile

You may have to run

touch ~/.bash_profile

first if the file does not yet exist.

Then paste in the following code and save the file:

# alias to love
alias love="/Applications/love.app/Contents/MacOS/love"

Now you can call love from the command line like Linux and Windows:

love ~/path/to/mygame

Android

As long as you have the love app installed from the playstore or another source the following methods will work:

  • Method 1 Transfer your game folder to /sdcard/lovegame where main.lua is found at /sdcard/lovegame/main.lua. Then run the app.
  • Method 2 Transfer a .love of your game to the device and click on it. Most file explorers will run the .love using the love app. If it does not you can install ES File Explorer which will. If you use Dropbox, you can use that to open .love files.



iOS

In order to run LÖVE for iOS, it must first be compiled and installed. To do that, you’ll need Mac OS X, Xcode 7 or newer, and the LÖVE for iOS source code downloadable from the home page.

  • If the include and libraries folders are not present in the love/platform/xcode/ios folder, download them and place them there. They contain the third-party library dependencies used by LÖVE.
  • Open the Xcode project found at love/platform/xcode/love.xcodeproj and select the love-ios target in the dropdown menu at the top of the window.
  • You may want to change the Build Configuration from Debug to Release for better performance, by opening the "Edit Scheme..." menu from the same dropdown selection.
  • Choose either an iOS Simulator device or your plugged-in iOS device in the dropdown selection to the right of the previous one, and click the Build-and-Run ▶︎ button to the left, which will install LÖVE on the target device after compiling it.

LÖVE on iOS includes a simple list interface of games that are installed (until you fuse a .love to it for distribution.)

  • To put a .love file on the iOS Simulator after LÖVE is installed, drag the file onto the iOS Simulator’s window while it’s open. LÖVE will launch if it’s not running already. If another game is currently active you may need to quit LÖVE for the new game to show up (press Shift-Command-H twice to open the App Switcher menu on the iOS Simulator.)
  • To put a .love file or game folder on your iOS device after LÖVE is installed, you can either download it with the Safari, or transfer it from your computer through iTunes when your device is connected: open iTunes, go to the iOS device which has LÖVE installed, go to the ‘Apps’ section and scroll down and find LÖVE, and add the .love file or game folder to LÖVE’s Documents section.

See the Game Distribution page for creating Fused LÖVE games on iOS and distributing them.

Next steps

Other Languages