2 unanswered questions from other boards

  1. Say I have a ball, when it collides with a balloon I want to score points, when it collides with a special ballon I want the balloon to grow in size for a certain amount of time…

Problem is I can only make the ball act in a certain way when it collides with anything… How do I make 2 separate events depending on what object the ball has collided with?

  1. How do I make my app compatible with for example the iPhone 4? When I simulate my app in the 3GS simulator everything looks fine but when I simulate on the iPhone 4 for some reason it’s scaled down to an almost 100x200 small screen?
    Thanks in advance, [import]uid: 14018 topic_id: 5378 reply_id: 305378[/import]

Problem is I can only make the ball act in a certain way when it collides with anything

Post your code and maybe we can tell you how to modify it. We have no idea what you’re doing. [import]uid: 12108 topic_id: 5378 reply_id: 17947[/import]

For answer number 2 read this: http://developer.anscamobile.com/content/configuring-projects

You need a config.lua file:

[lua]application =
{
content =
{
width = 320,
height = 480,
scale = “letterbox”
},
}[/lua] [import]uid: 11393 topic_id: 5378 reply_id: 17954[/import]

 -- Kollision  
 local function onCollisionEnemy(self, event)  
 if (event.phase == "began") then  
  
 self:removeSelf()   
 return true  
  
 end  
 end  
 enemy.collision = onCollisionEnemy  
 enemy:addEventListener("collision", enemy)  

This is what I’m using right now which makes the enemy disappear when it collides with everything. I don’t know how to modify it so when it collides with ‘ball’, it prints “Hello” for example instead of disappearing… [import]uid: 14018 topic_id: 5378 reply_id: 17955[/import]

IMHO and certainly in the Object Oriented world (ok, we’re strictly not in the with lua), If you are structuring your code correctly, you should have a function to create the balloons. This function could accept a number of parameters, some of which could be used to differentiate the behaviour of the balloon.

Essentially, the display object for the balloon can have a variable to determine its behaviour, this variable can be checked in the collision listener to determine what happens when it hits another object. A standard method to determine what type of object has been collided with is to simply assign a variable as a name.

For example, I use the variable ‘class’ (because I’m used to working in C#)…

[lua]function newBalloon( type, x, y )
local balloon = display.newBalloon( “balloon.png”, x, y )
balloon.class = “balloon”
balloon.type = type
return balloon
end

function newBall( x, y )
local ball = display.newImage( “ball.png”, x, y )

function ball:collision( event )
if (event.phase == “began” and event.other.class == “balloon”) then
if (event.other.type == “points”) then
event.other:removeSelf()
ball.points = ball.points + 1
elseif (event.other.type == “grow”) then
event.other:removeSelf()
ball.xScale, ball.yScale = ball.xScale + .1, ball.yScale + .1
end
end
end

ball:addEventListener( “collision”, ball )

return ball
end
– your logic here to create the ball and balloon by calling the functions above.[/lua]

I’ve not tested the above code, but it should demonstrate my point. I hope that answers part one of your question.

matt [import]uid: 8271 topic_id: 5378 reply_id: 17977[/import]

Thanks Bedhouin, that helped me solve it!

And thank you Matt for that!! Helped a lot! Was stuck with this collision problem for a very long time!! [import]uid: 14018 topic_id: 5378 reply_id: 17984[/import]