justgook/webgl-shape/3.0.0

WebGL.Shape2d.TexturedShape

Shapes with textures

Same as ShapeSolid but also can render shapes that needs textures

{ a | width : Width, height : Height }
-> List (TexturedShape key)
-> ( List Entity, TextureLoader key )

Converts List Shape to WebGL entities

import WebGL
import WebGL.Game2d.TexturedShape exposing (toEntities)


rectangle =
    ...


textures =
    ...


screen =
    { width = 100, height = 100 }


main =
    toEntities screen textures [ rectangle red 30 30 ]
        |> Webgl.toHtml [ width 100, height 100 ]
shape : Width -> Height -> Render -> TexturedShape texture

Create TexturedShape from Render

rectangle : Color -> Width -> Height -> TexturedShape
rectangle color w h =
    Render.rect color |> TexturedShape.shape w h
group : List (TexturedShape key) -> TexturedShape key

Put shapes together so you can move and rotate them as a group. Maybe you want to put a bunch of stars in the sky:

shapes =
    [ star
        |> move 100 100
        |> rotate 5
    , star
        |> move -120 40
        |> rotate 20
    , star
        |> move 80 -150
        |> rotate 32
    , star
        |> move -90 -30
        |> rotate -16
    ]


star =
    group
        [ triangle yellow 20
        , triangle yellow 20
            |> rotate 180
        ]
(Texture -> TexturedShape texture)
-> texture
-> TexturedShape texture

Create TexturedShape that depend on texture.

(Texture -> Texture -> TexturedShape key)
-> key
-> key
-> TexturedShape key
(Texture -> Texture -> Texture -> TexturedShape key)
-> key
-> key
-> key
-> TexturedShape key
(Texture -> Texture -> Texture -> Texture -> TexturedShape key)
-> key
-> key
-> key
-> key
-> TexturedShape key
( Texture
-> Texture
-> Texture
-> Texture
-> Texture
-> TexturedShape key
)
-> key
-> key
-> key
-> key
-> key
-> TexturedShape key
type alias TexturedShape key =
Shape (Form key)
type Form key
= Form (ShapeData Render)
| Group (GroupData (Shape (Form key)))
| Textured (TexturedData key (TexturedShape key))

Textures

type TextureLoader key
= TextureLoader
{ get : key -> Maybe Texture
, missing : key -> TextureLoader key
, extract : () -> ( TextureLoader key, List key )
, insert : key -> Texture -> TextureLoader key
}