Author Topic: Universal SD / HD Switching for iOS (iPad / iPhone) - Refresh problem  (Read 30847 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Well, then I am at a loss. Assuming you set the replacement atlas correctly, it should get used when the button is created. Methinks you'll need to debug that a bit more.

iandunlop_oefun

  • Guest
Well, then I am at a loss. Assuming you set the replacement atlas correctly, it should get used when the button is created. Methinks you'll need to debug that a bit more.

Ok, I think I'm getting closer to the cause of the issue. The button in question appears at the expected size when I hover over it. Looking at the SDK source I couldn't find any direct way that the atlas pixelSize property is used, other than the UISprite.MakePixelPerfect() method. Looking at UIImageButton.OnHover(bool isOver) I can see now why the button "pops" to it's expected size - because that directly calls MakePixelPerfect().

So, unless MakePixelPerfect is called the UISprite won't reflect the atlases pixelSize value. On initialization MakePixelPerfect is not called. This is why on first presentation of the view the button does not reflect the pixelSize multiplier.

Any ideas?

Is there some way to force MakePixelPerfect?

iandunlop_oefun

  • Guest
For UIImageButton the fix is fairly straightforward - just call MakePixelPerfect() inside the Start() method. However, I ran into another issue where pixelSize isn't accounted for - the colliders on buttons don't update. So you're left with a small rect that doesn't match the visual size.

Given these issues I've abandoned trying to use the atlas pixelSize. Perhaps there is something I'm doing wrong here but I can't figure it out.

What I'm now doing is switching the manual height setting on the UIRoot and leaving the pixel size on *all* atlases set to 1.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You're supposed to be working with a manual height to begin with. Pixel size only works with a manually set height. You basically choose the target height you'll be designing your UI in, then stick with it, and if the resolution is high enough, swap to an HD atlas.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Oh and btw you can call MakePixelPerfect on everything by broadcasting it:

  1. NGUITools.Broadcast("MakePixelPerfect");

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Another note... colliders on buttons shouldn't update. There is no reason for them to update. As far as they're concerned, the UI size hasn't changed because the scale of UIRoot shouldn't be changing (this is where the "automatic" being turned off comes in).

They will only scale if you've turned the automatic back on for some reason, which doesn't mix with the pixelSize setting.

iandunlop_oefun

  • Guest
You're supposed to be working with a manual height to begin with. Pixel size only works with a manually set height. You basically choose the target height you'll be designing your UI in, then stick with it, and if the resolution is high enough, swap to an HD atlas.

I am - see my original post. My point was that I'm now dynamically switching the manual height based on the device / destination screen size.

iandunlop_oefun

  • Guest
Oh and btw you can call MakePixelPerfect on everything by broadcasting it:

  1. NGUITools.Broadcast("MakePixelPerfect");

That would solve one particular issue but doesn't address the collider problem.

iandunlop_oefun

  • Guest
Another note... colliders on buttons shouldn't update. There is no reason for them to update. As far as they're concerned, the UI size hasn't changed because the scale of UIRoot shouldn't be changing (this is where the "automatic" being turned off comes in).

They will only scale if you've turned the automatic back on for some reason, which doesn't mix with the pixelSize setting.

Manual height was being set (automatic was not enabled on the UIRoot).

Atlas.pixelSize is not being handled correctly on UIImageButton's. Hence the "pop" I was getting when I hovered over or touched the button. In your code you only use pixelSize in the MakePixelPerfect method.

The collider's do need to increase in size because the size of the button on screen is larger. In my test case I was switching to an iPhone atlas with atlas pixelSize set to 2. However, the collider was still set for the original iPad version of the button.

My solution was to set *all* my atlases to 1 and change the manual height dynamically based on device screen size.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
The collider on the screen shouldn't change. You may have a bigger screen size, but since you are not using it (you're using the manual setting on the root), it is completely irrelevant. The button should stay the same size proportionally. Does your button's size change? If your button is 200x30, it should still be 200x30 after the atlas swap. The whole point of the atlas swapping is to handle doubling (or halving) of resolutions, iOS style.

loopyllama

  • Guest
My curiosity has to the better of me. You mention you use the same art for both atlases. Is your art designed to be pixel perfect for the iPhone 4 or the iPad 3? Which one? Then I cannot help but ask why you are not using different art when you are not keeping pixels 1:1 (which would be setting the UIRoot to automatic). Are you SURE you shouldn't be disabling your atlas switching code, using your single iPad 3 atlas set to pixel size of 1, and setting the UIRoot to automatic? It really sounds like that is what you want. That would make a button that is 100 pixels tall stay 100 pixels tall on any device. For instance in the wacky case of a button that is 500 pixels tall, it would be almost 1/3 of the screen tall on the ipad3 and over half the screen tall on the iPhone 4. It sounds like you want to want to take the pixel perfect button on the iPhone 4 that would be over half the screen and make it twice as big. But instead you are trying to make pixel perfect art two times bigger when switching from the iPad 3 to iPhone 4? I must have misread something. Please set the record straight to make helping easier.

iandunlop_oefun

  • Guest
The collider on the screen shouldn't change. You may have a bigger screen size, but since you are not using it (you're using the manual setting on the root), it is completely irrelevant. The button should stay the same size proportionally. Does your button's size change? If your button is 200x30, it should still be 200x30 after the atlas swap. The whole point of the atlas swapping is to handle doubling (or halving) of resolutions, iOS style.

I have a smaller screen size. I'm going from iPad retina to iPhone retina. The pixelSize on the iPad atlas was 1 and the pixelSize on the iPhone atlas was 2. The button grows in size when running at 960x640 (if I touch the button or hover over it). In all cases manual height on the UIRoot was set to 1536.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
So your problem is that you're mixing two incompatible screen sizes -- iPhone and iPad. iPhone's resolution isn't simply half of iPad's. iPhone is 960x640, while iPad3 is 2048x1536. 1536/2=768, not 640.

Edit: Edited because I should be using height, not width. <_<
« Last Edit: May 15, 2012, 11:46:01 PM by ArenMook »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Your pixel size for your iPhone atlas should be 1536/640=2.4
« Last Edit: May 15, 2012, 11:44:55 PM by ArenMook »

iandunlop_oefun

  • Guest
My curiosity has to the better of me. You mention you use the same art for both atlases. Is your art designed to be pixel perfect for the iPhone 4 or the iPad 3? Which one? Then I cannot help but ask why you are not using different art when you are not keeping pixels 1:1 (which would be setting the UIRoot to automatic). Are you SURE you shouldn't be disabling your atlas switching code, using your single iPad 3 atlas set to pixel size of 1, and setting the UIRoot to automatic? It really sounds like that is what you want. That would make a button that is 100 pixels tall stay 100 pixels tall on any device. For instance in the wacky case of a button that is 500 pixels tall, it would be almost 1/3 of the screen tall on the ipad3 and over half the screen tall on the iPhone 4. It sounds like you want to want to take the pixel perfect button on the iPhone 4 that would be over half the screen and make it twice as big. But instead you are trying to make pixel perfect art two times bigger when switching from the iPad 3 to iPhone 4? I must have misread something. Please set the record straight to make helping easier.

Art is designed for iPad retina (iPad 3). For iPhone retina I want the buttons to be larger on screen (because the physical display is smaller).

These are approx. sizes:
- If I have an 80x80 iPad retina button, I want that to be 80x80 on iPhone retina.
- However, on iPhone (non-retina) I need that button to be 40x40

I will investigate UIRoot in automatic mode - perhaps I should be using that?