可以說是自上次widget 1.0 升級成 2.0之後 又一個重大改變
對開發者來說 最大困擾是-原本的CODE怎麼BUILD不過了!?
原因是在2076版使用了Graphics 2.0,在原本的CODE上增加了些彈性和強化
有三個需要知道如何修正程式碼地方要了解
在修改之前,Corona 也提供了一個方法讓既有開發者能"無痛"的移殖至Graphics 2.0
在config.lua 設定檔中加上 graphicsCompatibility = 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application = | |
{ | |
content = | |
{ | |
graphicsCompatibility = 1, -- 加上這段 | |
width = 320, | |
height = 320 * display.pixelHeight/display.pixelWidth, | |
scale = "letterbox", | |
fps = 60, | |
imageSuffix = { | |
["@2x"] = 2, | |
} | |
}, | |
} |
所以-為了能夠獲得更好的相容性及更多的彈性
我們來了解需要修改的部份有哪些
- display.setReferencePoint => Anchor Point
- color values 0~255 => 0~1
- text color : setTextColor => setFillColor
display.setReferencePoint => Anchor Point
在程式撰寫時,為了不讓元件走位,通常都會設置ReferencePoint,讓其固定以某一個方位為座標對照點
現在我們必須使用錨點來指定座標對照點,優點是再也不受邊角的限制,不一定要將對照點設在正中央或四個角
舊用法
object:setReferencePoint(display.CenterReferencePoint)
新用法
object.anchorX,object.anchorY = 0.5,0.5
由對照圖表可以看出原來的
referencePoint VS anchor Point
display.TopLeftReferencePoint => 0,0
display.TopCenterReferencePoint => 0.5,0
display.TopRightReferencePoint => 1,0
display.CenterLeftReferencePoint => 0,0.5
display.CenterReferencePoint => 0.5,0.5
display.CenterRightReferencePoint => 1,0.5
display.BottomLeftReferencePoint => 0,1
display.BottomCenterReferencePoint=> 0.5,1
display.BottomRightReferencePoint => 1,1
而且 不只如此,此錨點能作用在像rotation旋轉的動作上,舉例來說要做一個時鐘,現在只要將時針,分針的圖放上螢幕,然後將anchor Point(錨點)設在其轉軸點(如0.2,0.5),接著按每秒轉動的角度做旋轉,就能夠使用更簡潔的程式碼完成。
color values 0~255 => 0~1
顏色設定的使用方法從0~255的值變成0~1實際用法依然是使用0~255 只是現在要除上一個255的基底
舊用法
obj:setFillColor(255,200,200,255)
新用法
obj:setFillColor(255/255,200/255,200/255,255/255)
textColor : setTextColor => setFillColor
同時將設定字體顏色的用法調整和設定Color的方法一致
並且套用最新設置顏色的值 0~1
舊用法
textObj:setTextColor(255,200,200,255)
新用法
textObj:setFillColor(255/255,200/255,200/255,255/255)
雖然這次更動幾乎讓小島的程式都要回去再看過,但看在加強了不少東西的份上,就勉勉強強欣然接受了!
textObj:setTextColor(255,200,200,255)
新用法
textObj:setFillColor(255/255,200/255,200/255,255/255)
雖然這次更動幾乎讓小島的程式都要回去再看過,但看在加強了不少東西的份上,就勉勉強強欣然接受了!
沒有留言:
張貼留言