How can I position a sprite animation at the edge of the screen? Spritesheet made with texturepacker

Hello,

I have created a Sprite Sheet (actually 3 sheets with different suffixes) using TexturePacker, however I got a problem. I try to load a sprite and position the sprite at the, bottom in this case, edge of the screen, however when I do this, the top half of the sprite would be on the screen, while the bottom half would be out of the screen. How do I fix this? How do I lift up the sprite so that it sits exactly at the bottom of the screen, indifferent of the resolution or device. The way I did it before, when I used sprite sheets made manually and not with TexturePacker, is that I simply knew the height of the sprite(it was only for one resolution) and I just set 

[lua]sprite.y = display.contentHeight - spriteHeight/2[/lua]

where spriteHeight was known by me.

So how do I do this?

Thanks in advance!

Calin

The sprite object should have a width and height attribute you can use:

sprite.y = display.contentHeight - sprite.height/2

Great! Thanks! That solves it. I’ve got one more question, however, if possible: is there a way to read the resolution of the device my game is running on? I know I declared some kind of intended resolution in config.lua, however, is there a way I could find the current resolution of the device?

Why I’m asking is because I would like to have some kind of border built from 4 parts, but I want this border to keep the same thickness relative to the device’s edge, no matter the resolution of the device. Is this possible? 

On Android there are ways to determine the actual device size.  Look at the system.getInfo() API library call.  For iOS those don’t exist, but because the device set is limited and the screen sizes well known, you can look up the device and go from there.  In general, with Corona SDK you do not need to know that.  We create a virtual canvas based on the values you provide in your config.lua. 

display.contentWidth and display.contentHeight will reflect the values in your config.lua

display.actualContentWidth and display.actualContentHeight will reflect the size of the screen when you’re using letterbox mode and the screen is a different shape than the values you provided in the config.lua.  For instance, lets say you did this:

width = 640

height = 960

in your config.lua, which is the size of an iPhone 4 screen.  On an iPhone 5, you would get:

display.contentWidth = 640

display.contentHeight = 960

display.actualContentWidth = 640

display.actualContentHeight = 1136

But if you did a width of 320 and height of 480, then you would get:

display.contentWidth = 320

display.contentHeight = 480

display.actualContentWidth = 320

display.actualContentHeight = 568

If you did a width of 800 and a height of 1200 then you would get:

display.contentWidth = 800

display.contentHeight = 1200

display.actualContentWidth = 800

display.actualContentHeight = 1420

It’s all scaled based on your requested content area.  If you use a set width and height in your config.lua, then there is no guarentee that 0, 0 will be the top left corner and that display.contentWidth, display.contentHeight will be the bottom right corner.  However in that circumstance display.actualContentWidth, display.actualContentHeight will be the bottom left corner.   There are two other important values:

display.screenOriginX

display.screenOriginY

which is the actual x and y of the top left corner.

Thank you!

The sprite object should have a width and height attribute you can use:

sprite.y = display.contentHeight - sprite.height/2

Great! Thanks! That solves it. I’ve got one more question, however, if possible: is there a way to read the resolution of the device my game is running on? I know I declared some kind of intended resolution in config.lua, however, is there a way I could find the current resolution of the device?

Why I’m asking is because I would like to have some kind of border built from 4 parts, but I want this border to keep the same thickness relative to the device’s edge, no matter the resolution of the device. Is this possible? 

On Android there are ways to determine the actual device size.  Look at the system.getInfo() API library call.  For iOS those don’t exist, but because the device set is limited and the screen sizes well known, you can look up the device and go from there.  In general, with Corona SDK you do not need to know that.  We create a virtual canvas based on the values you provide in your config.lua. 

display.contentWidth and display.contentHeight will reflect the values in your config.lua

display.actualContentWidth and display.actualContentHeight will reflect the size of the screen when you’re using letterbox mode and the screen is a different shape than the values you provided in the config.lua.  For instance, lets say you did this:

width = 640

height = 960

in your config.lua, which is the size of an iPhone 4 screen.  On an iPhone 5, you would get:

display.contentWidth = 640

display.contentHeight = 960

display.actualContentWidth = 640

display.actualContentHeight = 1136

But if you did a width of 320 and height of 480, then you would get:

display.contentWidth = 320

display.contentHeight = 480

display.actualContentWidth = 320

display.actualContentHeight = 568

If you did a width of 800 and a height of 1200 then you would get:

display.contentWidth = 800

display.contentHeight = 1200

display.actualContentWidth = 800

display.actualContentHeight = 1420

It’s all scaled based on your requested content area.  If you use a set width and height in your config.lua, then there is no guarentee that 0, 0 will be the top left corner and that display.contentWidth, display.contentHeight will be the bottom right corner.  However in that circumstance display.actualContentWidth, display.actualContentHeight will be the bottom left corner.   There are two other important values:

display.screenOriginX

display.screenOriginY

which is the actual x and y of the top left corner.

Thank you!

hi, What would be the problem if the picture won’t show in the simulator? it only shows white screen… I didn’t use texture because I don’t have a license… Thank you so much.

hi, What would be the problem if the picture won’t show in the simulator? it only shows white screen… I didn’t use texture because I don’t have a license… Thank you so much.