Optimizing code

Get help using Construct 2

Post » Thu Apr 26, 2012 6:26 pm

I was wondering along the same lines- My game spawns bad guys and they sometimes spawn on top of each other as they are programmed to randomly spawn outside of the screen and come into the screen every random number of seconds. For every new bad guy this adds another factorial to the amount of checks of overlapping that I would have to do. That is if there are five bad guys spawning- there are 5! number of ways in which they can spawn on top of each other- this gets really large really fast to write if this guy is over lapping this guy etc. I am new to programming games. SO I was wondering if there is some tool in construct 2 that can call all objects of a certain type a group name like ->ENEMY and then make it so they can't spawn on top of each other???? The thing is they have to be able to overlap with objects in the same layer as they are programmed to animate when they die- and the animation is an object in the same layer.   I was also wondering if anyone knows how to make a color always on the bottom- with most spriting and animating there is a color that is always on the bottom- or every other color gets displayed if this color (say white) ever overlaps with other colors so that objects can overlap (like a plane flying over an island). I thought initially that the layers would suffice but since the sprite image is always a square then sprites which aren't squares have a color on the outside- like white.
B
2
Posts: 1
Reputation: 402

Post » Fri Apr 27, 2012 2:54 am

[QUOTE=JamesOG] I was wondering along the same lines- My game spawns bad guys and they sometimes spawn on top of each other as they are programmed to randomly spawn outside of the screen and come into the screen every random number of seconds. For every new bad guy this adds another factorial to the amount of checks of overlapping that I would have to do. That is if there are five bad guys spawning- there are 5! number of ways in which they can spawn on top of each other- this gets really large really fast to write if this guy is over lapping this guy etc. I am new to programming games. SO I was wondering if there is some tool in construct 2 that can call all objects of a certain type a group name like ->ENEMY and then make it so they can't spawn on top of each other???? The thing is they have to be able to overlap with objects in the same layer as they are programmed to animate when they die- and the animation is an object in the same layer.   I was also wondering if anyone knows how to make a color always on the bottom- with most spriting and animating there is a color that is always on the bottom- or every other color gets displayed if this color (say white) ever overlaps with other colors so that objects can overlap (like a plane flying over an island). I thought initially that the layers would suffice but since the sprite image is always a square then sprites which aren't squares have a color on the outside- like white.[/QUOTE]
When you mean group of objects probably it's the family function you want to take a look, it's a premium feature so you need to have the paid version of C2.
After you made a family of objects you can call events with that family instead of individual sprites.
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Fri Apr 27, 2012 6:30 am

[Quote=JamesOG]I was also wondering if anyone knows how to make a color always on the bottom- with most spriting and animating there is a color that is always on the bottom- or every other color gets displayed if this color (say white) ever overlaps with other colors so that objects can overlap (like a plane flying over an island). I thought initially that the layers would suffice but since the sprite image is always a square then sprites which aren't squares have a color on the outside- like white.[/QUOTE]

That's actually a somewhat older way of doing things. I recall GameMaker used to let you pick a color for transparencies. These days though, it's best to just use transparent PNG files for your images.

Besides red, green and blue values, PNG files can have an alpha value. That not only designates that a particular pixel can be seen through, but it can be seen through to a particular degree.

If you take a look at many of the examples that come with C2, you'll see a bunch of such images. You just need an image editor that can export that format, like Photoshop or GIMP.

Just to add to this discussion too, I think optimization is an art and science itself. I'm by no means adept at it, but have the highest regard for those who know how to optimize code.
B
126
S
7
G
4
Posts: 185
Reputation: 7,233

Previous

Return to How do I....?

Who is online

Users browsing this forum: makkancs and 26 guests