It is currently 8:00 pm 09/07/10


Post a new topicPost a reply Page 1 of 1   [ 9 posts ]
Author Message
 Post subject: How can I add collision to emitters
PostPosted: 10:09 pm 07/29/10 
FRB Rookie
FRB Rookie

Joined: 6:48 pm 01/31/10
Posts: 9
I added the emitter to spriteList
Code:
emitter.emit(spiteList)


And I use this method to add AAR collision to each sprites
Code:
foreach (sprite in spriteList)
{ SetSpriteCollision(sprite) }


This is SetSpriteCollision() Method
Code:
private void SetSpriteCollision(Sprite sprite)
{
AxisAlignedRectangle rectangle = new AxisAlignedRectangle();
rectangle.X = sprite.X;
rectangle.Y = sprite.Y;
sprite.setCollision(rectangle);
}


When use to Entity class or a normal Sprite object, it's worked.
But when do this with Emitter it's nothing.

Did I do wrong? or Emitter can't do the collision?

Thanks in advance.


Top
 Profile E-mail  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 11:11 pm 07/29/10 
FRB Founder
FRB Founder
User avatar

Joined: 6:48 pm 01/17/05
Posts: 4290
Location: South Ogden, UT
That code sets the collision on the Sprite. You still have to call CollideAgainst or CollideAgainstMove or CollideAgainstBounce.

_________________
--Vic--


Top
 Profile E-mail  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 12:17 am 07/30/10 
FRB Rookie
FRB Rookie

Joined: 6:48 pm 01/31/10
Posts: 9
So I changed the code to...

Code:
foreach (Sprite sprite in SpriteList)
{ AxisAlignedRectangle rectangle = ShapeManger.AddAxisAlignedRectangle();
sprite.ScaleX = rectangle.ScaleX = rectangle.ScaleY;
rectangle.AttachTo(sprite, false);
}


This is how I can Add AAR to the emitter.
BUT! only the first sprite is attach to the AxisAlignedRectangle.

How can I attach AxisAlignedRectangle to every sprites in this emitter?

edit------

After that I use for loop too...

Code:
for (int i = 0; i < spriteList.count; i++)
{ AxisAlignedRectangle rectangle = ShapeManger.AddAxisAlignedRectangle();
spriteList[i].ScaleX = rectangle.ScaleX = rectangle.ScaleY;
rectangle.AttachTo(spriteList[i], false);
}


It's only attach AAR to the first sprite that emit from the emitter like above.

Screenshot:

Image

Please help... :(


Top
 Profile E-mail  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 2:34 am 07/30/10 
FRB Specialist
FRB Specialist

Joined: 10:56 am 07/20/08
Posts: 291
Location: Amsterdam, the Netherlands
Your loop(s) seems fine, so I guess it's going wrong with the emitting / filling of the spritelist. Can you post the entire code?

Next, as Vic said, adding AA rectangles to sprites doesn't give you magically collisionchecking. That's something you have to do manually. You need to call SpriteA.CollideAgainst(SpriteB) for every pair of sprites. When that returns true, there is collision and you can handle it the way you want. There are also CollideAgainstMove() and CollideAgainstBounce() that handle some of the replacing of objects themselves.

_________________
- KeeWeed -


Top
 Profile  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 5:40 am 08/03/10 
FRB Rookie
FRB Rookie

Joined: 6:48 pm 01/31/10
Posts: 9
As I said before, my problem is not about the collision checking.
My problem is how to attach collisions to every sprites in the emitter.

If my code is correct. Why it's just attach one AAR at the first sprite?

Use For loop and/or foreach to check each sprite in the spriteList and attach collision to each sprite.
Why it's just attach to the first? What's about the remain sprites?

OK, I changed from AAR to a simple circle shape.

Edit---
If you really want to see the code.

Initialize Method:
Code:
bullet1Collision = ShapeManager.AddCircle();
bullet1Collision.Color = Color.Red;

            // Setup bullet1 Emitter
            bullet1 = new Emitter();
            bullet1.Texture = FlatRedBallServices.Load<Texture2D>("Content/Objects/Entity1");
            bullet1.EmissionSettings.VelocityRangeType = RangeType.Cone;
            bullet1.EmissionSettings.WedgeSpread = 0;
            bullet1.EmissionSettings.RadialVelocity = 5;
            bullet1.EmissionSettings.AlphaRate = -.1f;
            bullet1.RotationZVelocity = 4;

            bullet1.TimedEmission = true;
            bullet1.SecondFrequency = .05f;
            bullet1.RemovalEvent = Emitter.RemovalEventType.Alpha0;

            SpriteManager.AddEmitter(bullet1);

            bullet1SpriteList = new SpriteList();
            bullet1.Emit(bullet1SpriteList);

            foreach (Sprite sprite in bullet1SpriteList)
            {
                bullet1Collision.AttachTo(sprite, false);
            }


Update Method:
Code:
bullet1.TimedEmit(bullet1SpriteList);


This is the result :
Image

If you see the red circle around the sprite. that's a circle shape that I attached to them.
But it's not attach to the other sprites.

I've waited for the answer for almost two days. Please help.


Top
 Profile E-mail  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 6:49 am 08/03/10 
FRB Rookie
FRB Rookie

Joined: 6:48 pm 01/31/10
Posts: 9
Sorry for double post. But I have to say I messed up something.
So I fix it by move something to update method and everything's fine.

.. XD


Top
 Profile E-mail  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 8:45 am 08/03/10 
FRB Founder
FRB Founder
User avatar

Joined: 6:48 pm 01/17/05
Posts: 4290
Location: South Ogden, UT
Yes, Initialize is only called once, so that would explain why that's happening.

I've also done this just in case anyone else needs more help on this topic:

http://www.flatredball.com/frb/docs/index.php?title=FlatRedBall.Graphics.Particle.Emitter:Particle_Collision

_________________
--Vic--


Top
 Profile E-mail  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 9:33 am 08/03/10 
FRB Rookie
FRB Rookie

Joined: 6:48 pm 01/31/10
Posts: 9
Roof Top Pew Wee wrote:
Yes, Initialize is only called once, so that would explain why that's happening.

I've also done this just in case anyone else needs more help on this topic:

http://www.flatredball.com/frb/docs/index.php?title=FlatRedBall.Graphics.Particle.Emitter:Particle_Collision


Thanks a lot. :D

But you must to fix this secion.

--FlatRedBall.Graphics.Particle.Emitter|<- Back to Emitter]]

It's not a link.


Top
 Profile E-mail  
 
 Post subject: Re: How can I add collision to emitters
PostPosted: 10:39 am 08/03/10 
FRB Founder
FRB Founder
User avatar

Joined: 6:48 pm 01/17/05
Posts: 4290
Location: South Ogden, UT
Good catch - fixed.

_________________
--Vic--


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 9 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
twilightBB Style by Daniel St. Jules of Gamexe.net