Destroy ball object after two bounces

For questions about using Classic.

Post » Wed Sep 03, 2008 1:26 am

Sorry, I know I asked this in my other post but I felt like it'd be better off to make a new post about this.

I can't seem to figure out how to destroy the ball object after it has bounced two times. Not only that, but I want to make it so that a sound effect plays every time it bounces off of a wall.

I was thinking of making is so when the ball collides with a solid, it rasies a private variable up by 1. Then when it gets to a certain value, it destroys itself. But that doesn't work. The value stays at zero even when it collides with the wall. It doesn't play a sound effect either, no matter what I do.

There doesn't seem to be an event option to check for if the ball has "bounced" or not. Maybe I'm wrong. But I can't seem to figure out how to do this simple thing in Construct. Could anyone help me out?
B
2
S
2
G
4
Posts: 153
Reputation: 1,756

Post » Wed Sep 03, 2008 2:08 am

There doesn't currently seem to be any way to test for collision directly with a ball object. You can make a second, invisible sprite slightly larger than the ball, and put it on top of the ball and test for collisions that way.

It would be nice to have a ball behavior condition that tests for collision though (there aren't any ball behavior conditions at all currently). Or simply make the sprite collision condition work in tandem with the ball behavior. You might want to hit up the feature request thread.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Sep 03, 2008 2:21 am

Hmm... well, what happens is the 'Bounce off solids' option in the ball movement, when ticked, automatically moves the object off the solid and changes the direction. Because it's moved off, by the time the 'On collision' event comes to be tested, it's still not overlapping.

Deadeye's solution could work, or you could try turning off 'Bounce off solids' in the ball properties. You can then add an event - ball collides with sprite - and add the 'Bounce off object' action in the ball to bounce it off. Then you can add your own actions to the event as well, like playing sounds and incrementing counters. I just tried it, though, and the collisions are a little less accurate this way. You might need to make the bullets slower.

I think I can fix this for a future build though - so if the ball registers a collision when deciding if it should bounce, then it should also register a collision in the events. This might get physics objects to register collisions as well...
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Wed Sep 03, 2008 2:42 am

[quote="Ashley":2ii2jgrk]I think I can fix this for a future build though - so if the ball registers a collision when deciding if it should bounce, then it should also register a collision in the events. This might get physics objects to register collisions as well...[/quote:2ii2jgrk]


Yes, yes, a thousand times YES! If you could do this I would be ecstatic.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Sep 03, 2008 5:08 am

I second that notion. I hope to see this fixed right away. Thanks Ashley.
B
2
S
2
G
4
Posts: 153
Reputation: 1,756


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests