Star collisions need to be made and removed from the stage so that points can be accumulated for the player.
Create a function for the star collision called
onStarCollision()
and have aself
andevent
parameter:local onStarCollision = function( self, event )
Add the
if
statements that remove thestars
children from the game screen when a collision is made. Increment the score by 500 for each star removed from the screen. Close the function withend
:if event.phase == "began" and self.isHit == false then self.isHit = true print( "star destroyed!") self.isVisible = false stars.numChildren = stars.numChildren - 1 if stars.numChildren < 0 then stars.numChildren = 0 end self.parent:remove( self ) self = nil local newScore = gameScore + 500 setScore( newScore ) end end