Hey guys, based on feedback from @UberGoober I’ve experimented with a few additions to Craft to make things a little easier to work with. These improvements are mostly meant for Codea 4 but I’ve back ported some of them where it made sense.
The Main Scene
Use craft.scene.main to update and draw a scene automatically
-- This is all you need to do to draw and update your scene
function setup()
scene = craft.scene()
craft.scene.main = scene
end
Entity Callbacks
A set of new callback events in entities let you attach functions that will be called automatically:
entity.update
entity.fixedUpdate
entity.destroyed
function setup()
-- Create a new craft scene
scene = craft.scene()
scene.camera.z = 10
scene.camera.eulerAngles = vec3(0, 180, 0)
scene.sun.eulerAngles = vec3(45, 45, 0)
-- Create a new entity
e = scene:entity()
e.model = craft.model(asset.builtin.Primitives.Monkey)
e.update = function(entity, dt)
entity.y = math.sin(ElapsedTime)
end
e.destroyed = function(entity)
sound(SOUND_POWERUP)
end
craft.scene.main = scene
end
function touched(touch)
if touch.state == BEGAN then
e:destroy()
end
end
The plan was is to forward touch events automatically, but this is a little bit complicated and may come later down the line
@binaryblues It looks like DeltaTime was not being passed properly to scene:update() causing it to stall voxel updates. I’ve pushed a fix which will be in the next beta and app store versions
@UberGoober I’m sure when Codea 4 comes out, all of this will be included in the docs. You can copy this info and save it till then. There are too many useless/not updated things already pinned at the top of the forum.
@dave1707 The suggested lack of value of other pinned things doesn’t seem relevant to the decision of whether or not to add something new of high value.
Craft is hard for people to learn, and these enhancements can make it much easier to get started with, and there is literally no other way to learn about them.
@UberGoober There are other ways to learn about those enhancements so you don’t need to pin a couple of lines of code at the top of the forum. The majority of new users probably look at example code (written by you) to see how to do Craft code. So if all your example code has those enhancements in them then the new users will see them and know how to use them. That would be more effective then something pinned that someone probably won’t look at anyways. My opinion is examples are more beneficial when learning something new with dome documentation as a helper.
@dave1707 I myself can’t use these enhancements without looking at this reference—and I suggested some of them! And if I need the reference, newer users need it even more.
@UberGoober You should only need it once and that’s when you use it in one of your own examples. After that you refer to your own code and don’t have to hunt thru the forum looking for something you remember seeing. At least that’s what I do when I see something new or interesting.