orientationChanged image angle

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
goncalo
Posts: 6
Joined: Tue May 31, 2011 11:53 am

orientationChanged image angle

Post by goncalo » Fri Aug 10, 2012 2:37 pm

Hello, i have a problem with the orientation of iPhone.

I want that some images change the angle when a rotate the iphone, but with this code i don’t have the best result every time.
Some times the images change to the orientation of the iPhone, but some times they don’t rotate at all.

i send a file with the example, because i want the background image to stay on the same spot, and only the images of the buttons to change angle.

Does some else had this problem?

Code: Select all

on orientationChanged
   put mobileDeviceOrientation () into theOrientation
   if theOrientation = "portrait" then
      set the angle of image "butao_home_low.png" of card "game_stuff" to 90
   else if theOrientation = "portrait upside down" then
      set the angle of image "butao_home_low.png" of card "game_stuff" to 270
   else if theOrientation = "landscape left" then
      set the angle of image "butao_home_low.png" of card "game_stuff" to 180
   else if theOrientation = "landscape right" then
      set the angle of image "butao_home_low.png" of card "game_stuff" to 0
   end if
end orientationChanged
Thanks in advance.
Gonçalo

MacOSX 10.6
iMac 27" Intel Core 2 Duo 3,06 GHz

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: orientationChanged image angle

Post by Mark » Sat Aug 11, 2012 2:38 am

Hi,

Can you check whether the orientationChanged message isn't triggered or the images don't rotate properly? If the message isn't triggered, you could try using a recursive handler, which checks the mobiledeviceOrientation function.

Code: Select all

on openCard
  send "check" to me in 0 secs
  pass openCard
end opencard

local lPrevOrientation
on check
   put mobileDeviceOrientation () into theOrientation
   if lPrevOrientation <> theOrientation and there is an image "butao_home_low.png" of this cd then
     // orientation changed
     if theOrientation = "portrait" then
        set the angle of image "butao_home_low.png" of card "game_stuff" to 90
     else if theOrientation = "portrait upside down" then
        set the angle of image "butao_home_low.png" of card "game_stuff" to 270
     else if theOrientation = "landscape left" then
        set the angle of image "butao_home_low.png" of card "game_stuff" to 180
     else if theOrientation = "landscape right" then
        set the angle of image "butao_home_low.png" of card "game_stuff" to 0
     end if
     put theOrientation into lPrevOrientation
   end if
   if there is an image "butao_home_low.png" of this cd then send "check" to me in 333 millisecs
end check
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply