Kilopop - that isn’t a graphics 2.0 daily build, just a normal one.
Any graphics 2.0 daily build has the subversion number greater than 2000 (yours is 1244).
Go here to grab it: https://developer.coronalabs.com/downloads/graphics-daily-builds
I’m about to do my final github update for the day. It has some useful changes.
Get the latest working project here: https://github.com/Rakoonic/Vector-Importer
Here, for example, is the code used to import and create the objects:
[lua]--------------------------------------------------------------
– SETUP -----------------------------------------------------
local __G = require( “libs.globals” )
local vectorImporter = require( “libs.vectorimporter” )
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– STORYBOARD ------------------------------------------------
function scene:createScene( event )
local sceneGroup = self.view
– Create the ice cream polygon object
local icecream = vectorImporter:new{
file = “assets/icecream.json”,
parent = sceneGroup,
bezierSubdivisions = 5,
strokeWidthScalar = 2,
makeOpenShapesLines = false,
autoCenter = true,
x = __G.screenWidth * 0.3,
y = __G.screenHeight / 2,
}
– Create the face polygon object
local face = vectorImporter:new{
file = “assets/face.json”,
parent = sceneGroup,
bezierSubdivisions = 15,
autoCenter = true,
x = __G.screenWidth * 0.7,
y = __G.screenHeight / 2,
scale = 0.8,
rotation = -10,
}
end
– STORYBOARD LISTENERS --------------------------------------
scene:addEventListener( “createScene”, scene )
– RETURN STORYBOARD OBJECT ----------------------------------
return scene[/lua]So, important tweaks are the changing of the library name (big wow, right?), and some additional properties. Here are all the properties you can pass when creating the object.
-
file - Must be the full path from the root of your project.
-
directory - Must either be a standard Corona directory identifier (system.DocumentsDirectory etc), or a string. The string can be either “docs” or “documents” for system.DocumentsDirectory, or anything else for system.ResourceDirectory (although probably best to stick with “resource” for clarity). Defaults to the resource directory if not supplied.
-
parent - A parent group that this object will be placed into if passed.
-
bezierSubdivisions - How much to subdivide each bezier curve. Note that this produces ‘bezierSubdivisions + 1’ line segments (making 0 a valid option for no subdivision). Defaults to 5 if not supplied.
-
strokeWidthscalar - How much to scale up stroke width values in the file. Defaults to 1 (no change) if not supplied.
-
makeOpenShapesLines - Determines how to handle open filled shapes. Probably needs additional work
Defaults to true.
-
autoCenter - creates the objects at the origin - IE regardless of the actual values of the imported files, it moves all these so the object is centered at 0,0 within the object group. An example is if you look at the face JSON file - the face as a whole is located somewhere around 7000,-7000. If you placed the imported object at 0,0, you aren’t going to see it because it is waaaay off screen. autoCenter can help you position things correctly. Note that this also affects where the object will rotate and scale from. Defaults to false if not supplied.
-
x - The x location you want the object to be drawn at. Defaults to 0 if not supplied.
-
y - The y location you want the object to be drawn at. Defaults to 0 if not supplied.
-
rotation - The rotation of the object. Defaults to 0 if not supplied.
-
scale - The scale of the object. Defaults to 1 (no change) if not supplied.
The object / display group returned also contains a few new functions:
- obj:getCenter() – Returns the overall center of all the vector objects drawn within the object. Note if you use autoCenter, then this will be 0, 0.
- obj:getSize() – Returns the overall width and height of all the vector objects drawn within the object.
These two functions are hooks into the object. bounds property which is the bounding rectangle of the entire file imported.
If you wish to access sub-objects, then these are merely the children of the object, so you could access them like this:
[lua]local firstSubObject = obj[1][/lua]etc.
Each sub-object has an additional property called . bounds , which is the bounding rectangle of just that sub-object (similar to the object. bounds ).
The final big change is that the object model now uses a display group as the container for the object, so when you use vectorImporter:new() it returns a display group.
So you can later then just manipulate your vector image in one go by changing the X, Y, scale etc values of this object, and in fact can also chuck it into transitions and whatever (although changing the alpha probably isn’t going to have the effect you want if it has too many overlapping layers).
Final note (for now):
If you want to apply an effect to your vector object, you are going to have to chuck it into a snapshot. This is actually now quite simple, as you can find out the bounds / sizes easily. So something might look like this:
[lua]local border = 10
local width, height = obj:getSize()
local snapshot = display.newSnapshot( width + border * 2, height + border * 2 )
snapshot.group:insert( obj )[/lua]
Then you could happily go about adding filters to the snapshot.
Why the border value? Because if you want to add a filter that extends beyond the border of the actual image (say a gaussian blur), then you need this border for the effect to bleed into.