Class TCastleTiledMapControl

Unit

Declaration

type TCastleTiledMapControl = class(TCastleUserInterface)

Description

Warning: this symbol is deprecated: use TCastleTiledMap in a viewport

Display a map created in Tiled (https://www.mapeditor.org/).

Hierarchy

Overview

Methods

Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Render; override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;
Public procedure LoadFromFile(const AURL: string); deprecated 'set URL instead of calling LoadFromFile';
Public function PositionToTile(const Position: TVector2; const ContainerCoordinates: Boolean; out TilePosition: TVector2Integer): Boolean;
Public function TileRectangle(const TilePosition: TVector2Integer; const ContainerCoordinates: Boolean): TFloatRectangle; overload;
Public function TileRectangle(const TilePosition: TVector2Integer; const ContainerCoordinates: Boolean; const ForceTileWidth, ForceTileHeight: Single): TFloatRectangle; overload;

Properties

Public property Origin: TVector2 read FOrigin write SetOrigin;
Public property Map: TCastleTiledMapData read FMap;
Published property ClipChildren default true;
Published property URL: String read FURL write SetURL;
Published property Scale: Single read FScale write SetScale default 1;
Published property ObjectsVisible: Boolean read FObjectsVisible write FObjectsVisible default true;
Published property SmoothScaling: Boolean read FSmoothScaling write SetSmoothScaling default false;
Published property SmoothScalingSafeBorder: Boolean read FSmoothScalingSafeBorder write SetSmoothScalingSafeBorder default false;
Published property OriginPersistent: TCastleVector2Persistent read FOriginPersistent ;

Description

Methods

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Public destructor Destroy; override;

This item has no description.

Public procedure Render; override;

This item has no description. Showing description inherited from TCastleUserInterface.Render.

Render a control. Called only when Exists and GLInitialized, you can depend on it in the implementation of this method.

Do not explicitly call this method. Instead, render controls by adding them to the TCastleContainer.Controls list, or render them explicitly (for off-screen rendering) by TCastleContainer.RenderControl. This is method should only be overridden in your own code.

Before calling this method we always set some OpenGL state, and you can depend on it (and you can carelessly change it, as it will be reset again before rendering other control).

OpenGL state always set:

  • Viewport is set to include whole container.

  • Depth test is off.

  • (For fixed-function pipeline:) The 2D orthographic projection is always set at the beginning. Useful for 2D controls, 3D controls can just override projection matrix, e.g. use CastleRenderContext.PerspectiveProjection.

  • (For fixed-function pipeline:) The modelview matrix is set to identity. The matrix mode is always modelview.

  • (For fixed-function pipeline:) The raster position is set to (0,0). The (deprecated) WindowPos is also set to (0,0).

  • (For fixed-function pipeline:) Texturing, lighting, fog is off.

Beware that GLSL RenderContext.CurrentProgram has undefined value when this is called. You should always set it, before making direct OpenGL drawing calls (all the engine drawing routines of course do it already, this is only a concern if you make direct OpenGL / OpenGLES calls).

Public function PropertySections(const PropertyName: String): TPropertySections; override;

This item has no description. Showing description inherited from TCastleComponent.PropertySections.

Section where to show property in the editor.

Public procedure LoadFromFile(const AURL: string); deprecated 'set URL instead of calling LoadFromFile';

Warning: this symbol is deprecated: set URL instead of calling LoadFromFile

Load given TMX file to memory and creates structures.

Public function PositionToTile(const Position: TVector2; const ContainerCoordinates: Boolean; out TilePosition: TVector2Integer): Boolean;

Detect tile under given position.

The interpretation of Position depends on ContainerCoordinates, and is similar to e.g. TCastleViewport.PositionToCameraPlane:

  • When ContainerCoordinates = True, then Position is relative to the whole container (like TCastleWindow or TCastleControl).

    And it is expressed in real device coordinates, just like TInputPressRelease.Position when mouse is being clicked, or like TInputMotion.Position when mouse is moved.

  • When ContainerCoordinates = False, then Position is relative to this UI control.

    And it is expressed in coordinates after UI scaling. IOW, if the size of this control is Width = 100, then Position.X between 0 and 100 reflects the visible range of this control.

Note that you can query the positions that are outside of this UI control, or even outside of the container. They will return correct map tiles, as if the map was rendered there. If you want to avoid this, you can e.g. check whether Position is inside the RenderRect (if it's a position in container coordinates, with ContainerCoordinates = True).

This method returns False if the position is outside of the map. Valid map tiles are from (0, 0) (lower-left) to (TCastleTiledMapData.Width - 1, TCastleTiledMapData.Height - 1) (upper-right).

Public function TileRectangle(const TilePosition: TVector2Integer; const ContainerCoordinates: Boolean): TFloatRectangle; overload;

Rectangle where the given map tile is rendered. Useful to render something over a TCastleTiledMapControl, e.g. a pawn in a game.

In some way, this method is an inverse of the PositionToTile method. It converts map (tile) coordinates back into coordinates useful to display something. The ContainerCoordinates value determines the coordinate system of the resulting rectangle. It's meaning is similar to the ContainerCoordinates parameter of the PositionToTile method.

This method works for any TilePosition, even outside of valid map positions. Returns TFloatRectangle.Empty is Map not loaded (URL not set).

Some maps may use tilesets in which image size is different than map tile size. That is, TCastleTiledMapData.TTileset.TileWidth may be different than TCastleTiledMapData.TileWidth for some tilesets. The simpler version of this method, without ForceTileWidth/Height, just returns the size of the map tile looking at (TCastleTiledMapData.TileWidth, TCastleTiledMapData.TileHeight), since it doesn't know the tileset you use.

You can pass ForceTileWidth and ForceTileHeight to set particular size.

Public function TileRectangle(const TilePosition: TVector2Integer; const ContainerCoordinates: Boolean; const ForceTileWidth, ForceTileHeight: Single): TFloatRectangle; overload;

This item has no description.

Properties

Public property Origin: TVector2 read FOrigin write SetOrigin;

Origin determines the map position at control's left-bottom corner. Increasing Origin.X moves visually the map to the left, increasing Origin.Y moves it down.

Public property Map: TCastleTiledMapData read FMap;

Currently loaded map (from URL), if any. Nil if no map is loaded (when URL is empty). Read-only.

Published property ClipChildren default true;

This item has no description. Showing description inherited from TCastleUserInterface.ClipChildren.

Clip the rendering of children.

By default this is False and so the control can draw outside of it's designated rectangle (RenderRect). Although all the standard UI controls are carefully implemented such that their Render and RenderOverChildren draw only within their RenderRect. But it is easy to place children controls outside of this rectangle.

When this property is True, the rendering is clipped, so the "overflowing" parts are never visible. This affects both Render and RenderOverChildren of this control, as well as all children rendering.

Published property URL: String read FURL write SetURL;

URL (or just filename) of the Tiled map file (TMX).

Published property Scale: Single read FScale write SetScale default 1;

This item has no description.

Published property ObjectsVisible: Boolean read FObjectsVisible write FObjectsVisible default true;

Show objects like polylines and points on the map.

Published property SmoothScaling: Boolean read FSmoothScaling write SetSmoothScaling default false;

How are images scaled (because of UI scaling, because of Scale). True means we use nice "bilinear" filter. False means we use pixelated "nearest" filter.

Beware that using True, and scaling the map, requires preparing the tileset (atlas of tile images) in a proper way. The space around each tile must have at least 1-pixel margin filled with the same color and alpha ("color bleeding"), otherwise bad colors will creep in because of bilinear filtering. Alternatively, you can use SmoothScalingSafeBorder.

Published property SmoothScalingSafeBorder: Boolean read FSmoothScalingSafeBorder write SetSmoothScalingSafeBorder default false;

In case of SmoothScaling, prevent the color outside of rendered frame from creeping in, by stretching the rendered frame a bit. See TSprite.SmoothScalingSafeBorder.

It is better to prepare the sprite (tileset) images with some spacing between tiles, and color bleeding, instead of using this property. This property workarounds the fact that some sprite (tileset) images lack proper spacing and color bleeding, but it distorts the image a bit, so it's no longer pixel-perfect.

Published property OriginPersistent: TCastleVector2Persistent read FOriginPersistent ;

Origin that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write Origin directly.

See also
Origin
Origin determines the map position at control's left-bottom corner.

Generated by PasDoc 0.16.0.