SpriteSheet Only Displaying the First Frame - HELP!

Hello everyone,

I having a little issue with spritesheets.  It maybe a very small tweak that’s needed, but I just cant seem to get it to work.

Here’s the issue:

 I am playing around with a quick concept for a boggle game.  I have a grid (4x4) that holds letters of the alphabet.  These letters are being generated randomly from a spritesheet image.  Here’s the code:

local options = { width = 70, height = 65, numFrames = 26 } local letterSheet = graphics.newImageSheet( "IMG/boggletiles.png", options ) local sequenceData = { { name = "letters", start=1, count=26, time=1000, loopCount=1 } }

And then I have the following for getting the letters into a grid (randomly), and mask which is used for when player taps the letter:

---LETTER TILES ---- local letterList = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} local letter = {} local mask = {} local letterGroup = display.newGroup( ) group:insert(letterGroup) local maskGroup = display.newGroup( ) group:insert(maskGroup) --masks for x = 1, 4 do for y = 1, 4 do mask[#mask+1] = display.newImageRect( "IMG/mask.png", 70, 65 ) mask[#mask].x = x\*70-15 mask[#mask].y = y\*65+70 mask[#mask].isVisible = false maskGroup:insert(mask[#mask]) end end --setSequence( "c" ) --display.newSprite( letterSheet, sequenceData ) --LETTERS for x = 1, 4 do for y= 1, 4 do letter[#letter+1] = display.newSprite( letterSheet, sequenceData ) --sprite.newSprite(letterSet) letter[#letter].x = x\*70-15 letter[#letter].y = y\*65+70 letter[#letter].currentFrame = math.random(1,26) letter[#letter].val = letterList[letter[#letter].currentFrame] letter[#letter].state = "unspent" letter[#letter].mask = mask[#letter] letter[#letter]:addEventListener("tap", tapLetter) topBarGroup:insert( letter[#letter] ) end end topBarGroup:insert(letterGroup) topBarGroup:insert(maskGroup)

Everything works as intended - I get the correct mapping of each letter value etc… However,

all I see is letter “A” being displayed in every row and column, which means that the spriteSheet is only “sitting” on the first frame, and not going through all the 26 letters of the alphabet.  Does this make sense?

What Am I doing wrong that’s preventing from the sprite to show all the frames?

I have attached an image so you can see what I am talking about.

Any help is highly appreciated.

Thanks

Looks like you should be doing this before the line where you add your event listener for example:

letter[#letter]:setSequence( tolower( letterList[math.random( 1, #letterList )] ) )

Hope this helps.

Gremlin,

Thanks for your response.  I just added the proposed line of code before the event listener, and it’s still showing the first letter in all tiles.

Here’s the the code after adding the line ( By the way, since I still want the letters to be upper case, I left out the toLowercase() function)
 

for x = 1, 4 do for y= 1, 4 do letter[#letter+1] = display.newSprite( letterSheet, sequenceData ) --sprite.newSprite(letterSet) letter[#letter].x = x\*70-15 letter[#letter].y = y\*65+70 letter[#letter].currentFrame = math.random(1,26) letter[#letter].val = letterList[letter[#letter].currentFrame] letter[#letter].state = "unspent" letter[#letter].mask = mask[#letter] letter[#letter]:setSequence( letterList[math.random( 1, #letterList )] ) --ADDED LINE letter[#letter]:addEventListener("tap", tapLetter) topBarGroup:insert( letter[#letter] ) end end

Any other tips?  I feel like it maybe just a matter of a small change for this to work, but I can’t see it unfortunately :frowning:

The tolower() function call isn’t doing what you think it is doing, in this context. It isn’t changing the characters displayed, it’s changing the capital letters in your table, that are passed to the setSequence() call to lowercase, so it matches the names in your lua data file.

That is, i’m assuming your using texture packer or something. If not, and the code is just what you posted up and nothing else, then this should work:

letters[#letters]:setSequence( math.random( 1, #letterList) )

If that doesn’t work, then you may be missing some required parameters in your sequence data table, my memory is fuzzy on what is actually required there, since i always use Texture Packer to save time.

The Corona docs on this subject should clear that up for you. There is also some helpful blog posts you can find on this site by doing a quick google search.

Thanks again for your help.  I figured out by playing around what you suggested and it works now.  All I had to do was to actually add 

letter[#letter]:setSequence(letterList[letter[#letter].currentFrame] )

Thanks again! Really appreciate it!

[quote=“magadistudio,post:5,topic:325751”]

Thanks again for your help. I figured out by playing around what you suggested and it works now. All I had to do was to actually add

letter[#letter]:setSequence(letterList[letter[#letter].currentFrame] )

Thanks again! Really appreciate it! [/quote]

Essentially the same thing yeah :slight_smile:

Glad you got it working. Happy to help.

Looks like you should be doing this before the line where you add your event listener for example:

letter[#letter]:setSequence( tolower( letterList[math.random( 1, #letterList )] ) )

Hope this helps.

Gremlin,

Thanks for your response.  I just added the proposed line of code before the event listener, and it’s still showing the first letter in all tiles.

Here’s the the code after adding the line ( By the way, since I still want the letters to be upper case, I left out the toLowercase() function)
 

for x = 1, 4 do for y= 1, 4 do letter[#letter+1] = display.newSprite( letterSheet, sequenceData ) --sprite.newSprite(letterSet) letter[#letter].x = x\*70-15 letter[#letter].y = y\*65+70 letter[#letter].currentFrame = math.random(1,26) letter[#letter].val = letterList[letter[#letter].currentFrame] letter[#letter].state = "unspent" letter[#letter].mask = mask[#letter] letter[#letter]:setSequence( letterList[math.random( 1, #letterList )] ) --ADDED LINE letter[#letter]:addEventListener("tap", tapLetter) topBarGroup:insert( letter[#letter] ) end end

Any other tips?  I feel like it maybe just a matter of a small change for this to work, but I can’t see it unfortunately :frowning:

The tolower() function call isn’t doing what you think it is doing, in this context. It isn’t changing the characters displayed, it’s changing the capital letters in your table, that are passed to the setSequence() call to lowercase, so it matches the names in your lua data file.

That is, i’m assuming your using texture packer or something. If not, and the code is just what you posted up and nothing else, then this should work:

letters[#letters]:setSequence( math.random( 1, #letterList) )

If that doesn’t work, then you may be missing some required parameters in your sequence data table, my memory is fuzzy on what is actually required there, since i always use Texture Packer to save time.

The Corona docs on this subject should clear that up for you. There is also some helpful blog posts you can find on this site by doing a quick google search.

Thanks again for your help.  I figured out by playing around what you suggested and it works now.  All I had to do was to actually add 

letter[#letter]:setSequence(letterList[letter[#letter].currentFrame] )

Thanks again! Really appreciate it!

[quote=“magadistudio,post:10,topic:325751”]

Thanks again for your help. I figured out by playing around what you suggested and it works now. All I had to do was to actually add

letter[#letter]:setSequence(letterList[letter[#letter].currentFrame] )

Thanks again! Really appreciate it! [/quote]

Essentially the same thing yeah :slight_smile:

Glad you got it working. Happy to help.