Orasund/pixelengine/4.0.1

NOTE: the latest version is 6.2.0

PixelEngine.Graphics

This module takes care of the Graphics.

You will want to add PixelEngine.Graphics.Image or PixelEngine.Graphics.Tile to actually draw something.

Area

The main idea of this graphic engine is to arrage the content into horizontal stripes, so called areas.

type alias Area msg =
Area msg

A horizontal area of the content. A Area defines how the content should be displayed.

Note:
An area can only contain elements of the same type. So either you have tiles or images.

A typical game

{ rows : Int
, tileset : Tileset
, background : Background
}
-> List ( ( Int, Int ), Tile msg )
-> Area msg

An area for using tilesets.

It supports one tileset at a time, that means all sprites must be of the same size and stored as a grid in one single file. This area is useful for displaying the playing field of a game.

Checkout PixelEngine.Graphics.Tile for more information.

This area has the following options:

  • rows - The amount of rows of the grid. This value defines the height of the Area.
  • tileset - The tileset that will be used for all elements in the Area.
  • background - The background of the Area.
{ height : Float
, background : Background
}
-> List ( ( Float, Float ), Image msg )
-> Area msg

An area containing images that can be arranged freely.

This is a complete contrast to the way how tiledArea is working. Usefull applications are GUIs, menus or loading screens.

Checkout PixelEngine.Graphics.Image for more information.

This area has the following options:

  • height - The height or the Area in pixels.
  • background - The background of the Area.
heightOf : List (Area msg) -> Float

Returns the height of a list of Areas

This can be used to return the height of a tiledArea. For a imageArea this function is trivial.

Background

type alias Background =
Background

Every area has a background.

{ source : String
, width : Float
, height : Float
}
-> Background

An image that gets repeated.

Image "groundTile.png"
colorBackground : Color -> Background

A single color background. It uses avh4/elm-color.

colorBackground (Color.rgb255 20 12 28)

Options

type alias Options msg =
Options msg

Options for the render function

{ width : Float
, transitionSpeedInSec : Float
}
-> Options msg

The engine comes with a set of options:

  • width - Width of the game.
    Note:
    all spatial values are given in Pixels.

  • transitionSpeedInSec - The speed of animations.
    Default value: 0 for no animations

For the start use the following settings

{width = 800, transitionSpeedInSec = 0.2}

Advanced

If one wants to use just use this module on its own, you can use render instead of the game function from the main module.

Render

render : Float -> Options msg -> List (Area msg) -> Html msg

Displays content of the game.

Note:
The first argument is the scale. Use only power of 2 as scale to ensure crisp pixels.