Ok - feature was “almost” there - just had to convert shape property values from a string to a lua-table-list:
[lua]local onShapeProperty = function(property, atype, object)
if(type(object.shape)==“string”)then
local shapeT = split(object.shape,",")
if(#shapeT > 1)then
local shape = {}
for i,v in ipairs(shapeT)do table.insert(shape,tonumber(v)) end
object.shape = shape
end
end
end
Whoops, I always meant to add this functionality in. I have added the following code to lime-object.lua around line 444 just after the “elseif(self.shape) then” line:
if type(self.shape) == "string" then
local splitShape = splitString(self.shape, ",")
if #splitShape \> 1 then
local shape = {}
for i = 1, #splitShape, 1 do
shape[#shape + 1] = tonumber(splitShape[i])
end
body = display.newRect( self.map.world, self.x, self.y, self.width or 1, self.height or 1 )
self.shape = shape
end
end
I’ve also added a localised function to the top:
local splitString = utils.splitString
[import]uid: 5833 topic_id: 6863 reply_id: 23933[/import]
Currently the Tiles are only built from their sprite image whereas an Object can be built from a sprite image (if it is a Tile-Object), radius, points, its actual width/height and now a shape. It would be fairly trivial to copy over the code from Object:build() to Tile:build() to get these other options for Tiles if that was wanted? [import]uid: 5833 topic_id: 6863 reply_id: 23941[/import]
I will update the Tile:build() function to make it accept other options, *should* be simple enough [import]uid: 5833 topic_id: 6863 reply_id: 23947[/import]
OK, I have currently just updated the function to allow shapes to be specified, the other options would be trickier. For instance to create a body from points you would also need to specify which layer the point objects are on.
[code]
— Builds the physical representation of the Tile.
function Tile:build()
if(self.HasBody and self.sprite) then
local body = self.sprite
if(self.shape) then
if type(self.shape) == “string” then
local splitShape = splitString(self.shape, “,”)
if #splitShape > 1 then
local shape = {}
for i = 1, #splitShape, 1 do
shape[#shape + 1] = tonumber(splitShape[i])
end
self.shape = shape
end
end
end
– Now that tiles can be set at runtime it is important to make sure physics is loaded as it may not have been at load time
if not physics then
require(“physics”)
physics.start()
end
Although if you specify a “radius” property for your tile it should work by default as it just gets past to the physics.addBody function. [import]uid: 5833 topic_id: 6863 reply_id: 23957[/import]