display.newSprite Scale?

Is there a way to scale sprite? Or maybe scale image sheets?

Hi @naitver,

Yes, you can scale a sprite after you create it, but image sheets don’t get scaled… you’re basically pulling a frame from the image sheet (or a series of frames for an animated sprite) and then, after you create the sprite, you can scale it.

One word of caution: if you’re using physics and making your sprites into physical bodies, you should not scale them. The actual sprite will scale, visually, but the physics engine will not consider the internal body definition scaled, so collisions will not behave as you might expect.

If you’re not using physics, you can disregard the above paragraph. :slight_smile:

Brent

Here are some sprite examples (showing scaling and other features) as examples too:

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites.zip

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites2.zip

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites3.zip

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites4.zip

If I try and sprite:scale(1,-1) to flip the animated sprite it doesn’t. I can change the rotation but can’t do a flip on the X or Y axis. Ideas?

Hi @lessmsios,

Can I see your code? I use the :scale() function to flip an animated sprite and it works fine. 

Brent

@lessmsios,

The examples I linked above do scaling (I just double checked them with build 2016.2809), better double check your code.

Also, if you are still running into issues, please do your code, i.e. like this:

-- Create sprite, play 'leftwalk' local tmp = display.newSprite( pinkySheet, pinkySeqData ) tmp.x = display.contentCenterX + 300 tmp.y = display.contentCenterY --tmp.xScale = -1 -- works tmp:scale(-1,1) -- also works tmp:setSequence( "leftwalk" ) tmp:play()

-Ed

Turned out to be programmer error. There was a different routine being called that was resetting the orientation. Thanks for the fast replies!

David

Hi @naitver,

Yes, you can scale a sprite after you create it, but image sheets don’t get scaled… you’re basically pulling a frame from the image sheet (or a series of frames for an animated sprite) and then, after you create the sprite, you can scale it.

One word of caution: if you’re using physics and making your sprites into physical bodies, you should not scale them. The actual sprite will scale, visually, but the physics engine will not consider the internal body definition scaled, so collisions will not behave as you might expect.

If you’re not using physics, you can disregard the above paragraph. :slight_smile:

Brent

Here are some sprite examples (showing scaling and other features) as examples too:

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites.zip

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites2.zip

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites3.zip

http://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2015/09/sprites4.zip

If I try and sprite:scale(1,-1) to flip the animated sprite it doesn’t. I can change the rotation but can’t do a flip on the X or Y axis. Ideas?

Hi @lessmsios,

Can I see your code? I use the :scale() function to flip an animated sprite and it works fine. 

Brent

@lessmsios,

The examples I linked above do scaling (I just double checked them with build 2016.2809), better double check your code.

Also, if you are still running into issues, please do your code, i.e. like this:

-- Create sprite, play 'leftwalk' local tmp = display.newSprite( pinkySheet, pinkySeqData ) tmp.x = display.contentCenterX + 300 tmp.y = display.contentCenterY --tmp.xScale = -1 -- works tmp:scale(-1,1) -- also works tmp:setSequence( "leftwalk" ) tmp:play()

-Ed

Turned out to be programmer error. There was a different routine being called that was resetting the orientation. Thanks for the fast replies!

David