Skip to first unread message

Attila Cseh

unread,
Sep 24, 2014, 1:01:45 PM9/24/14
to
Hi!

Based on screen orientation I plan to resize image sprites in AI2.

Should these blocks work as seen below?

For me they don't.

What sould be behind the "if"?

Thank you!


Greg Jensen

unread,
Sep 24, 2014, 1:32:52 PM9/24/14
to
Please try inserting the image again. The paste resulted in the image file's ascii code. Not sure what you did there.I edited out the code.

Attila Cseh

unread,
Sep 25, 2014, 2:34:38 PM9/25/14
to mitappinv...@googlegroups.com
Hi Greg!
Instead of pasting I try now in attachment.
What I'd like the app to do is, based on the screen orientation, to resize the image sprite according to screen resolution.
Would this be the right way?
 :)
pic_size.jpg

M. Hossein Amerkashi

unread,
Sep 25, 2014, 2:48:41 PM9/25/14
to mitappinv...@googlegroups.com
You could also check and see if the Screen Width > Screen Height. If so, then landscape else portrait.

-Hossein.

Greg Jensen

unread,
Sep 25, 2014, 2:53:02 PM9/25/14
to mitappinv...@googlegroups.com
Ah.. The logic looks good but the screen orientation is: 
"The requested screen orientation. Commonly used values are unspecified (-1), landscape (0), portrait (1), sensor (4), and user (2). See the Android developer documentation for ActivityInfo.Screen_Orientation for the complete list of possible settings."
Also.. hover the cursor over a component setting to see the documentation (the text above) for it

Taifun

unread,
Sep 25, 2014, 3:00:32 PM9/25/14
to mitappinv...@googlegroups.com
if screen.width > screen.height
then do something (landscape)
else do something else (potrait)
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Attila Cseh

unread,
Sep 25, 2014, 3:13:38 PM9/25/14
to mitappinv...@googlegroups.com
Hi Hossein!
Your approach works, thank you!
However now I'm facing problem with the resized picture quality az aspect ratio.
The image sprite should be 100x100.
When in portrait it is resized to 100x101.
In landscape it is 111x84.
As far as I know well AI2 has 320*480.

pic_size2.jpg
2014-09-25-21-10-05-801.png
2014-09-25-21-10-10-835.png

Attila Cseh

unread,
Sep 25, 2014, 3:17:48 PM9/25/14
to mitappinv...@googlegroups.com
Should I try the numeric values in the "if"?
What Taifun and Hossein wrote it works.
But I'm really wondering what is wrong with my "way"?

Attila Cseh

unread,
Sep 25, 2014, 3:22:32 PM9/25/14
to mitappinv...@googlegroups.com
Well no luck with the numeric values in the "if"! :(

pic_size3.jpg

Attila Cseh

unread,
Sep 25, 2014, 3:34:16 PM9/25/14
to mitappinv...@googlegroups.com
Well, it is interesting!
Just look at these blocks!
The screen1.ScreenOrientation block gives me back only that value, what I set in Designer view.
Unspecified
Sensor
User
I need to work on it to find out.
pic_size4.jpg
2014-09-25-21-26-10-849.png

M. Hossein Amerkashi

unread,
Sep 25, 2014, 3:41:20 PM9/25/14
to mitappinv...@googlegroups.com
This seems to be a bug. We'll follow-up. Thanks for reporting.

-Hossein.

Greg Jensen

unread,
Sep 25, 2014, 3:46:41 PM9/25/14
to mitappinv...@googlegroups.com
hmm... seems the documentation is not correct.
Try 'unspecified' in the Designer and see what orientation changed reports.

Also, If the image is 100X100 why are you adjusting it for screen orientation change?  If you want to force it to a specific % of screen width and screen height and not maintain the image's aspect ratio then just do that.

Attila Cseh

unread,
Sep 25, 2014, 3:53:47 PM9/25/14
to mitappinv...@googlegroups.com
My idea was to have the image sprite fills in the same area proportionally on big screens aswell.
What I mean is if I leave it 100x100, on a small phone it looks perfect, but on a HD or FullHD display it looks too small and my app leaves big empty space around on screen.

Attila Cseh

unread,
Sep 25, 2014, 3:57:43 PM9/25/14
to mitappinv...@googlegroups.com
(I tried unspecified too, but gave same result)

Greg Jensen

unread,
Sep 25, 2014, 4:15:30 PM9/25/14
to mitappinv...@googlegroups.com
Another way to address the problem is to have two or three copies of the image at different sizes.  Set the appropriate source image at Screen.Initialize or .ScreenOrientationChanged. In pic_size  check the width or height to determine the screen size in pixels.

If you need to calculate the aspect ratio of the sprite to match the screen (regardless of the image) then you accept the distortion and quality of the image associated with doing that.  Just set the image sprite height/width to a % of screen height/width whenever the orientation changes. You don't have to know which way it is just multiply what you get when it's changed by your % (eg imagesprite.width=screen1.width * .05).

BTW, you may want to use Canvas height and width rather than screen size. They'll only be the same as long as the canvas is set to fill parent and it's not in a layout. ;)

Attila Cseh

unread,
Sep 25, 2014, 4:18:56 PM9/25/14
to mitappinv...@googlegroups.com
Sounds "must try"!
I'll take time tomorrow.
Thank you Greg!
Attila

Attila Cseh

unread,
Oct 3, 2014, 1:50:25 PM10/3/14
to mitappinv...@googlegroups.com
Dear Greg, Hossein and Taifun,

Thank you all for the support!
I learned o lot from your comments.
We can close this topic now! :)

Attila

Greg Jensen

unread,
Oct 3, 2014, 5:33:45 PM10/3/14
to mitappinv...@googlegroups.com
You're very welcome
Reply all
Reply to author
Forward
0 new messages