The Collectible Items example gave me errors on the console:"…attempt to call method ‘removeSelf’ (a nil value)" which was referring to the local onTransitionEnd handler inside of the onCollision event handler.
In the process, I learnt that the onComplete handler does have an event-kind of parameter, which is actually equal to the object itself…
The documentation about transition.to at “http://developer.anscamobile.com/reference/index/transitionto” is hopelessly incomplete (like much of Corona’s doc… ). Only when I introspected the parameter I found out it was the object itself. Guess Graham figured that out also somehow…
Anyway, what confused Lua was the fact that the local onTransitionEnd handler was defined with the same parameter name (event) as the outer-function onCollision event handler - theoretically I believe that the local inner “event” parameter should have precedence over the outer scoped one, but Lua doesn’t seem to agree… Changing the onTransitionEnd parameter to event2 makes all work correctly.
The attached snippet of the onCollision handler corrects that little snafu.
It also changes the color of the text to something that shows up on my screen
Enjoy, Frank.
[lua]local function onCollision(self, event )
if ( event.phase == “began” ) then
if event.other.IsGround then
player.canJump = true
if player.state == STATE_JUMPING then
player.state = STATE_IDLE
player:prepare(“anim” … player.state)
player:play()
end
elseif event.other.IsPickup then
local item = event.other
local onTransitionEnd = function(event2)
event2:removeSelf()
end
– Fade out the item
transition.to(item, {time = 500, alpha = 0, onComplete=onTransitionEnd})
local text = nil
if item.pickupType == “score” then
text = display.newText( item.scoreValue … " Points!", 0, 0, “Helvetica”, 50 )
elseif item.pickupType == “health” then
text = display.newText( item.healthValue … " Extra Health!", 0, 0, “Helvetica”, 50 )
end
if text then
text:setTextColor(100, 100, 100)
text.x = display.contentCenterX
text.y = text.height / 2
transition.to(text, {time = 1000, alpha = 0, onComplete=onTransitionEnd})
end
end
elseif ( event.phase == “ended” ) then
if event.other.IsGround then
player.canJump = false
end
end
end[/lua] [import]uid: 8093 topic_id: 7341 reply_id: 307341[/import]