Object Table - Objects are invisible

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]

Obviously I can’t test with that code, however I was wondering whether or not you are inserting everything into localGroup, or just some images, like your platforms - but not your background?

Is it possible that the images aren’t invisible but are simply behind your background. (You can find this out quickly by briefly setting your background to a low alpha.)

If so, consider using toFront() on your platforms.

Otherwise, for trouble shooting purposes, could you use a few print statements to ensure things are being set as you’ve intended?

Peach :slight_smile: [import]uid: 52491 topic_id: 15438 reply_id: 57089[/import]

Looks like my background was being thrown infront of it, due to the order of my statements.

Thanks [import]uid: 61422 topic_id: 15438 reply_id: 57090[/import]

No worries; glad I could help get it sorted :slight_smile: [import]uid: 52491 topic_id: 15438 reply_id: 57231[/import]