Skip to main content

Posts

Showing posts from March, 2010

[Corona] Landscape 比照 Flash 座標系的設定

目前看起來,由 action script 轉到 Object-C 的難度遠遠超過 Corona SDK for iPhone 用的 Lua , 想當然爾選擇 Corona SDK 來寫 iPhone app 對 ASer 來說是第一首選。趁著難得的空檔,花了些時間研究一下,沒想到一開始就被它的座標系搞到眼花...只要 landscape 外加 rotation 的時候整個座標系就會很難控制...(因為跟它不熟啦...XD ) 為了堅持在 Corona 中使用 Flash 的座標系(左上到右下),當 landscape 時修改當場景的 group 屬性就可以擔保裡面所有物件都不需要再移動... main.lua : -- -- landscape 使用熟悉的 Flash 座標系 in corona -- local bg = display.newRect( 0, 0, 320, 480 ) bg:setFillColor(100,120,120) local rect = display.newRect( 0, 0, 50, 50 ) rect:setFillColor(255,255,255) --直接指定 rect 在場景中的 x, y rect.x = 100 rect.y = 100 --利用 group 實現場景 local group = display.newGroup() group.rotation = 90 group.yReference = 160 group.xReference = 160 --將 rect 加到場景中 group:insert( rect ) local function onOrientationChange( event ) local tp = event.type if (tp == "landscapeLeft") then group.rotation = 90 group.yReference = 160 group.xReference = 160 elseif ( tp == "landscapeRight" ) then group.rotation = -90 group.yReference = 240 group.xR