Difference between revisions of "love.window.fromPixels"

m
m
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Converts a number from pixels to density-independent units.
 
Converts a number from pixels to density-independent units.
  
If the <code>highdpi</code> window flag is enabled in Mac OS X and the window is in a retina screen, density-independent units will be twice the size of pixels. Otherwise they will usually be the same. This function can be used to convert coordinates from pixels to the the size users are expecting them to display at onscreen. [[love.window.toPixels]] does the opposite.
+
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.fromPixels(1600)</code> would return <code>800</code> in that case.
 +
 
 +
This function converts coordinates from pixels to the size users are expecting them to display at onscreen. [[love.window.toPixels]] 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 mouse events are always in terms of pixels.
+
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 ==

Latest revision as of 19:43, 25 November 2015

Available since LÖVE 0.9.2
This function is not supported in earlier versions.

Converts a number from pixels to density-independent units.

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.fromPixels(1600) would return 800 in that case.

This function converts coordinates from pixels to the size users are expecting them to display at onscreen. love.window.toPixels 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.

Function

Synopsis

value = love.window.fromPixels( pixelvalue )

Arguments

number pixelvalue
A number in pixels to convert to density-independent units.

Returns

number value
The converted number, in density-independent units.

Function

Synopsis

x, y = love.window.fromPixels( px, py )

Arguments

number px
The x-axis value of a coordinate in pixels.
number py
The y-axis value of a coordinate in pixels.

Returns

number x
The converted x-axis value of the coordinate, in density-independent units.
number y
The converted y-axis value of the coordinate, in density-independent units.

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