🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Can an game object class has other object as a member?

Started by
2 comments, last by eu5 3 years, 4 months ago

Hi. I have a simple question that where is good for hit effect object.

When I shoot a missile and the missile hit a enemy, a hit effect will be created. (btw “hit effect” is correct word? let me know!)

I'm a beginner in game programming. So I don't know what I am thinking is good or bad.

A missile has a collision handler. So if a missile has collision, the handler will be called. If a missile class has a hit effect object as a member, I simply can write a code like next.

// called when this object had collision.
Missile::collision_handler(…)
{
	...
	
	// create hit effect.
	m_pHitEffectMng->Create(...);
}

// Or I have to receive the hit effect object as a handler's parameter.


What do you think guys? (I'm not using an engine.)

Advertisement

Do you havy any reason to have an SFX instance per missile? Like for having missiles with different buffs like ice, fire or poison on them? The right wording in my opinion is SFX btw.

If your answer is no then don't put it into a class instance rather than into some kind of metadata manager. When missile X hits the target, create effect Y and you are done.

On the other hand if you intend to have for some reason, dynamic objects of certain SFX type like the mentioned ice, fire or poison missile, then you need to store some kind of hint in the missile instance that lets some authoritity create the desired SFX instance.

Why do you create instances anyways? In most games I have seen, missiles or any other kind of distance projectile (arrow, bullet, throwing knife) is just a pure visual thing without any control logic behind. Sometimes they're treated as a particle system, sometimes it is just math and a white line. So instead of creating missile class instances, you should use some kind of a system that manages all those ranged weapon stuff. This will save a lot of memory and computation time as you don't have to update hundrets of missiles every frame but do that in a loop in your system

@shaarigan

Um.. first of all, I'm implementing a very simple 2D game like the Galaga. And I don't use a polygon thing.
(I'm not sure it is related.)

All of my game's object drawn on the screen is just a raster image like a png, tga.. (It's just a tutorial of game programming for me. when I finish this, I'm gonna learn the Direct3D)

So I thought every object drawn on the screen must be a class type. And I did like that I thought.

And I agree with your saying that "When missile X hits the target, create effect Y and you are done".

I think too It's a simple and good way that also I tried at first time.

But I thought that placing the effect's creation in missile's collision handler also make sense.

But I'm gonna pick your way. Thank you!

This topic is closed to new replies.

Advertisement