No animation, then (as in, a way to manage joint rotations). What I have now should be what you need:
Code: Select all
graphics = {
-- index 1 is the image, w is the width, and h is the height
stem = {love.graphics.newImage("stem.png"),w=16,h=29},
}
-- here's a demonstration bone structure
flower = {
-- x and y are treated as coordinate overrides - you'll likely only want them on the first bone.
x=400, y=500,
-- a, l, and i are angle (in radians), length (in pixels), and image (see above for image declaration)
a=math.pi, l=60, i=graphics.stem,
-- child bones are contained in the parts table
parts = {
-- child bones work exactly the same way as the parent bone, with the same variables
{a=1, l=30, i=graphics.stem},
{a=-1, l=40, i=graphics.stem,
-- child bones can have their own child bones (which can have their own child bones, etc.)
parts = {{a=1, l=20, i=graphics.stem,},},
},
},
}
function love.draw()
-- draw the bone structure (you could also draw any individual branch of it with this same function)
bonedraw(flower)
end
-- don't screw with this part unless you want to declare bones in a different format or something...
function bonedraw(bone, x,y, a)
x,y,a = bone.x or x, bone.y or y, (a or 0) + (bone.a or 0)
local s = bone.l / bone.i.h
love.graphics.draw(bone.i[1], x,y, a, s,s, bone.i.w/2,0)
x,y = x-bone.l*math.sin(a), y+bone.l*math.cos(a)
if bone.parts then for k,v in pairs(bone.parts) do bonedraw(v, x,y, a) end end
end
bonedraw is responsible for drawing a bone structure. You can add more bones to a joint by simply using table.insert(bone.parts, {a=angle, l=length, i=image}) (you can name bones, if you prefer). Please note from above that image needs to be a table containing an image in index 1, and image width and height at indices "w" and "h" (tip: by using a height that's less than the full height of the image, you can have image overlap on joints). As for the graphic, the top-center of the image is the origin of the bone, and the bottom-center is its joint (the end where child bones will attach).
To do the growing thing you want, just increase a bone's length over time and add a new segment when it's full length.
EDIT) With a bit of playing around, you can easily get something like this:
If you can't figure it out yourself, let's start a new thread, since it would be off-topic for this one.