This guide explains the changes required to modify existing Graphics 1.0 code to handle some behavioral changes introduced in Graphics 2.0. By migrating your projects, you'll be able to take advantage of all the new graphics features which are not actively supported in Graphics 1.0 Compatibility Mode.
Guides for the new Graphics 2.0 features are available in Corona University.
The following are behavioral changes to Graphics 2.0 APIs:
In Graphics 1.0, display object constructors had a top/left parameter. These have been reinterpreted as x and y values that specify the object's center point. The original behavior of interpreting the x and y parameter as top/left is available if using V1 Compatibility Mode. You can see the difference by comparing the
The following methods and properties have been removed:
Note that groups do not have anchor points. All operations are based around the group's fixed origin point.
For properties like object:setFillColor() and object:setStrokeColor(), RGBA color settings range between
1.0, not between
255. In addition, APIs that were available in Graphics 1.0 will adopt the new range by default, unless you enable V1 Compatibility Mode.
Also note that
object:setTextColor() has been deprecated. You should use object:setFillColor() on text objects instead.
This section aims to ease the migration of projects containing widgets.
In Graphics 1.0, all widgets were top-left aligned, except for newPickerWheel().
In Graphics 2.0, all widgets are center aligned for consistency. The default anchoring for all widgets is
0.5 for both the x and y coordinates.
The following changes relate to widget.newTableView():
In Graphics 2.0, the x and y properties of the table view refer to the center of the widget. This is a change from Graphics 1.0 in which the x and y properties were aligned to the top left.
In Graphics 2.0, the x and y position of the rows — when inserting objects into a row via the
onRowRender method — will refer to the center of the row.
The following example shows how your Graphics 1.0 code might look, followed by what it should look like in Graphics 2.0:
-- Graphics 1.0 local function onRowRender( event ) local phase = event.phase local row = event.row -- We cache the row contentWidth and contentHeight because the row bounds can change as we add children local rowHeight = row.contentHeight local rowWidth = row.contentWidth local rowTitle = display.newText( row, "Row " .. row.index, 0, 0, nil, 14 ) -- Left-align the label rowTitle.x = row.x - ( rowWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 ) rowTitle.y = rowHeight * 0.5 rowTitle:setTextColor( 0 ) end -- Graphics 2.0 (even in V1 Compatibility Mode) local function onRowRender( event ) local phase = event.phase local row = event.row -- We cache the row contentWidth and contentHeight because the row bounds can change as we add children local rowHeight = row.contentHeight local rowWidth = row.contentWidth local rowTitle = display.newText( row, "Row " .. row.index, 0, 0, nil, 14 ) -- Left-align the label rowTitle.x = 0 rowTitle.anchorX = 0 rowTitle.y = rowHeight * 0.5 rowTitle:setFillColor( 0 ) end
The following libraries and APIs have been removed in Graphics 2.0 and are not available, even in V1 Compatibility Mode:
require()this legacy sprite module.