Class Canvas
In most applications, the canvas resolution is independent of the screen
resolution of the device. This allows applications to have a reasonably
consistent user interface across devices with different screen sizes, as
the canvas can be scaled depending on the difference between preferred
canvas size and the actual screen size. The canvas is then used to convert
between the two coordinate systems. How this scaling behaves when faced
with different screen sizes, resolutions, and aspect ratios is controlled
by the canvas' ScaleStrategy
.
In some cases no scaling is necessary, and the application will simply use the native resolution of the screen. This is referred to as a "flexible" or "native" canvas, which does not have a preferred size or aspect ratio and will simply translate screen coordinates 1-to-1.
-
Constructor Summary
ConstructorDescriptionCanvas
(int preferredWidth, int preferredHeight, ScaleStrategy scaleStrategy) -
Method Summary
Modifier and TypeMethodDescriptionint
int
int
int
int
int
int
int
getWidth()
float
Returns the zoom level that indicates how canvas pixels should be displayed relative to screen pixels.boolean
boolean
void
offsetScreen
(int offsetX, int offsetY) Offset the canvas position on the screen.void
resizeScreen
(int screenWidth, int screenHeight) Sets the screen dimensions to the specified values.float
toCanvasX
(int screenX) float
float
toCanvasY
(int screenY) float
float
toScreenX
(float canvasX) float
float
toScreenY
(float canvasY) float
toString()
-
Constructor Details
-
Canvas
-
-
Method Details
-
resizeScreen
public void resizeScreen(int screenWidth, int screenHeight) Sets the screen dimensions to the specified values. This method should be called by the renderer when the application window is first created, and whenever the window is resized. -
offsetScreen
public void offsetScreen(int offsetX, int offsetY) Offset the canvas position on the screen. This is mainly needed for when the screen contains system UI such as a status bar or window title where no application graphics can be displayed. -
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getBounds
-
getCenter
-
isLandscape
public boolean isLandscape() -
isPortait
public boolean isPortait() -
getZoomLevel
public float getZoomLevel()Returns the zoom level that indicates how canvas pixels should be displayed relative to screen pixels. This is based on the current screen size, the canvas' preferred size, and itsScaleStrategy
. -
toCanvasX
public float toCanvasX(int screenX) -
toCanvasX
-
toCanvasY
public float toCanvasY(int screenY) -
toCanvasY
-
toScreenX
public float toScreenX(float canvasX) -
toScreenX
-
toScreenY
public float toScreenY(float canvasY) -
toScreenY
-
toString
-
getPreferredWidth
public int getPreferredWidth() -
getPreferredHeight
public int getPreferredHeight() -
getScaleStrategy
-
getScreenWidth
public int getScreenWidth() -
getScreenHeight
public int getScreenHeight() -
getOffsetX
public int getOffsetX() -
getOffsetY
public int getOffsetY()
-