Stacked Objects Bounce

May 7, 2010 at 7:21 PM

I'm working on a new game where I need to stack about 10 rows of "bricks" on each other. I have everything working great, except for the fact that the entire structure looks like it's alive instead of looking like a brick wall. How can I solve this?

May 7, 2010 at 11:06 PM

From my experience, 10 is a pretty high stack, unless its a really carefully made structure like a pyramid I've never been able to make it hold together in Farseer 2.1 anyway, not sure about latest version. Here are some of my experiences:

May 8, 2010 at 12:14 AM

It's actually a brick wall, consisting of many bricks. They are stacked with 1 over 2 and 2 over 1... It would be very stable if there were no bounce...

May 8, 2010 at 12:48 AM

Setting the iterations higher actually did make it a lot better, thanks. The next problem I have is this: I need to be able to get the amount of force applied to one of my bricks when a collision occurs, so I know wether or not to Destroy it. Picture a wrecking ball hitting this wall. Some would crumble, and some would go flying. I need to be able to crumble some of them, which I already know how to do, but first, I need to know the force.

I'd like to do something like:


if (Force > 10) {
Brick.Life =- 1;

May 8, 2010 at 12:52 PM

Take a look at these:

May 8, 2010 at 1:25 PM

Alright thanks, it looks like those will help. But where can I put the OnCollide Method and have it still be called? I'm using FRB, and I have a class named Brick that creates a Geom/Body inside it. I imagine I need the oncollide in this, or possibly in the screen class that wraps all the bricks. I guess this is more of a normal c# question, but I hope you can help. I've never fooled around with event handlers.

May 8, 2010 at 3:07 PM

I don't know about FRB, but I can summarise the event handlers for you.

Publishers raise events when interesting things happen, and subscribers listen for the events and react accordingly.  The Geom in this case is the publisher, and one of your game objects like an actor is the subscriber, and the interesting event is a collision.

Getting more specific, a geom object exposes an event called "OnCollision" with arguments (Geom geometry1, Geom geometry2, ContactList contactList).  If you create a method with that signature you can subscribe to the event, which means your method is "listening" for the event and will fire when the geom object decides to raise the event.  So pretend you've got a method called MyCollisionMethod, like this:

protected void MyCollisionMethod(Geom geometry1, Geom geometry2, ContactList contactList)
  ...react accordingly...

When you create your geom object, once you've created it you add this to take out your subscription:

 geom.OnCollision += MyCollisionMethod;

This attaches your MyCollisionMethod method to the event OnCollision.  It is important to then unsubscribe to the event when you are finished needing it, so you add this:

 geom.OnCollision -= MyCollisionMethod;

The reason is that a subscription keeps a subscriber alive, and it wont be eligible for GC until the publisher has gone.  Basically just add that -= unsubscription line when you are getting rid of the object that was listening to the event.

May 9, 2010 at 1:16 AM

Well that was easy enough to grasp. Now I can delete the bricks, but it seems like it's causing the game to lag after about 10 or 20 have been deleted. I'm using Geom.Dispose and Body.Dispose to delete the brick from the simulator. I hope that is right. I've narrowed it down to these two functions that slow the game down to an amazingly low fps. Any ideas?