I'm still using sprite.lua and it can't autoscale, what do I need to do?

hi, i am updating codes for my 2 years old game to accomodate higher res gadgets. After updating all images (to use higher res graphics), I find one problem with my game. I still use sprite.lua and “old” codes for sprites movement in my game:

waiter = sprite.newSpriteSheet("MonkeySprite.png", 56, 67) waiterset = sprite.newSpriteSet (waiter, 1, 12)

i use this kind of code for my sprites movement (such as player movement). because now i have much bigger sprite image, these codes dont work anymore because the autoscaling simply doesnt work here.

I changed all display.newImage codes to display.newImageRect for scaling issues but i wonder how to do the same thing with sprites? I have googled about this and found out this link: http://coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

but still, i am confused about how to “convert” my old sprite codes to the newer one so my sprite image can scale perfectly? Thanks.

Hi @brad2000xi,

When setting up the image sheets for your sprites, have you added the “sheetContentWidth” and “sheetContentHeight” parameters? This is required to make image sheets respect dynamic scaling, including sprites that are assembled from image sheets.

This guide specifies this better:

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Brent

hi this is where i get confused. i know i need to change my codes from newSpriteSheet stuffs to the newer ones like graphics.newImageSheet but i dont know what codes to substitute my movements. ok here’s my codes for the original player movement:

waiter = sprite.newSpriteSheet("MonkeySprite.png", 56, 67) waiterset = sprite.newSpriteSet (waiter, 1, 12) sprite.add (waiterset, "playerleft", 9, 4, 125, 0) sprite.add (waiterset, "playerright", 5, 4, 125, 0) player = sprite.newSprite(waiterset) player.x = display.contentWidth/2 player.y = display.contentHeight - display.contentWidth/10 player.name = "player" player:prepare("playerleft")

now I have modified some codes like this:

 local waiteroptions = { width = 56, height = 67, numFrames = 12, sheetContentWidth = 56, sheetContentHeight = 67 } waiter = graphics.newImageSheet("MonkeySprite.png", waiteroptions)

but then I got stuck… what to change for the rest of the codes? below the waiter code, I had -> “waiterset = sprite.newSpriteSet (waiter, 1, 12)”, should I delete that one? or do I need to change it to something else?

Also notice that I also have the sprite.add codes for the player movements, these ones:

 sprite.add (waiterset, "playerleft", 9, 4, 125, 0) sprite.add (waiterset, "playerright", 5, 4, 125, 0)

but what are the codes for these playerleft and playerright using the new Image Sheets? That’s the part where I’m confused.

Hi @brad2000xi,

The following document should help explain this. Basically, set up the image sheet to contain every frame you’ll need (I think you’re already doing this). Then, to create different sprite animations, you create sprite sequences as shown in the doc, and pass that data to the display.newSprite() constructor. This creates a sprite display object which “knows” those sequences, and then sequences can be played/paused/etc. upon that sprite object.

http://docs.coronalabs.com/api/library/display/newSprite.html

Hope this helps,

Brent

Hi @brad2000xi,

When setting up the image sheets for your sprites, have you added the “sheetContentWidth” and “sheetContentHeight” parameters? This is required to make image sheets respect dynamic scaling, including sprites that are assembled from image sheets.

This guide specifies this better:

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Brent

hi this is where i get confused. i know i need to change my codes from newSpriteSheet stuffs to the newer ones like graphics.newImageSheet but i dont know what codes to substitute my movements. ok here’s my codes for the original player movement:

waiter = sprite.newSpriteSheet("MonkeySprite.png", 56, 67) waiterset = sprite.newSpriteSet (waiter, 1, 12) sprite.add (waiterset, "playerleft", 9, 4, 125, 0) sprite.add (waiterset, "playerright", 5, 4, 125, 0) player = sprite.newSprite(waiterset) player.x = display.contentWidth/2 player.y = display.contentHeight - display.contentWidth/10 player.name = "player" player:prepare("playerleft")

now I have modified some codes like this:

 local waiteroptions = { width = 56, height = 67, numFrames = 12, sheetContentWidth = 56, sheetContentHeight = 67 } waiter = graphics.newImageSheet("MonkeySprite.png", waiteroptions)

but then I got stuck… what to change for the rest of the codes? below the waiter code, I had -> “waiterset = sprite.newSpriteSet (waiter, 1, 12)”, should I delete that one? or do I need to change it to something else?

Also notice that I also have the sprite.add codes for the player movements, these ones:

 sprite.add (waiterset, "playerleft", 9, 4, 125, 0) sprite.add (waiterset, "playerright", 5, 4, 125, 0)

but what are the codes for these playerleft and playerright using the new Image Sheets? That’s the part where I’m confused.

Hi @brad2000xi,

The following document should help explain this. Basically, set up the image sheet to contain every frame you’ll need (I think you’re already doing this). Then, to create different sprite animations, you create sprite sequences as shown in the doc, and pass that data to the display.newSprite() constructor. This creates a sprite display object which “knows” those sequences, and then sequences can be played/paused/etc. upon that sprite object.

http://docs.coronalabs.com/api/library/display/newSprite.html

Hope this helps,

Brent