Hi, I’m using the code from the blog post (how to spawn objects).
The objects are acting as they should, and collision events are firing and responding normally. However, I can’t see the object itself. I’ve explicitly set isVisible=true and alpha=1, it’s still transparent though.
I was originally just building the platform object myself, not inside a table or function, and this worked as expected. This leads me to believe it’s an issue with the object table.
Code is below:
-- Spawn a platform
function spawnPlatform(params)
local object = display.newImage( "platform.png" )
-- Set the objects table to a table passed in by parameters
object.objTable = params.objTable
-- Automatically set the table index to be inserted into the next available table index
object.index = #object.objTable + 1
-- Give the object a custom name
object.myName = "Platform : " .. object.index
-- Make is visible
object.alpha = 1
object.isVisible = true
-- Position
object.x = params.x
object.y = params.y
-- Set as physics object
physics.addBody( object, "static", { friction=0.3, isSensor=true } )
-- The objects group
object.group = params.group or localGroup
-- If the function call has a parameter named group then insert it into the specified group
object.group:insert(object)
-- Insert the object into the table at the specified index
object.objTable[object.index] = object
return object
end
platforms = spawnPlatform(
{
objTable = platformsTable,
x = 120,
y = 350,
group = localGroup
}
)
local function onPlatformCollision( event )
vx, vy = man:getLinearVelocity()
if vy \> 0 then
man:setLinearVelocity( 0, 0 )
man:applyLinearImpulse(0, -0.6, man.x, man.y)
end
end
On collision my character jumps on the platform, but it’s simply not visible. I have also tried explicitly setting the height (which I have removed from the code above), still no dice though.
Any help is hugely appreciated.
Thanks [import]uid: 61422 topic_id: 15438 reply_id: 315438[/import]
[import]uid: 52491 topic_id: 15438 reply_id: 57089[/import]