Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I’m just starting out

edited October 2018 in Questions Posts: 18

Here’s my code as I attempt to setup a project under Craft.

-- Test function setup() -- Create the scene scene = craft.scene() -- Move the main camera = vec3 (0,-10,0) -- Adjust the scene lighting scene.sun.rotation = quat.eulerAngles(75,0,45) scene.ambientColor = color(30,30,30) -- Turn on fog and set distances and color scene.fogEnabled = false scene.fogNear = 10 scene.fogFar = 1000 scene.fogColor = color(168, 168, 168, 255) -- Get the sky material and change the sky and horizon colors local skyMaterial = = color(255, 60, 60, 255) skyMaterial.horizon = color(255, 180, 180, 255) -- Create a new entity ground = scene:entity() -- Attach a model and material for rendering ground.model = craft.model.cube(vec3(1,1,1), vec3(0,0,0)) ground.material = craft.material("Materials:Voxel") -- Rotate the entity ground.eulerAngles = vec3(45, 0, 45) -- Set the z position of the entity ground.z = 100 end function update(dt) -- Update the scene (including physics, voxels and other systems) scene:update(dt) end function draw() update(DeltaTime) -- Draw the scene (must be done within the draw function) scene:draw() end

All I get is this, no matter what I do with the camera, I don’t see anything other than this horizon line, no cubes, no nothing.

Can someone help me figure out how to setup a basic scene in Codea as a template.


  • dave1707dave1707 Mod
    Posts: 8,491

    @Kurall_Creator Welcome to the forum. Instead of fixing your code for you, here’s a simple example that you can look over that will help you fix your code.

    function setup()
        assert(craft, "Please include Craft as a dependency")
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        scene = craft.scene(), 62, 255, 255)
        skyMaterial.horizon=color(99, 255, 0, 255)
        scene.sun.rotation=quat.eulerAngles(20,45,-30), vec3(0,0,0), 100, 0, 200)
        -- create cube with texture
        c1.model = craft.model.cube(vec3(10,10,10))
        c1.material = craft.material("Materials:Standard") = readImage("Blocks:Trunk White Top")
    function draw()
        text("Drag your finger on the screen to rotate the cube",WIDTH/2,HEIGHT-100)
    function update(dt)
  • Thanks Dave, that’s prefect. I can start to do some things to see what piece of code does what through commenting it out.

  • dave1707dave1707 Mod
    Posts: 8,491

    @Kurall_Creator Changing existing code to see what happens is a great way to learn. You can do a forum search for craft code to get more examples. Just a reminder, when you post code, put ~~~ before and after your code so it displays correctly. I added them you your above example.

  • Thanks Dave,

    Using your example and the inbuilt examples, I got a cool result.

    I’m definitely happy picking up this package, learning how to create some interesting stuff.

  • dave1707dave1707 Mod
    Posts: 8,491

    @Kurall_Creator You’re off to a good start. There’s a lot of things to learn with Codea and it will keep you interested for a long time.

Sign In or Register to comment.