| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Mischief.Render.Tutorial.Basics
Synopsis
2.1. Sprites
This chapter will go over some of the basic rendering tools and how to use them.
Windows and Cameras
In order to get anything to render, you will need to spawn a window, and a camera that outputs to it.
window <-spawnWindowspawn_(Camera,RelOutputTowindow)
The window can be given a title using , a size using WindowTitle and flags using WindowSize. You can find
more info in Mischief.SDL.Window.WindowFlags
Each camera has a CameraTexture component containing its texture. A view to the texture can be obtained using
cameraView. Alternatively, cameraSwapView will give you the view while swapping the actual camera's texture to a secondary one,
so that you can both read and output to it at the same time.
Sprites
In order to spawn a sprite you need to give it the entity of an Image asset. You also need to provide it a material.
img <-load@Image"foo.png" spawn_ (Spriteimg,WithMaterial@SpriteMaterial)
Sprites accept all forms of transform manipulation: movement, rotation, scaling.
-- rotating all sprites by 0.2query_$ do (entity, transform) <- [q|Entity, Transform / With Sprite|]qlift$insert(Transform.rotateZ0.2) entity
You can insert a custom SpriteSlice to make the sprite only a slice of its texture:
insert(SpriteSlice(V230 0) (V250 50))
You can set a custom SpriteFlip to flip the sprite horizontally or vertically:
insert(SpriteFlip{x = True, y = False}) sprite
Internally, the information from all these components is uploaded into a buffer on each entity, which is bound to the materials
extending SpriteDataSpriteMaterial. It is then used when calling sampleSprite.