We’ve been prodding each other in IRC to come up with better skybox functions, so here is an early attempt by me (unsurprisingly).
Full project and source included - but expect it to shift to github and actually be updated very soon.
https://www.dropbox.com/s/2wjtz3mhjjjngbr/Skybox.zip
What you’ll see:
A menu screen that you can ignore completely, just click on a button to start it up.
And then… a skybox. Amazing, I know.
Although the interface will change and some more functionality will be added soon, you can have a quick play with what is there.
The meat is in game.lua in the skybox creation routine (starting at line 20):
[lua]function setUp( group )
local border = 25
skybox = skyboxClass.new{
parent = group,
fov = 90,
xAngle = 0,
yAngle = 0,
clip = true,
left = border,
top = border,
width = display.contentWidth - border * 2,
height = display.contentHeight - border * 2,
subdivide = 5,
zCull = 0.01,
– zOffset = 0.5,
scale = 400,
images = {
path = “gfx/sky”,
suffix = “png”,
width = 512,
height = 512,
},
}
end[/lua]
Expect or possibly pray for the following options in the future:
- Specify the field of view in degrees.
- Enable / disable individual faces (for example remove top and bottom if you can’t ever look up and down).
- Rotate and flip individual faces (in case they import in the wrong orientation).
- Snapshot version (to allow filters)
- Cloud layers (flat planes with a texture applied that you can scroll and what-not)
Options are:
- parent - optional. What this group / container gets inserted into.
- fov - not working - hah!
- xAngle - optional. The starting x angle. Defaults to 0.
- yAngle - optional. The starting y angle. Defaults to 0.
- clip - optional. Whether this uses a container (true) or just a group (false). Defaults to false.
- left - optional. Where the left edge is. Defaults to 0. *
- top - optional. Where the top edge is. Defaults to 0. *
- width - optional. How wide the view is. Defaults to display.contentWidth. *
- height - optional. How tall the view is. Defaults to display.contentHeight. *
- subdivide - optional. How many times each face is subdivided to help with culling. Creates subdivide * subdivide cells per face, so there aren’t many reasons to set it higher. Defaults to 4.
- zCull - optional. At what values a cell gets culled. Any corner nearer than this value won’t be drawn. Defaults to 0.1
- zOffset - optional. How far back the whole skybox gets pushed from the camera. Can be used for a few odd effects, but likely you aren’t gonna want to touch this. Defaults to 0. Note that the skybox itself is a cube 2 units wide (to give you some idea of values).
- scale - optional. How much to scale everything drawn on screen. Higher values gives a lower field of view. Eventually this will be replaced by the actual fov value above. Defaults to 500.
- images - required. A table that contains the following values:
- path - required. A path from the project root. It also needs to include the ‘stub’ of the imageset filename.
- suffix - optional. What type of images - png or jpg. Defaults to jpg.
- width - required. How wide the images are.
- height - required. How tall the images are.
* Note that these limits are only respected when clip is set to true (IE using a container). If just using a display group, then the skybox can and likely will be drawn outside of these boundaries.
How to set up the images:
The project contains the following 6 files:
- gfx/sky-back.png
- gfx/sky-down.png
- gfx/sky-front.png
- gfx/sky-left.png
- gfx/sky-right.png
- gfx/sky-up.png
These naturally represent the individual faces of the skybox.
The -back, -down, -front etc suffixes are required and must not be changed.
To use these files, in the skybox creation function you would use the following path:
path = “gfx/sky”
and the following suffix:
suffix = “png”
The file names are automatically generated from these by inserting the relevant direction indicator into the filename.