jjLAYER class JJ2+

Layer of tiles

A level normally has eight layers, numbered 1 to 8 from front to back: layers 1 and 2 are drawn in front of everything, layer 3 just in front of the sprites, layer 4 is the sprite layer where the gameplay happens, and layers 5 to 8 form the background, layer 8 being the farthest one. They're reached through jjLayers, which keeps this numbering even after jjLayerOrderSet() changes the order they're drawn in. More layers can be created by the constructors or taken from another level by jjLayersFromLevel().

Properties a script changes are applied to the level once per frame.

Constructors

jjLAYER(uint layerWidth, uint layerHeight) partially supported
Creates a new empty layer of the given size in tiles
jjLAYER(const jjLAYER&in layer)
Creates a new layer as a copy of another one

Functions

void generateSettableTileArea(int xTile, int yTile, int width, int height)
Prepares a rectangular area of the layer for tileSet()
void generateSettableTileArea()
Prepares the whole layer for tileSet()
float getXPosition(const jjPLAYER&in play) const
Returns the horizontal position of the layer as last drawn for a player, in pixels
float getYPosition(const jjPLAYER&in play) const
Returns the vertical position of the layer as last drawn for a player, in pixels
bool maskedHLine(int xPixel, int lineLength, int yPixel) const partially supported
Returns whether any pixel of a horizontal line is solid
bool maskedPixel(int xPixel, int yPixel) const partially supported
Returns whether a pixel is solid
int maskedTopVLine(int xPixel, int yPixel, int lineLength) const partially supported
Returns where the topmost solid pixel of a vertical line is
bool maskedVLine(int xPixel, int yPixel, int lineLength) const partially supported
Returns whether any pixel of a vertical line is solid
void setXSpeed(float newspeed, bool newSpeedIsAnAutoSpeed)
Changes the horizontal speed or automatic speed of the layer
void setYSpeed(float newspeed, bool newSpeedIsAnAutoSpeed)
Changes the vertical speed or automatic speed of the layer
uint16 tileGet(int xTile, int yTile) const
Returns the tile at the given position in tiles
uint16 tileSet(int xTile, int yTile, uint16 newTile)
Changes the tile at the given position in tiles

Properties

jjLAYERCYLINDER cylinder
Properties used when textureStyle is TEXTURE::CYLINDER
const bool hasTileMap
Whether the layer has a tile map
bool hasTiles
Whether the layer is drawn
const int height C++
Height of the layer in tiles
bool limitVisibleRegion
Whether the layer is shifted down by an amount that depends on the resolution
jjLAYERMENU menu partially supported
Properties used when textureStyle is TEXTURE::MENU
jjLAYERREFLECTION reflection
Properties used when textureStyle is TEXTURE::REFLECTION
int rotationAngle partially supported
Angle offset of the layer's swaying while a player is stoned
int rotationRadiusMultiplier partially supported
How far the layer sways while a player is stoned
SPRITE::Mode spriteMode
The sprite mode the layer is drawn with
uint8 spriteParam
The parameter of the layer's sprite mode
TEXTURE::Texture texture
The 256×256 pixel image a textured layer is drawn with
TEXTURE::Style textureStyle
The effect a textured layer is drawn with
SURFACE::Surface textureSurface
Where and whether the layer is drawn textured
bool tileHeight C++
Whether the layer repeats vertically
jjLAYERTILEMENU tileMenu
Properties used when textureStyle is TEXTURE::TILEMENU
bool tileWidth C++
Whether the layer repeats horizontally
jjLAYERTUNNEL tunnel
Properties used when textureStyle is TEXTURE::TUNNEL
jjLAYERWARPHORIZON warpHorizon
Properties used when textureStyle is TEXTURE::WARPHORIZON
jjLAYERWAVE wave
Properties used when textureStyle is TEXTURE::WAVE
const int width C++
Width of the layer in tiles
const int widthReal
Width of the layer in tiles, including any widening needed for tiling
const int widthRounded C++
Width of the layer in groups of four tiles, (widthReal + 3) / 4
float xAutoSpeed
Horizontal automatic scrolling speed of the layer
float xInnerAutoSpeed C++
Horizontal automatic scrolling speed of the texture inside the layer, see xInnerSpeed
float xInnerSpeed
Horizontal speed of the texture inside the layer
float xOffset
Horizontal offset of the layer in pixels
float xSpeed
Horizontal parallax speed of the layer
LAYERSPEEDMODEL::LayerSpeedModel xSpeedModel
Horizontal speed model of the layer
float yAutoSpeed C++
Vertical automatic scrolling speed of the layer, see xAutoSpeed
float yInnerAutoSpeed C++
Vertical automatic scrolling speed of the texture inside the layer, see xInnerSpeed
float yInnerSpeed C++
Vertical speed of the texture inside the layer, see xInnerSpeed
float yOffset C++
Vertical offset of the layer in pixels, see xOffset
float ySpeed C++
Vertical parallax speed of the layer, see xSpeed
LAYERSPEEDMODEL::LayerSpeedModel ySpeedModel
Vertical speed model of the layer

Constructor documentation

jjLAYER::jjLAYER(uint layerWidth, uint layerHeight)

Creates a new empty layer of the given size in tiles

The new layer has no tiles yet, doesn't move with the camera (both speeds are 0) and isn't drawn until it's included in jjLayerOrderSet().

jjLAYER::jjLAYER(const jjLAYER&in layer)

Creates a new layer as a copy of another one

The copy takes the tiles, the texture and all other properties of the layer except its sprite mode, which starts as SPRITE::NORMAL. It isn't drawn until it's included in jjLayerOrderSet().

Function documentation

void jjLAYER::generateSettableTileArea(int xTile, int yTile, int width, int height)

Prepares a rectangular area of the layer for tileSet()

Has no effect, every tile can already be changed on its own.

void jjLAYER::generateSettableTileArea()

Prepares the whole layer for tileSet()

Has no effect, every tile can already be changed on its own.

float jjLAYER::getXPosition(const jjPLAYER&in play) const

Returns the horizontal position of the layer as last drawn for a player, in pixels

Accounts for everything that moves the layer, such as its speeds, offsets and the player's camera, so it can be used to keep something aligned to a layer. The player should be a local one. For a layer that isn't part of the level, the position is estimated from the camera, xSpeed and xOffset.

float jjLAYER::getYPosition(const jjPLAYER&in play) const

Returns the vertical position of the layer as last drawn for a player, in pixels

See getXPosition().

bool jjLAYER::maskedHLine(int xPixel, int lineLength, int yPixel) const

Returns whether any pixel of a horizontal line is solid

bool jjLAYER::maskedPixel(int xPixel, int yPixel) const

Returns whether a pixel is solid

int jjLAYER::maskedTopVLine(int xPixel, int yPixel, int lineLength) const

Returns where the topmost solid pixel of a vertical line is

bool jjLAYER::maskedVLine(int xPixel, int yPixel, int lineLength) const

Returns whether any pixel of a vertical line is solid

void jjLAYER::setXSpeed(float newspeed, bool newSpeedIsAnAutoSpeed)

Changes the horizontal speed or automatic speed of the layer

Sets xAutoSpeed if newSpeedIsAnAutoSpeed is true, otherwise xSpeed and sets xAutoSpeed to 0. Unlike assigning the properties, the layer stays where it was in the view of the first player, in every speed model. xOffset doesn't change, the layer is moved by an offset of its own.

void jjLAYER::setYSpeed(float newspeed, bool newSpeedIsAnAutoSpeed)

Changes the vertical speed or automatic speed of the layer

Sets yAutoSpeed if newSpeedIsAnAutoSpeed is true, otherwise ySpeed and sets yAutoSpeed to 0. Unlike assigning the properties, the layer stays where it was in the view of the first player, in every speed model. yOffset doesn't change, the layer is moved by an offset of its own.

uint16 jjLAYER::tileGet(int xTile, int yTile) const

Returns the tile at the given position in tiles

An animated tile is returned as its animated tile ID, not its current frame. Returns 0 for a position outside the layer or a layer that isn't part of the level.

uint16 jjLAYER::tileSet(int xTile, int yTile, uint16 newTile)

Changes the tile at the given position in tiles

Only that tile changes, other places using the same tiles aren't affected. Returns newTile, or 0 if the layer isn't part of the level.

Property documentation

jjLAYERCYLINDER jjLAYER::cylinder

Properties used when textureStyle is TEXTURE::CYLINDER

The texture is drawn as the inside of a horizontal tube receding a short way into the distance, which can fade into the fade color near its horizon.

const bool jjLAYER::hasTileMap

Whether the layer has a tile map

false for a layer of the level that contains no tiles at all, nothing can ever be drawn of it. Always true for a layer created from a size or by jjLayersFromLevel().

bool jjLAYER::hasTiles

Whether the layer is drawn

Setting it to false hides the layer. A layer left out by jjLayerOrderSet() isn't drawn either way.

bool jjLAYER::limitVisibleRegion

Whether the layer is shifted down by an amount that depends on the resolution

Applies to a layer that doesn't repeat vertically and uses LAYERSPEEDMODEL::NORMAL or LAYERSPEEDMODEL::BOTHSPEEDS vertically.

jjLAYERREFLECTION jjLAYER::reflection

Properties used when textureStyle is TEXTURE::REFLECTION

The part of the view below the horizon is drawn as a plane stretching into the distance that mirrors everything drawn above the horizon before this layer, rippled by the texture. Nothing is drawn above the horizon. The layer ignores its sprite mode.

int jjLAYER::rotationAngle

Angle offset of the layer's swaying while a player is stoned

Uses the range of 0 to 1023 of jjSin() and jjCos().

int jjLAYER::rotationRadiusMultiplier

How far the layer sways while a player is stoned

0 keeps the layer still.

SPRITE::Mode jjLAYER::spriteMode

The sprite mode the layer is drawn with

Defaults to SPRITE::NORMAL. A layer drawn as tiles supports NORMAL, TRANSLUCENT, TRANSLUCENTTILE, INVISIBLE, TINTED, PALSHIFT, TRANSLUCENTPALSHIFT, SINGLECOLOR, TRANSLUCENTCOLOR, BRIGHTNESS, CHROMAKEY, ALPHAMAP, MAPPING, TRANSLUCENTMAPPING and all BLEND_* modes, any other mode is ignored. A textured layer supports NORMAL, TRANSLUCENT, TRANSLUCENTTILE, INVISIBLE, CHROMAKEY, MAPPING, TRANSLUCENTMAPPING and the BLEND_* modes, with any other mode it's drawn normally. Layers drawn by special effects, such as a reflection, ignore the mode.

uint8 jjLAYER::spriteParam

The parameter of the layer's sprite mode

Its meaning depends on spriteMode, for example the opacity for SPRITE::BLEND_NORMAL, the palette entry for SPRITE::SINGLECOLOR and SPRITE::CHROMAKEY, or the brightness for SPRITE::BRIGHTNESS (128 leaves it unchanged). It's kept even while the current mode doesn't use it. Defaults to 0.

TEXTURE::Texture jjLAYER::texture

The 256×256 pixel image a textured layer is drawn with

TEXTURE::FROMTILES (the default) takes the 8×8 tiles at the top left corner of the layer. Reads as TEXTURE::CUSTOM after jjPIXELMAP::makeTexture() gave the layer an image. The other textures are read from a data file in the game's Source directory, if it's missing, the image of the layer doesn't change.

TEXTURE::Style jjLAYER::textureStyle

The effect a textured layer is drawn with

Used only when textureSurface isn't SURFACE::UNTEXTURED. Each style has its own properties, for example warpHorizon for TEXTURE::WARPHORIZON. TEXTURE::MENU is drawn as a warp horizon.

SURFACE::Surface jjLAYER::textureSurface

Where and whether the layer is drawn textured

SURFACE::UNTEXTURED draws the layer as tiles. Otherwise it's drawn with the effect of textureStyle, see SURFACE::Surface for the options.

jjLAYERTILEMENU jjLAYER::tileMenu

Properties used when textureStyle is TEXTURE::TILEMENU

The rotating background of the main menu: three parts repeated over the view, each turning and zooming at its own pace around a pivot. The front part is the layer's texture, the middle one the 2×2 tiles at the top left corner of layer 4, and the back one the tile at 0,2 of layer 4.

jjLAYERTUNNEL jjLAYER::tunnel

Properties used when textureStyle is TEXTURE::TUNNEL

The texture is drawn as rings shrinking towards a center in the distance, which can fade into the fade color. spiral makes the rings twist inwards.

jjLAYERWARPHORIZON jjLAYER::warpHorizon

Properties used when textureStyle is TEXTURE::WARPHORIZON

The texture is drawn as a floor and a ceiling stretching to a horizon in the distance. The horizon can fade into the fade color and show stars.

jjLAYERWAVE jjLAYER::wave

Properties used when textureStyle is TEXTURE::WAVE

The texture is drawn flat and repeated, with its rows and columns shifted by sine waves.

const int jjLAYER::widthReal

Width of the layer in tiles, including any widening needed for tiling

Always equal to width, layers are never stored widened.

float jjLAYER::xAutoSpeed

Horizontal automatic scrolling speed of the layer

Scrolls the layer constantly, regardless of the camera. How it combines with xSpeed depends on xSpeedModel.

float jjLAYER::xInnerSpeed

Horizontal speed of the texture inside the layer

Used only when textureSurface is SURFACE::INNERLAYER or SURFACE::INNERWINDOW: the regular speeds then place the layer in the level, while the inner speeds move the texture within it. Defaults to 0.

float jjLAYER::xOffset

Horizontal offset of the layer in pixels

Added to the position of the layer regardless of its speeds. The automatic speed scrolls the layer without changing it. Stored in 16.16 fixed point, so a value out of the range of roughly -32768 to 32767 becomes 0.

float jjLAYER::xSpeed

Horizontal parallax speed of the layer

How fast the layer moves relative to the camera: 1 moves it together with the sprite layer, 0 keeps it fixed on screen. How it combines with xAutoSpeed depends on xSpeedModel.

LAYERSPEEDMODEL::LayerSpeedModel jjLAYER::xSpeedModel

Horizontal speed model of the layer

Decides how the speed properties position the layer horizontally, see LAYERSPEEDMODEL::LayerSpeedModel.

LAYERSPEEDMODEL::LayerSpeedModel jjLAYER::ySpeedModel

Vertical speed model of the layer

Decides how the speed properties position the layer vertically, see LAYERSPEEDMODEL::LayerSpeedModel.