display group properties

so I am trying to modify something so that regardless of the device rotation it takes up the entire width and height of the screen

this is my code:

[lua]

.

.           – code inside of a orientation runtime listener 

.

            if oneGroup then – oneGroup being the displayGroup

                oneGroup:setReferencePoint(display.CenterReferencePoint)

                oneGroup:rotate(-event.delta)

                oneGroup.width = display.contentWidth

                oneGroup.height = display.contentHeight    

            end

.

.

.

[/lua]

However when I do this, it rotate the thing I want rotated, but doesn’t actually fill up the screen. It appears that it only rotated it and didn’t actually effect the height and width property, as the top and bottom of the screen and left blank and parts of the image is off the screen on both sides

Any suggestion as to where I am going wrong?

display.contentWidth and display.contentHeight are constants defined by the resolution of your device screen ( and your config settings if you are using content scaling ).

So they don’t change when you rotate the device.

You need to use some math to calculate the width and height the group should have to fill the screen.

“you need to use some math”

Care to elaborate on what kind perhaps? involving what properties?

If you have in config that your app is portrait, then on rotation you check if it’s landscape and then you swap width and height. Content sizes are always regarding start up setrings - are not dynamic.

As piotrz55 says, if the app starts in portrait, then display.contentWidth/Height are always in portrait.  Maybe you can just check system.rotation (see docs for system.*) and check for “portrait” vs “landscapeLeft”, etc. and then resize/rotate accordingly.

 @piotrz55 I understand you suggestion, but i’ve already swapped the two values around to understand behaviour. which prompted me to start this thread

For example:

[lua]

oneGroup.width = display.contentHeight

oneGroup.height = display.contentWidth

[/lua]

when switching between landscape and portrait modes the code above causes one of those things to happen:

  1. it doesn’t effect any sides, as if those calls were never made

  2. it seems to continually stretch the width and the height everytime you rotate, which perplexes me severely. Because those are asignment statements and not increment statements, I dont understand why the screen ‘blows up’ the display object

@jbp1, there isn’t a system.rotation, so I am assuming you meant to say system.orientation

I think now… that just swaping values is useless. You need to redraw everything, reposition it…

so, to understand what your saying. 

on orientation change:

  1. clear the screen

  2. detect current orientation

  3. call function that corresponds to current orientation 

So, i’ll need a function call that draws for a landscape screen, and a function that draws for a portrait?

I would go this way but not as drastic. Do not redraw everything, only things you need. You can reposition objects or reshape it if it’s enough. Remember that reshaped objects (eg vector rectangles) change theirs reference points if width or height is modified.

display.contentWidth and display.contentHeight are constants defined by the resolution of your device screen ( and your config settings if you are using content scaling ).

So they don’t change when you rotate the device.

You need to use some math to calculate the width and height the group should have to fill the screen.

“you need to use some math”

Care to elaborate on what kind perhaps? involving what properties?

If you have in config that your app is portrait, then on rotation you check if it’s landscape and then you swap width and height. Content sizes are always regarding start up setrings - are not dynamic.

As piotrz55 says, if the app starts in portrait, then display.contentWidth/Height are always in portrait.  Maybe you can just check system.rotation (see docs for system.*) and check for “portrait” vs “landscapeLeft”, etc. and then resize/rotate accordingly.

 @piotrz55 I understand you suggestion, but i’ve already swapped the two values around to understand behaviour. which prompted me to start this thread

For example:

[lua]

oneGroup.width = display.contentHeight

oneGroup.height = display.contentWidth

[/lua]

when switching between landscape and portrait modes the code above causes one of those things to happen:

  1. it doesn’t effect any sides, as if those calls were never made

  2. it seems to continually stretch the width and the height everytime you rotate, which perplexes me severely. Because those are asignment statements and not increment statements, I dont understand why the screen ‘blows up’ the display object

@jbp1, there isn’t a system.rotation, so I am assuming you meant to say system.orientation

I think now… that just swaping values is useless. You need to redraw everything, reposition it…

so, to understand what your saying. 

on orientation change:

  1. clear the screen

  2. detect current orientation

  3. call function that corresponds to current orientation 

So, i’ll need a function call that draws for a landscape screen, and a function that draws for a portrait?

I would go this way but not as drastic. Do not redraw everything, only things you need. You can reposition objects or reshape it if it’s enough. Remember that reshaped objects (eg vector rectangles) change theirs reference points if width or height is modified.