TexturePacker exporters for Codea (Easy sprite sheet import and use!)

@HaroBlack thank you, mmm… The problem which I am wondering about is the position shifting in-between the BoundaryBox and the actual sprites, I expected a shift for poth of them!.
Anyway I tried your suggestion but unfortunately nothing changed!

Sorry @aosama, just noticed your post. Can you post your code for me to look at? I’ve not seen this issue.

@toadkick. Thanks, Here is the code

function draw()

background(0)

translate(WIDTH/2,HEIGHT/2) -- try to comment this line to see the difference

local sprites = {
    "Base Large",
    "Beam",
    "Church",
    "Court",
    "Explosion"
}

local x = 0
for i,spr in ipairs(sprites) do
    local w, h = batch:spriteSize(spr)
  batch:sprite(spr,0, 0)     
end    
batch:draw()

end

@aosama: Ah yes, I see the issue. Here’s the fix:

function draw()

background(0)

translate(WIDTH/2,HEIGHT/2) -- try to comment this line to see the difference

local sprites = {
    "Base Large",
    "Beam",
    "Church",
    "Court",
    "Explosion"
}

local x = 0
for i,spr in ipairs(sprites) do
    local w, h = batch:spriteSize(spr)
  batch:sprite(spr,0, 0)     
end

translate(0, 0)    
batch:draw()
end

What’s going on here is that whenever you call batch:sprite(), the ‘sprite’ is created with the current transform information (in this case, with a translation of WIDTH/2, HEIGHT/2). But, it doesn’t actually get drawn until batch:draw() is called. Since your translation is still WIDTH/2, HEIGHT/2 at the time batch:draw() is called, your batch is also getting drawn with that translation, so your sprite is actually getting drawn at (WIDTH, HEIGHT). Does that make sense?

@toadkick : I thought that translate will affect all the following commands once time… Anyway I tried your fix…but it did not fix the problem !!

@aosama: ugh, sorry, that was a stupid mistake on my part. What I meant was:


function draw()
    background(0)

    pushMatrix()

    translate(WIDTH/2,HEIGHT/2) -- try to comment this line to see the difference

    local sprites = {
        "Base Large",
        "Beam",
        "Church",
        "Court",
        "Explosion"
    }

    local x = 0
    for i,spr in ipairs(sprites) do
        local w, h = batch:spriteSize(spr)
        batch:sprite(spr,0, 0)     
    end

    popMatrix()

    batch:draw()
end

@toadkick : Finally it works fine, but I have to learn more about translate cause It makes me little bit confused. Thanks

@aosama: FWIW, you don’t have to use translate() (or the view matrix at all) to position your sprites if you aren’t building a scene graph (if you don’t know what a scene graph is, you probably aren’t building one, and you probably don’t need to mess with the view matrix). You can just pass the x and y position to batch:sprite() (just like Codea’s sprite())

Like this:


function draw()
    background(0)

    local sprites = {
        "Base Large",
        "Beam",
        "Church",
        "Court",
        "Explosion"
    }

    for i, spr in ipairs(sprites) do
        batch:sprite(spr, WIDTH/2, HEIGHT/2)
    end

    batch:draw()
end

@toadkick : you are right, but as I told you this story started with Lua Jump example where it uses the translate feature.

Probably should move the batch table creator outside of draw()