Skip to main content
Inspiring
April 30, 2012
Question

bitmap scrollRect rounding values when scaling on iPad

  • April 30, 2012
  • 1 reply
  • 2052 views

I have a project that was designed for iphone. I have been told to make it work "full screen" on the ipad.

Most of the backgrounds and art resources have been changed to be 960x720 so that when it scales up on the ipad, it will scale evenly to 1024x768. I do not have any say in this, I have to work with that.

The stage is still set to 960x640 with the scale mode being "show all"

The stage quality is set to low because of memory concerns. Setting it to anything causes crashes on older devices.

Now, for the most part, this works just fine. However, I am having a problem with some of the animated sprites.

So the "parent" container sprite is scaled up 1.0666666666666666666666666666667  (1024/960)

In my library, I have a spritesheet which is 2730x116 consisting of 21 frames.

On the screen, I create a sprite object, and then put a bitmap containing my sprite sheet in that sprite.

I then give the bitmap a scrollRect to only show the frame that I want to show. (these values are stored in an array that was created when I created the sheet)

Now, when scaling is 1:1 - everything is positioned and works just fine.

However, when I scale up to 1024x768, the scrollRect stops working as it's supposed.

What I have determined is that when it sets the scrollRect on the bitmap, it's not taking the stage scaling into account. I have verified this by invert scaling the bitmap by 960/1024 (bringing it back on an on-screen scale ratio of 1:1) - but now it's the wrong size - but the scroll rect is working. If it set the bitmaps scalex and y back to 1, the scrollRects x/y/width/height starts showing the the incorrect bitmap data, even though the numbers in the trace output are correct.

I figured if I could set the scrollRect values to compensate for the scaling, then it would show the correct region, however, if I try to set the scrollRect values to a floating number, it is automatically rounding them

For example.

Let's say I want to show in my sprite sheet located at (x=390, y=0, w=130, h=116) which is frame 4 in my sheet.

Screen = 10204x768

Stage: x=960,y=640

Stagequality = low

StageScaleMode = show all

MainSpriteObject.scalex and y = 1.0666666666666666666666666666667 = (1024/960)

Create new sprite.

create new bitmap.

Bitmapdata in bitmap to sprite sheet (w=2730,h=116)

Bitmap.scrollRect = new Rectangle(390,0,130,116)

the position is wrong (and when I animate through the frames by changing the scrollrect x value by 130 pixels per fame) the image "jumps around"

if I try doing THIS:

bitmap.scrollRect = new Rectangle(390.06666667, 0, 130.0666667, 116.066667);  (numbers are not perfect, but they illistrate my problem);

trace(bitmap.scrollRect) outputs: (390,0,130,116)    - it rounded the decimals!

I've tried scaling the bitmaps parent sprite up and down, but to no effect.

I'm very quickly running out of ideas and could use any help on this.

How can I get the scrollRect on the bitmaps to display properly when their parent containers are scaled, or how can I get the scrollRect to accept float values?

This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
April 30, 2012

Your life would be much simpler if you kept the 960x720 stage and left the scale mode with the default values, then your movie will scale up to 1024x768 without you needing to do any code changes at all. Also, your sprite sheet size exceeds the 2048 limit of iPad. Can you make it be two rows of images, and 1365x232?

I'm not sure that scrollrect takes advantage of the GPU's memory. Can you try using AIR 3.2, and Direct renderMode? If that doesn't perform well you may need to investigate Starling, and have that handle the spritesheet correctly.

Inspiring
April 30, 2012

I am not manually changing the stage size.

in my fla I set the stage to 960x720.

If I do not set the stage.scalemode = showall then the screen doesn't fill, I am left with black area on the bottom and right.

I was unaware of any 2048 limit for the ipad. I will look into that, but considering it's happening with sheets that DO fit into that limit, I am positive it's not that.

I am using air3.3b2 right now... as "direct renderMode", I will give it a try and see what happens.

I am planning on learning and using starling for our next project, but consiering that the current one is so close to finish, I don't know if it owuld be worth the time needed to implement.

Colin Holgate
Inspiring
April 30, 2012

>"If I do not set the stage.scalemode = showall then the screen doesn't fill, I am left with black area on the bottom and right."

That is happening because you have set the stage align to top left. Don't do that either. Don't do any align or any scale mode, then the 960x720 will fill the 1024x768 screen correctly.