Pixel Envision Ltd.
Mobile Game Development Studio
  • Home
  • About Us
  • Our Games
    • Hyper-Casual
    • Casual Games
      • Don’t Get Caught
      • Hordes of Enemies
      • noded
      • kubic
      • Whip Swing
      • Witches’ Brew
    • Kids Apps
      • Coloring Book
      • Cars & Trucks Puzzle
      • Train Puzzles for Kids
      • Animal Puzzle
      • Fairy Tale Puzzles for Kids
      • Find the Differences
  • Support
  • Privacy Policy
Select Page ...

Monthly: August, 2011

CoronaSDK Proper Orientation Rotation with Animation

August 3, 2011 CoronaSDK, Lua

This is a code I came up when learning Lua & CoronaSDK programming. Copy of the original code still available at Ansca code exchange.

It is mostly working as I wanted except a small bug. If you rotate the device while app is loading assets, there might be a small delay. I’m planning to work on an update for that as soon as our game is out…

rotationfix.lua

Lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--]]
 
-- SET YOUR ORIENTATIONS HERE
local mainOr = "portrait"
local altOr = "portraitUpsideDown"
 
-- MASTER CODE
local stage = display.getCurrentStage( )
stage:setReferencePoint(display.CenterReferencePoint)
 
isRotated = false
local rotatefilter --function reserve
local rotatestart --function reserve
local rotatecomplete --function reserve
local curOrientation = mainOr --inital launch always match mainOr
local rota = 0
local isrotating = false
local rd = 600
 
-- iPad rotates slower
if system.getInfo("model") == "iPad" then rd = 750 end
 
function rotatefilter( )
  if (system.orientation == mainOr or system.orientation == altOr ) then
    return system.orientation
  else
    if curOrientation then return curOrientation else return mainOr end
  end
end
 
function rotatestart( val, initial )
  if isrotating == false and curOrientation ~= val then
    if val == mainOr then
      rota = 180
      curOrientation = mainOr
    elseif val == altOr then
      rota = -180
      curOrientation = altOr
    end
    isrotating = true
    if initial and rd == 750 then
      transition.to( stage, { rotation=rota, time=0, delta=true, onComplete=rotatecomplete } )
    else
      transition.to( stage, { rotation=rota, time=rd, delta=true, transition=easing.inOutQuad, onComplete=rotatecomplete } )
    end
  end
end
 
function rotatecomplete( )
  isrotating = false
  if curOrientation == altOr then isRotated = true else isRotated = false end
  if curOrientation ~= rotatefilter() then rotatestart(rotatefilter()) end
end
 
--Check initial orientation and and rotate if needed
if ( system.orientation == altOr and isrotating == false) then rotatestart(altOr,true) end
 
local function onOrientationChange( event )
  local type = event.type
  if ( type == mainOr or type == altOr ) then rotatestart(type) end
end
 
Runtime:addEventListener( "orientation", onOrientationChange )

Welcome to Pixel Envision!

August 1, 2011 Blog

Finally after days of hard work on our site, we are ready to launch.

As our first game coming close to it’s debut, we will continue to enhance/expand our web site and post updates of our progress…

This web site will act as our central marketing & support portal for our upcoming applications as well as a place to share our knowledge with our fellow developers.

Our first post will be a useful cache warmer PHP code I came up with when working on this WordPress powered web site.

Please follow us on social media to receive latest news & updates.

Thank you for visiting us… :)

«12
  • Tags

    3ds Max Coming Soon CoronaSDK Featured Flash Lua MAXScript PHP Programming Reviews Tips & Tricks Unity 3D Windows Phone
  • Recent Comments

    • Yogesh Singh on ZIP (POSTAL) Code Validation Regex & PHP code for 12 Countries
    • Admin on Maxscript – Vray Cubemap Generator for Unity
    • charlie on Maxscript – Vray Cubemap Generator for Unity
    • Mastan on PHP Currency Converter
    • Rakesh Vishnoi on ZIP (POSTAL) Code Validation Regex & PHP code for 12 Countries
    • Find us on

      amazonandroidapplefacebooklinkedintwitterwindowsyoutube
    • Company Information

      Lytchett House, 13 Freeland Park, Wareham Road, Poole, Dorset, BH16 6FA

      Pixel Envision Limited is a company registered in England, company number: 09558675. Registered Office: Preston Park House, South Road, Brighton, East Sussex, BN1 6SB, United Kingdom

    • Privacy Policy
    Copyright © 2011-2021 Pixel Envision Ltd, all rights reserved.