[Resolved] Critique code please!

I am trying to get the following code to work, but so far it does not work. I got the code off a sprite tutorial from anscamobile. All I did was copy and paste. I have not edited anything except the file name to load my spritesheet that is in the main project directory.
require “sprite”
local sheet1 = sprite.newSpriteSheet(“Flames.png”, 100, 100)
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 15)
local instance1 = sprite.newSprite(spriteSet1)
instance1.x = display.contentWidth/2
instance1.y? = display.contentHeight/2
instance1:play()
So all in all it looks like it should work, but doesn’t. Can anyone help me get it working? Im still in learning mode here so every bit of help is appreciated.

Also, if there is a better way of loading and playing a spritesheet, please post! I have tried a few things but my options are limited as, once again, im still learning about Lua…

Thank you. [import]uid: 157993 topic_id: 30190 reply_id: 330190[/import]

you have to define a sprite sequence on SpriteSet1 and then do a :prepare before :play

By the way, this method of doing sprites is the “old” method. There is the new sprites API. See http://www.coronalabs.com/blog/2012/03/06/image-sheets-image-groups-and-sprites/ [import]uid: 160496 topic_id: 30190 reply_id: 120906[/import]

Not only that but you also need to edit the code so the dimensions/frame count actually match your own sheet if they don’t already.

@Mike - I still use the “old” method :wink: [import]uid: 52491 topic_id: 30190 reply_id: 120945[/import]

peach - so do I :slight_smile: I find it more comfortable. [import]uid: 160496 topic_id: 30190 reply_id: 120948[/import]

Ok, so thanks for the post. I read the update but it confuses me. I dont understand the structure of loading in a sprite sheet.

Know of any other resource that explains how to do sprites? I would like to learn the new way considering i am still quite new to learning Corona, but so far i just dont get it… >_>

I get everything else so far, like if statements, functions, variables, etc., but for some reason sprites just throw me off. Im still trying to understand the new way to do it so if anyone has got it to work, please show me how you did it.

Thank you. [import]uid: 157993 topic_id: 30190 reply_id: 120979[/import]

Forgot to include this code I am trying to get to work…

–Start of code
require (“sprites”)

local options =
{
– array of tables representing each frame (required)
frames =
{
– FRAME 1:
{
– all params below are required for each frame
x = 2,
y = 200,
width = 50,
height = 50
},

– FRAME 2:
{
x = 2,
y = 200,
width = 50,
height = 50
},

}

local fireSprite = graphics.newImageSheet( “Flames.png”, options )

–End of code

That is what i am trying to get to work now…It doesnt work and i am not sure why. Help please, anyone?
[import]uid: 157993 topic_id: 30190 reply_id: 120982[/import]

Can you look in Corona build 840 folder-
SampleCode > Sprites > JungleScene ?

That has a working example and doesn’t require you to specify frame info in the way you are doing so there. (Just so I know, as I’m not overly familiar with new sprite APIs yet - where did you learn about setting up frame info? Texture Packer?)

Take a look at that and tell me how you go. [import]uid: 52491 topic_id: 30190 reply_id: 121111[/import]

Sorry, I shoulda updated this…Anyway, Its funny you comment as I found a working tutorial on your techority page that helped me alot. I dont have the link to the page…but I understand sprites now. Thanks! :wink: [import]uid: 157993 topic_id: 30190 reply_id: 121166[/import]

I actually saw a comment on one of my sprite tutes; I guess that was you? Fantastic to hear it either way, really love it when I can help - especially nice when past work, like tutes, help new people. It reminds me of why I write them to begin with :wink: [import]uid: 52491 topic_id: 30190 reply_id: 121439[/import]

Yep, it was me.^^ [import]uid: 157993 topic_id: 30190 reply_id: 121518[/import]

you have to define a sprite sequence on SpriteSet1 and then do a :prepare before :play

By the way, this method of doing sprites is the “old” method. There is the new sprites API. See http://www.coronalabs.com/blog/2012/03/06/image-sheets-image-groups-and-sprites/ [import]uid: 160496 topic_id: 30190 reply_id: 120906[/import]

Awesome - thank you for confirming :slight_smile: [import]uid: 52491 topic_id: 30190 reply_id: 121579[/import]

Not only that but you also need to edit the code so the dimensions/frame count actually match your own sheet if they don’t already.

@Mike - I still use the “old” method :wink: [import]uid: 52491 topic_id: 30190 reply_id: 120945[/import]

peach - so do I :slight_smile: I find it more comfortable. [import]uid: 160496 topic_id: 30190 reply_id: 120948[/import]

Ok, so thanks for the post. I read the update but it confuses me. I dont understand the structure of loading in a sprite sheet.

Know of any other resource that explains how to do sprites? I would like to learn the new way considering i am still quite new to learning Corona, but so far i just dont get it… >_>

I get everything else so far, like if statements, functions, variables, etc., but for some reason sprites just throw me off. Im still trying to understand the new way to do it so if anyone has got it to work, please show me how you did it.

Thank you. [import]uid: 157993 topic_id: 30190 reply_id: 120979[/import]

Forgot to include this code I am trying to get to work…

–Start of code
require (“sprites”)

local options =
{
– array of tables representing each frame (required)
frames =
{
– FRAME 1:
{
– all params below are required for each frame
x = 2,
y = 200,
width = 50,
height = 50
},

– FRAME 2:
{
x = 2,
y = 200,
width = 50,
height = 50
},

}

local fireSprite = graphics.newImageSheet( “Flames.png”, options )

–End of code

That is what i am trying to get to work now…It doesnt work and i am not sure why. Help please, anyone?
[import]uid: 157993 topic_id: 30190 reply_id: 120982[/import]

Can you look in Corona build 840 folder-
SampleCode > Sprites > JungleScene ?

That has a working example and doesn’t require you to specify frame info in the way you are doing so there. (Just so I know, as I’m not overly familiar with new sprite APIs yet - where did you learn about setting up frame info? Texture Packer?)

Take a look at that and tell me how you go. [import]uid: 52491 topic_id: 30190 reply_id: 121111[/import]

Sorry, I shoulda updated this…Anyway, Its funny you comment as I found a working tutorial on your techority page that helped me alot. I dont have the link to the page…but I understand sprites now. Thanks! :wink: [import]uid: 157993 topic_id: 30190 reply_id: 121166[/import]

I actually saw a comment on one of my sprite tutes; I guess that was you? Fantastic to hear it either way, really love it when I can help - especially nice when past work, like tutes, help new people. It reminds me of why I write them to begin with :wink: [import]uid: 52491 topic_id: 30190 reply_id: 121439[/import]

Yep, it was me.^^ [import]uid: 157993 topic_id: 30190 reply_id: 121518[/import]