Difference between revisions of "love.window.toPixels"
(Created page) |
m (getPixelScale renamed to getDPIScale in 11.x) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
Converts a number from density-independent units to pixels. | Converts a number from density-independent units to pixels. | ||
− | + | The pixel density inside the window might be greater (or smaller) than the "size" of the window. For example on a retina screen in Mac OS X with the <code>highdpi</code> [[love.window.setMode|window flag]] enabled, the window may take up the same physical size as an 800x600 window, but the area inside the window uses 1600x1200 pixels. <code>love.window.toPixels(800)</code> would return <code>1600</code> in that case. | |
+ | |||
+ | This is used to convert coordinates from the size users are expecting them to display at onscreen to pixels. [[love.window.fromPixels]] does the opposite. The <code>highdpi</code> window flag must be enabled to use the full pixel density of a Retina screen on Mac OS X and iOS. The flag currently does nothing on Windows and Linux, and on Android it is effectively always enabled. | ||
Most LÖVE functions return values and expect arguments in terms of pixels rather than density-independent units. | Most LÖVE functions return values and expect arguments in terms of pixels rather than density-independent units. | ||
Line 29: | Line 31: | ||
== Notes == | == Notes == | ||
− | The units of [[love.graphics.getWidth]], [[love.graphics.getHeight]], [[love.mouse.getPosition]], and | + | The units of [[love.graphics.getWidth]], [[love.graphics.getHeight]], [[love.mouse.getPosition]], mouse events, [[love.touch.getPosition]], and touch events are always in terms of pixels. |
== See Also == | == See Also == | ||
* [[parent::love.window]] | * [[parent::love.window]] | ||
* [[love.window.fromPixels]] | * [[love.window.fromPixels]] | ||
− | * [[love.window. | + | * [[love.window.getDPIScale]] |
* [[love.window.setMode]] | * [[love.window.setMode]] | ||
* [[Config Files]] | * [[Config Files]] |
Latest revision as of 19:16, 5 November 2018
Available since LÖVE 0.9.2 |
This function is not supported in earlier versions. |
Converts a number from density-independent units to pixels.
The pixel density inside the window might be greater (or smaller) than the "size" of the window. For example on a retina screen in Mac OS X with the highdpi
window flag enabled, the window may take up the same physical size as an 800x600 window, but the area inside the window uses 1600x1200 pixels. love.window.toPixels(800)
would return 1600
in that case.
This is used to convert coordinates from the size users are expecting them to display at onscreen to pixels. love.window.fromPixels does the opposite. The highdpi
window flag must be enabled to use the full pixel density of a Retina screen on Mac OS X and iOS. The flag currently does nothing on Windows and Linux, and on Android it is effectively always enabled.
Most LÖVE functions return values and expect arguments in terms of pixels rather than density-independent units.
Contents
Function
Synopsis
pixelvalue = love.window.toPixels( value )
Arguments
number value
- A number in density-independent units to convert to pixels.
Returns
number pixelvalue
- The converted number, in pixels.
Function
Synopsis
px, py = love.window.toPixels( x, y )
Arguments
number x
- The x-axis value of a coordinate in density-independent units to convert to pixels.
number y
- The y-axis value of a coordinate in density-independent units to convert to pixels.
Returns
number px
- The converted x-axis value of the coordinate, in pixels.
number py
- The converted y-axis value of the coordinate, in pixels.
Notes
The units of love.graphics.getWidth, love.graphics.getHeight, love.mouse.getPosition, mouse events, love.touch.getPosition, and touch events are always in terms of pixels.
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info