Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Expert Advise needed: Balls & Can game

Author
Message
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 7th Dec 2011 14:53
I made a simple game where balls fall off the top of the screen, and you have to catch them in a tincan, that only moves left and right.

I want to detect when a ball actually falls inside the tincan, not when it hits the sides of the tincan or hits halfway in - half way out (along x co-ords).

If you have an easy solution without using Physics, I can appreciate any help & ideas.

Thanks
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 7th Dec 2011 15:00 Edited at: 7th Dec 2011 15:44
Can you not have an invisible sprite which fills the bottom 3rd (or however much you need) of the tincan. Which also moves left and right with the tincan. Then just use 'GetSpriteCollision'?

EDIT: Reading your post again, are you saying that if a ball collides with the side of the tincan, then the tincan should pass through the ball? and not deflect it?
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 7th Dec 2011 16:11
yes the invisible sprite at the bottom to trigger the hit is good.

However the problem is with the sides of the tincan and especially if the ball falls 1/3 in the opening of the can and 2/3 outside...
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 7th Dec 2011 16:18
Ok, I hear yah... I'm not sure about that...

Quick question though, why don't you use physics and have it so that the tincan deflects the ball when it hits it... So if the ball falls on the top edge of the can, the ball deflects either in the can, or out (depending on how it fell)? Similarly, if you move the tincan right (or left) and it hits a ball on the side, it just pushes the ball out the way, rather than passing through? That way the above will work as a ball can only be either in the can or out, and no inbetween...
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 7th Dec 2011 16:23
I am trying to avoid physics. my game currently runs at full 60fps on an iphone 3gs. if i switch on physics, the fps is dropping down quite a lot.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Dec 2011 17:40
I struggle to believe that physics is having a noticeable effect on your fps...? Box2D is notoriously fast. I've had hundreds of physics objects on screen at one time with no slow down at all on my iPod touch. Are you sure it wasn't caused by something else?

Your problem can be solved without physics by using multiple thin 'dummy' sprites detecting collisions on the different edges. That's the simplest way to do it I'd say.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 7th Dec 2011 19:35
You don't need to check for collisions for such a simple idea. Just compare the x positions of the ball and the can. If the difference is too big then the ball is outside. You perform this check when the ball reaches a specific y position, when it would go into the can.

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 7th Dec 2011 21:45
Baxslash, if i remove the physx, the game is back at 60fps!

i will try to implement a few dummy sprites and upon collision detection decide what fate the ball should have!

thanks a lot

Login to post a reply

Server time is: 2024-11-22 19:21:09
Your offset time is: 2024-11-22 19:21:09