Korok.io

Sprite

In korok, sprite is a rename of gfx.Tex2D which is a texture with some meta-data. By default, SpriteComp is used to draw sprite, which is the most commonly used renderable element.

Load Texture

For a single image:

                        
    asset.Texture.Load("face.png")
    face := asset.Texture.Get("face.png")
                        

For atlas:

                        
    assets.Texture.LoadAtals("images/bird.png", "images/bird.json")

    at, _ := asset.Texture.Atlas("images/bird.png")
    bg, _ := at.GetByName("background.png")
    nm, _ := at.GetByName("game_name.png")
                        

Draw Sprite

SpriteComp is used to draw sprite. By default, SpriteComp suppose a Transform component exist. You should always have a Transform component, almost very time you want to drawing something.

                        

    entity := korok.Entity.New()

    spr := korok.Sprite.NewComp(entity)
    spr.SetSprite(tex2d)

    xf := korok.Transform.NewComp(entity)
    xf.SetPosition(f32.Vec2{100, 100})