how to enumerate thru the image sprite ?

Hi experts,

I have a question about how can I read thru sprite images and then i should be able enumerate the pictures when I need such as when I click on a button, the image changes to another picture … basically what i need is as follows  :

1- create sprite

2- create NextButton  to allow user to see the previous image

3 create  backButton to allow user to see the previous image

I tried to use the amimation:setFrame() but it was giving me errors as shown in the attachment … i am not sure why is that.

please help

Abdul

First, you have wrong options table passed when using newImageSheet. As you can see from warning, you have only 1 frame defined for image but you are trying to access 51st one.

Second, I hope that under ‘animation’ variable is spriteImage on which you are trying to call setSequence.

Last one, there is error next to some sign. It’s not standard sign in quotation mark, so check if you haven’t accidentally typed some special sign.

Hi Piotrz55,

thanks for comment, here is my table options , i am not sure where is the mistake :

[lua]

    local sheetData= {width= 90, height = 82, numFrames=14, sheetContentWidth=630,sheetContentHeight=170}

    local sheet =  graphics.newImageSheet(loadedPic, sheetData)

    

    letter = display.newSprite(sheet, sequenceDate)

    

    letter:setSequence( “L1” )

    --sprite.currentFrame(2)

    --letter:setFrame(2)

    letter.x = xScreen /2

    letter.y = yScreen /2

    --letter:rotate(5)

    letter:play ()

   

[/lua]

currently L1 represent one image from the frame for testing only because I was not able to enumerate thru the sprite so i had to put each letter in each sequence as follows :

[lua]

    local sequenceDate= 

    {

        {name=“L1”, start=1, count= 1, time = 500, loopCount= 1},

        {name=“L2”, start=2, count= 1, time = 500, loopCount= 1},

        {name=“L3”, start=3, count= 1, time = 500, loopCount= 1},

   }

[/lua]

what do you think the mistake is ?

please help

Hi @alzaabi980,

Is your “sequenceDate” table properly scoped above where you are trying to set a sequence? What error report or incorrect behavior are you seeing now? Remember that setting a frame number is based on the frame index within that specific sequence, not within the overall sheet. So, if each sequence represents just one frame in your case, you’ll always set that sequence… and actually, you don’t need to set the frame, as it will default to the first (only) frame in that 1-frame sequence.

Hope this helps,

Brent Sorrentino

First, you have wrong options table passed when using newImageSheet. As you can see from warning, you have only 1 frame defined for image but you are trying to access 51st one.

Second, I hope that under ‘animation’ variable is spriteImage on which you are trying to call setSequence.

Last one, there is error next to some sign. It’s not standard sign in quotation mark, so check if you haven’t accidentally typed some special sign.

Hi Piotrz55,

thanks for comment, here is my table options , i am not sure where is the mistake :

[lua]

    local sheetData= {width= 90, height = 82, numFrames=14, sheetContentWidth=630,sheetContentHeight=170}

    local sheet =  graphics.newImageSheet(loadedPic, sheetData)

    

    letter = display.newSprite(sheet, sequenceDate)

    

    letter:setSequence( “L1” )

    --sprite.currentFrame(2)

    --letter:setFrame(2)

    letter.x = xScreen /2

    letter.y = yScreen /2

    --letter:rotate(5)

    letter:play ()

   

[/lua]

currently L1 represent one image from the frame for testing only because I was not able to enumerate thru the sprite so i had to put each letter in each sequence as follows :

[lua]

    local sequenceDate= 

    {

        {name=“L1”, start=1, count= 1, time = 500, loopCount= 1},

        {name=“L2”, start=2, count= 1, time = 500, loopCount= 1},

        {name=“L3”, start=3, count= 1, time = 500, loopCount= 1},

   }

[/lua]

what do you think the mistake is ?

Hi Brent,

I changed the approach but still I am not happy with it. I did some workaround… From your experience what is the best option to tackle such issue. I want simply to load the imagesheet into table and then I should be able to enumerate thru the table and also I should know which is image is clicked so there is a special sound for each letter.

in other words. the app is basically will allow a kid to click on letter and there is a sound for each letter… the kid can click next or back to see next letter or previous letter respectively…

any advice is valuable to me ?

Regards

Abdul

Hi Abdul,

In this case, I would suggest that you build one sprite with all of the letters, in a specific order. Then just set the frame of the sprite to the letter (index) that you want to show. At the same time, play a sound associated with that letter.

Hope this helps,

Brent

please help

Hi @alzaabi980,

Is your “sequenceDate” table properly scoped above where you are trying to set a sequence? What error report or incorrect behavior are you seeing now? Remember that setting a frame number is based on the frame index within that specific sequence, not within the overall sheet. So, if each sequence represents just one frame in your case, you’ll always set that sequence… and actually, you don’t need to set the frame, as it will default to the first (only) frame in that 1-frame sequence.

Hope this helps,

Brent Sorrentino

Thanks Brent,

Hi Brent,

I changed the approach but still I am not happy with it. I did some workaround… From your experience what is the best option to tackle such issue. I want simply to load the imagesheet into table and then I should be able to enumerate thru the table and also I should know which is image is clicked so there is a special sound for each letter.

in other words. the app is basically will allow a kid to click on letter and there is a sound for each letter… the kid can click next or back to see next letter or previous letter respectively…

any advice is valuable to me ?

Regards

Abdul

Hi Abdul,

In this case, I would suggest that you build one sprite with all of the letters, in a specific order. Then just set the frame of the sprite to the letter (index) that you want to show. At the same time, play a sound associated with that letter.

Hope this helps,

Brent

Thanks Brent,