Howdy, Stranger!

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

SpriteSheet Class with Frame Coord system

BriarfoxBriarfox Mod
edited March 2013 in Code Sharing Posts: 1,542

This is still a work in progress. I am new to this and would like feedback

This will take a sprite sheet and create individual sprites from it. You can then create animations by selecting what frames to display using the bottom left sprite as 1

Sprite Used in Demo -
code -


  • BriarfoxBriarfox Mod
    Posts: 1,542

    if anyone wants to help me out I had an issue in the main.lua

    coord = vec2(100,100)
    size = vec2(100,100)
    inc = 100
    cat = "cat1"
    --cat 2
    coord.x = coord.x +inc
    cat = "cat2"

    This would not work I had to inc coord.x by
    coord = vec2(coord.x+inc,coord.y) why?

  • IgnatzIgnatz Mod
    Posts: 5,396

    If you want the cats to be next to each other and not on top of each other, then you need to increment the x value for each new cat

  • Posts: 887

    I think what you are asking is:
    Why does


    work, but incrementing coord.x outside the vec2 doesn't


    In other words, why can't you reference coord.x directly?

    Unfortunately, I don't know the answer - I'm guessing a vec2 is a special case?

  • Jmv38Jmv38 Mod
    Posts: 3,297

    The problem must be somewhere else in your program. This works exactly as expected:

    -- test vec2
    function setup()
        v = vec2(100,200)
        v.x = v.x + 10
    function draw()
  • Jmv38Jmv38 Mod
    edited March 2013 Posts: 3,297

    Ok i've got it. Line 157 you write.
    Coord = screenCoord
    So you think you have copied screen Coord to coord... But no, you have copied the adress of screenCoords to coord: the two are pointing to the same memory location now. A class is a complex object, so the = asignment does not pass the value but the adress. if you want a real copy of the values, you must copy all fields as for variable b in below example:

    -- test vec2 function setup()     v = vec2(100,0)     a = v     b = vec2() ; b.x = v.x ; b.y = v.y     print("v = "..tostring(v))     print("a = "..tostring(a))     print("b = "..tostring(b))     v.x = v.x + 100     print("v = "..tostring(v))     print("a = "..tostring(a))     print("b = "..tostring(b)) end function draw() end

    Check the lua manual for types that are passed by value (numbers,booleans,strings?) everything else is passed as adress. Strings are not really passed as value, the adress is passed, but since in lua you never modify a string, you just create a new one, the result is the same.

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Thank you Jmv38, that was driving me crazy, perfect example.

  • Posts: 666

    You need to write a deepcopy() routine. I have one somewhere...i found it online. It handles tables. I don,t recall if it handles userdata, which is vec2, color, etc.

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Thanks aciolino, I had no idea what a deep copy was. Looks like I've been doing shallow copies. if you happen to run across you code I would like to see it.

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Updated to allow easier movement of mesh and uses rotation and translation now.

  • Posts: 18

    Briarfox : the previous links (above) are dead on purpose ?

  • BriarfoxBriarfox Mod
    Posts: 1,542

    I dont believe I deleted it on purpose. Its a library that has become very messy. I used it in a small game. I have plans on cleaning it up and will repost it.

Sign In or Register to comment.