Difference between revisions of "love (简体中文)"

Line 1: Line 1:
此模块包含所有其他模块。
+
当你开始用LÖVE编写游戏时, 需要了解几个最重要的API回调函数:
最美模块非它莫属。
+
[[love.load]]仅执行一次,用于初始化加载你的游戏,
 
+
[[love.update]]用于管理你的游戏每一帧的状态,
当你使用LÖVE编写游戏时,需要了解这几个最重要的API回调函数:
+
[[love.draw]]用于渲染你的游戏到屏幕.
[[love.load]]会初始化加载您的游戏,它仅会被执行一次,
 
[[love.update]]用来管理与更新你的游戏的每一帧的状态,
 
[[love.draw]]用来渲染屏幕。
 
  
 
为了处理玩家输入的信息以及呈现一个全方面体验的游戏,很多交互将会重写额外的回调函数.
 
为了处理玩家输入的信息以及呈现一个全方面体验的游戏,很多交互将会重写额外的回调函数.
  
LÖVE提供了默认的空回调函数,你可以通过对应的回调函数名在你自己的代码里重写这些函数:
+
LÖVE提供了默认的空回调函数,你可以通过对应的回调函数名在你自己的代码里重写这些函数:
  
 
<source lang="lua">
 
<source lang="lua">
 +
-- 初始化矩形的一些默认值.
 
function love.load()
 
function love.load()
  hamster = love.graphics.newImage("hamster.png")
+
    x, y, w, h = 20, 20, 60, 20
  x = 50
 
  y = 50
 
 
end
 
end
 +
 +
-- 每一帧变大矩形的尺寸.
 +
function love.update(dt)
 +
    w = w + 1
 +
    h = h + 1
 +
end
 +
 +
-- 渲染颜色矩形.
 
function love.draw()
 
function love.draw()
  love.graphics.draw(hamster, x, y)
+
    love.graphics.setColor(0, 100, 100)
 +
    love.graphics.rectangle("fill", x, y, w, h)
 
end
 
end
 
</source>
 
</source>
  
== 模块 ==
+
== Modules(模块) ==
{{#ask: [[Category:Modules]] [[parent::love (简体中文)]] [[Concept:Current]]
+
{{#ask: [[Category:Modules]] [[parent::love]] [[Concept:Current]]
 
| headers=hide
 
| headers=hide
 
| format=template
 
| format=template
Line 33: Line 38:
 
| ?PrettyRemoved
 
| ?PrettyRemoved
 
}}
 
}}
== 类型 ==
+
 
{{#ask: [[Category:Types]] [[parent::love (简体中文)]] [[Concept:Current]]
+
== Third-party modules(第三方模块) ==
 +
{{#ask: [[Category:Libraries]] [[parent::love]] [[Concept:Current]]
 
| headers=hide
 
| headers=hide
 
| format=template
 
| format=template
Line 44: Line 50:
 
| ?PrettyRemoved
 
| ?PrettyRemoved
 
}}
 
}}
== 回调函数 ==
+
 
{{#ask: [[Category:Callbacks]] [[parent::love (简体中文)]] [[Concept:Current]]
+
== Functions(方法) ==
 +
{{#ask: [[Category:Functions]] [[parent::love]] [[Concept:Current]]
 
| headers=hide
 
| headers=hide
 
| format=template
 
| format=template
Line 55: Line 62:
 
| ?PrettyRemoved
 
| ?PrettyRemoved
 
}}
 
}}
 +
 +
== Types(类型) ==
 +
{{#ask: [[Category:Types]] [[parent::love]] [[Concept:Current]]
 +
| headers=hide
 +
| format=template
 +
| template=ListingFields
 +
| introtemplate=ListingIntro
 +
| outrotemplate=ListingOutro
 +
| ?Description
 +
| ?PrettySince
 +
| ?PrettyRemoved
 +
}}
 +
 +
== Callbacks(回调) ==
 +
=== General(通用) ===
 +
{{#ask: [[Category:Callbacks]] [[Subcategory::General]] [[parent::love]] [[Concept:Current]]
 +
| headers=hide
 +
| format=template
 +
| template=ListingFields
 +
| introtemplate=ListingIntro
 +
| outrotemplate=ListingOutro
 +
| ?Description
 +
| ?PrettySince
 +
| ?PrettyRemoved
 +
}}
 +
 +
=== Joystick(操作杆) ===
 +
{{#ask: [[Category:Callbacks]] [[Subcategory::Joystick]] [[parent::love]] [[Concept:Current]]
 +
| headers=hide
 +
| format=template
 +
| template=ListingFields
 +
| introtemplate=ListingIntro
 +
| outrotemplate=ListingOutro
 +
| ?Description
 +
| ?PrettySince
 +
| ?PrettyRemoved
 +
}}
 +
 
[[Category:Modules]]
 
[[Category:Modules]]
{{#set:Description=此模块包含所有其他模块。}}
+
{{#set:Description=The root module which contains all the other modules.}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
  
== 其他语言 ==
+
== Other Languages ==
 
{{i18n|love}}
 
{{i18n|love}}

Revision as of 08:57, 14 April 2016

当你开始用LÖVE编写游戏时, 需要了解几个最重要的API回调函数: love.load仅执行一次,用于初始化加载你的游戏, love.update用于管理你的游戏每一帧的状态, love.draw用于渲染你的游戏到屏幕.

为了处理玩家输入的信息以及呈现一个全方面体验的游戏,很多交互将会重写额外的回调函数.

LÖVE提供了默认的空回调函数,你可以通过对应的回调函数名在你自己的代码里重写这些函数:

-- 初始化矩形的一些默认值.
function love.load()
    x, y, w, h = 20, 20, 60, 20
end

-- 每一帧变大矩形的尺寸.
function love.update(dt)
    w = w + 1
    h = h + 1
end

-- 渲染颜色矩形.
function love.draw()
    love.graphics.setColor(0, 100, 100)
    love.graphics.rectangle("fill", x, y, w, h)
end

Modules(模块)

love.audio Provides of audio interface for playback/recording sound.
love.data Provides functionality for creating and transforming data. Added since 11.0
love.event Manages events, like keypresses. Added since 0.6.0
love.filesystem Provides an interface to the user's filesystem.
love.font Allows you to work with fonts. Added since 0.7.0
love.graphics Drawing of shapes and images, management of screen geometry.
love.image Provides an interface to decode encoded image data.
love.joystick Provides an interface to connected joysticks. Added since 0.5.0
love.keyboard Provides an interface to the user's keyboard.
love.math Provides system-independent mathematical functions. Added since 0.9.0
love.mouse Provides an interface to the user's mouse.
love.physics Can simulate 2D rigid body physics in a realistic manner. Added since 0.4.0
love.sound This module is responsible for decoding sound files.
love.system Provides access to information about the user's system. Added since 0.9.0
love.thread Allows you to work with threads. Added since 0.7.0
love.timer Provides high-resolution timing functionality.
love.touch Provides an interface to touch-screen presses. Added since 0.10.0
love.video This module is responsible for decoding and streaming video files. Added since 0.10.0
love.window Provides an interface for the program's window. Added since 0.9.0

Third-party modules(第三方模块)

lua-enet Multiplayer networking module for games. Added since 0.9.0
socket Module for HTTP, TCP, and UDP networking. Added since 0.5.0
utf8 Provides basic support for manipulating UTF-8 strings. Added since 0.9.2

Functions(方法)

love.getVersion Gets the current running version of LÖVE. Added since 0.9.1
love.hasDeprecationOutput Gets whether LÖVE displays warnings when using deprecated functionality. Added since 11.0
love.isVersionCompatible Gets whether the given version is compatible with the current running version of LÖVE. Added since 0.10.0
love.setDeprecationOutput Sets whether LÖVE displays warnings when using deprecated functionality. Added since 11.0

Types(类型)

Data The superclass of all data.
Object The superclass of all LÖVE types.
Variant The types supported by love.thread and love.event.

Callbacks(回调)

General(通用)

Config Files Game configuration settings.
love.draw Callback function used to draw on the screen every frame.
love.errhand The error handler, used to display error messages.
love.errorhandler The error handler, used to display error messages. Added since 11.0
love.load This function is called exactly once at the beginning of the game.
love.lowmemory Callback function triggered when the system is running out of memory on mobile devices. Added since 0.10.0
love.quit Callback function triggered when the game is closed. Added since 0.7.0
love.run The main function, containing the main loop. A sensible default is used when left out.
love.threaderror Callback function triggered when a Thread encounters an error. Added since 0.9.0
love.update Callback function used to update the state of the game every frame.

Joystick(操作杆)

love.gamepadaxis Called when a Joystick's virtual gamepad axis is moved. Added since 0.9.0
love.gamepadpressed Called when a Joystick's virtual gamepad button is pressed. Added since 0.9.0
love.gamepadreleased Called when a Joystick's virtual gamepad button is released. Added since 0.9.0
love.joystickadded Called when a Joystick is connected. Added since 0.9.0
love.joystickaxis Called when a joystick axis moves. Added since 0.9.0
love.joystickhat Called when a joystick hat direction changes. Added since 0.9.0
love.joystickpressed Called when a joystick button is pressed.
love.joystickreleased Called when a joystick button is released.
love.joystickremoved Called when a Joystick is disconnected. Added since 0.9.0


Other Languages