Sprites ignore object.width and object.height?

The following code creates a sprite and scales it to 64 x 64.

local spriteSheet = graphics.newImageSheet("images/spriteSheet.png", {width = 32, height = 32, numFrames = 96})  
  
local sequenceData =   
 {  
 {name = "walkUp", sheet = spriteSheet, frames = {85, 86}, time = 500, loopCount = 0},  
 {name = "walkDown", sheet = spriteSheet, frames = {49, 50}, time = 500, loopCount = 0},  
 {name = "walkLeft", sheet = spriteSheet, frames = {61, 62}, time = 500, loopCount = 0},  
 {name = "walkRight", sheet = spriteSheet, frames = {73, 74}, time = 500, loopCount = 0}  
 }  
local sprite = display.newSprite(spriteSheet, sequenceData)  
  
sprite.x = 500  
sprite.y = 500  
sprite.width = 64  
sprite.height = 64  

The moment I play an animation, the sprite scales back to 32 x 32.

sprite:setSequence("walkDown")  
sprite:play()  

What am I doing wrong here? I need the sprite to stay the size I set it to. I can’t just change the imageSheet; the sprite must be able to scale to many different sizes on the fly. [import]uid: 99903 topic_id: 33591 reply_id: 333591[/import]

What happens if you put the sprite inside a displayGroup and scale the group instead?

I imagine that the frame display sequence is following the frame data (which says 32x32) but it would be interesting to see if a displayGroup could be used to maintain scale. [import]uid: 41884 topic_id: 33591 reply_id: 133497[/import]

Hello @dyson122,
The size of sprites is associated with the image sheet. If you want to scale the object individually, you can use the scale APIs .xScale, .yScale, :scale(x,y). However, you’re eventually going to encounter some issues with collision (assuming you’ll need to implement it) because physics bodies don’t inherently scale along with the image (this would apply to if you were manually resizing using .width and .height too). So, you can scale the sprite but you’ll need to remove and replace the physics body during or after the scale transition to match the new size of the object.

Hope this helps somewhat,
Brent Sorrentino [import]uid: 200026 topic_id: 33591 reply_id: 133505[/import]

Thanks for the suggestions, guys. I haven’t tried scaling display groups because it would cause all hell to break lose with what I have written so far. XScale and yScale worked great, though. I never use the physics API, so that isn’t a problem.

local spriteSheet = graphics.newImageSheet("images/spriteSheet.png", {width = 32, height = 32, numFrames = 96})  
  
--ADD SPRITE  
local layer = 10  
local setup = {kind = "sprite", layer = layer, locX = 29, locY = 21}  
local options = {  
 imageSheet = spriteSheet,  
 sequenceData =   
 {  
 {name = "walkUp", sheet = spriteSheet, frames = {85, 86}, time = 500, loopCount = 0},  
 {name = "walkDown", sheet = spriteSheet, frames = {49, 50}, time = 500, loopCount = 0},  
 {name = "walkLeft", sheet = spriteSheet, frames = {61, 62}, time = 500, loopCount = 0},  
 {name = "walkRight", sheet = spriteSheet, frames = {73, 74}, time = 500, loopCount = 0}  
 },  
 xScale = mte.findScale(32, layer),  
 yScale = mte.findScale(32, layer)  
}  
local sprite = mte.addObject(setup, options)  
  
sprite:setSequence("walkDown")  
sprite:play()  

I appreciate the quick responses! [import]uid: 99903 topic_id: 33591 reply_id: 133517[/import]

What happens if you put the sprite inside a displayGroup and scale the group instead?

I imagine that the frame display sequence is following the frame data (which says 32x32) but it would be interesting to see if a displayGroup could be used to maintain scale. [import]uid: 41884 topic_id: 33591 reply_id: 133497[/import]

Hello @dyson122,
The size of sprites is associated with the image sheet. If you want to scale the object individually, you can use the scale APIs .xScale, .yScale, :scale(x,y). However, you’re eventually going to encounter some issues with collision (assuming you’ll need to implement it) because physics bodies don’t inherently scale along with the image (this would apply to if you were manually resizing using .width and .height too). So, you can scale the sprite but you’ll need to remove and replace the physics body during or after the scale transition to match the new size of the object.

Hope this helps somewhat,
Brent Sorrentino [import]uid: 200026 topic_id: 33591 reply_id: 133505[/import]

Thanks for the suggestions, guys. I haven’t tried scaling display groups because it would cause all hell to break lose with what I have written so far. XScale and yScale worked great, though. I never use the physics API, so that isn’t a problem.

local spriteSheet = graphics.newImageSheet("images/spriteSheet.png", {width = 32, height = 32, numFrames = 96})  
  
--ADD SPRITE  
local layer = 10  
local setup = {kind = "sprite", layer = layer, locX = 29, locY = 21}  
local options = {  
 imageSheet = spriteSheet,  
 sequenceData =   
 {  
 {name = "walkUp", sheet = spriteSheet, frames = {85, 86}, time = 500, loopCount = 0},  
 {name = "walkDown", sheet = spriteSheet, frames = {49, 50}, time = 500, loopCount = 0},  
 {name = "walkLeft", sheet = spriteSheet, frames = {61, 62}, time = 500, loopCount = 0},  
 {name = "walkRight", sheet = spriteSheet, frames = {73, 74}, time = 500, loopCount = 0}  
 },  
 xScale = mte.findScale(32, layer),  
 yScale = mte.findScale(32, layer)  
}  
local sprite = mte.addObject(setup, options)  
  
sprite:setSequence("walkDown")  
sprite:play()  

I appreciate the quick responses! [import]uid: 99903 topic_id: 33591 reply_id: 133517[/import]