Shadows problem

Get help using Construct 2

Post » Sun Apr 14, 2013 9:46 pm

OMG @Yann thats a brilliant idea you got!

You are right the towers dont shade each other correctly but i got a solution.

Here

Instead of getting all masks on top of the shadow layer i let them along with the shadows to arrange in the layer the same way as the main layer stuff.

So now when the object is infront of another, the mask of the front object is over the shadow of the object in the back so it doesnt shades.

That works as a charm. There is one major problem though.... That way i got all the objects in the game multiplied by 3, as object count and as sprites. Even more i got them all ordering by Y (not sure if this affects the performance).

Btw is there a way to make the mask out of the object sprite in construct2, so i dont have to double the sprites in game?

Anyways for my project i think i'll stick with the simpliest way. Have all sprites along with shadows and live with the overlapping glitch. Sadly but i think that technique will get too much for the performance.
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Sun Apr 14, 2013 10:04 pm

[QUOTE=Pakost] OMG @Yann thats a brilliant idea you got!

You are right the towers dont shade each other correctly but i got a solution.

Here

Instead of getting all masks on top of the shadow layer i let them along with the shadows to arrange in the layer the same way as the main layer stuff.

So now when the object is infront of another, the mask of the front object is over the shadow of the object in the back so it doesnt shades.

That works as a charm. There is one major problem though.... That way i got all the objects in the game multiplied by 3, as object count and as sprites. Even more i got them all ordering by Y (not sure if this affects the performance).

Btw is there a way to make the mask out of the object sprite in construct2, so i dont have to double the sprites in game?

Anyways for my project i think i'll stick with the simpliest way. Have all sprites along with shadows and live with the overlapping glitch. Sadly but i think that technique will get too much for the performance.
[/QUOTE]

As I said, you can use and event system to sort the Z index, and throw your Z ordering plugin away. Using events you'll simple sort them, without any necessity of any other configuration than the placement of the "Imagepoint 0" on the bottom of the sprite.

Double a sprite on the canvas is surely an issue, especially on mobile devices.

Also, this sample have a nice workaround too, and sort Z as mentioned.

http://www.scirra.com/arcade/addicting-example-games/3923/isometric-game-basic-based-on-pathfinding-demo
ImageImageImageImageImageImage
B
93
S
20
G
12
Posts: 1,211
Reputation: 18,480

Post » Sun Apr 14, 2013 10:54 pm

@TELLES0808 im not quite sure but i think this z order plugin does quite the same. The only difference by me is that it arranges sprites on X also, if Y is the same.
But since this events runs per tick, and im planning to have alot of objects, i wonder if it will still be in no importaince to the performance.
Anyways, if i find a way to make those masks from the sprites in construct, so i dont double the imported images,its worth a shot. But I couldnt find a way to change the blending mode of a sprite with an action, so i suppose that cant be achieved.
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Mon Apr 15, 2013 12:24 am

yeah for the masking to work, you need the mask to be another object since you need it to be on the same layer as the shadow, and also on top of them.

Now if you double the amount of object, you indeed augment the amount of calculation.
And, if you use the ZSorter plugin, I believe it does things automagically every tick.

But if you handle sorting by yourself, you can trigger the sorting actions whenever you want.

So you can just limit the recalculation each time you move an object in the Y axis more than a given number.

One way to do this, is to use the function plugin and to create a "sort" function that will reorder the sprites

Then when you drag an object, or move your character, you monitor the Y position by storing it each time you sort the sprites (so you do the storing in the "sort" function.

Then when the difference between this value and the actual Y position of the moving sprite is greater than a given value (probably proportionnal to he size of your grid), you call the "sort" function.

Hope it wasn't too complex :D

Anyway, I think the best thing you can do to take your final decision is to run some stress test on the devices you target.

Maybe you can just decide to use one technique on desktop and another on portable devices. There's probably a way to make a simple switch so you can release easily two version.


B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Apr 15, 2013 5:00 am

I've heard countless people claim doing a for each ordered loop for sorting is the best way. Most of these people don't use it in any complex or detailed settings. It is a nightmare if you ever use any objects other than just one type (ie, if you mixed tiled backgrounds with sprites--you can't mix object types in families). Like anywhere else, I'll recommend you stick with the z-sorter plugin (and use rex's updated one, too). You can choose how often you sort in a single event. Instead of every tick, use every few milliseconds or whatever and then call the "sort objects on layer" action. It really is the best way to go currently, and you can modify things easily now, too! If you need to manually move an object in front of another, you can with C2's relatively new z-ordering events. Just call that after the z-sorter plugin call and voila!

As far as shadowing goes, perhaps a second layer could be your solution? That's my solution to the same problem in Courier. It isn't perfect, requires a little more manual placement and fixes, and can cause the player to occasionally have a shadow over (or not over) them at the wrong moment, but it sure beats doubling your objects and running anything CPU-intensive.

In actuality, I have several layers that I use for my game, really, as a solution to most of your problems.

Overshadow -- shadows on objects over the player permanently
Over -- things like rooftops always over the player
Player/objects--my z-sorted layer. Really not a ton of stuff on it in many cases
Structure shadows--shadows on structures like buildings or cliffs
Structures--buildings and such
Regular shadows--shadows like you're doing now
Ground--duh

I make the objects never overlap between the shadow layers, and it covers the majority of instances that I would require. The only downside is not getting shadows on the player, but that's a small trade-off for the tons of fixes and flexibility I get. You could run a darken/tint shader on the player if they overlap a shadow and semi-fix that issue, but otherwise this fixes about everything in a simple, easy-on-the-CPU kind of way.

I get a little more mileage since my game's perspective is more of a 3/4 view straight-on instead of isometric, so I can get away with simpler shadows at times. Also, making the shadows blurrier makes them not stand out too much AND you can blend/fake things. I have a non-uniform blobby shadow that I've gotten a ton of use out of with just stretching and rotating it to be "close" to the shadow that object would cast.

Our games are set up differently, but this all should be worth looking into to see if it helps. Scroll through the few pages of my Courier thread to see a few more of my shadowing examples because my shadows don't overlap, and buildings cast shadows on themselves, too--which is more useful to me since I don't pre-draw any of them in an image editor, but rather build them out of parts and textures in C2.

Good luck!


Bonus pro-tip: You can import some shadows objects as a tiled background, but import it upside-down. Rotate it right-side up in the editor. Now, when you resize it, you crop instead of distorting. Now you can have multiple different partial shadows using the same object. Very useful in a some rather specific instances. Also, if you need the bottom of the shadow to be round or something instead of flat, use one of your multi-purpose shape or blob shadows to fix the bottom edge. Using a uniform opacity for the layer, no-one will ever know you combined two objects to make the shadow.C-72013-04-15 05:08:28
B
90
S
32
G
14
Posts: 935
Reputation: 14,540

Post » Mon Apr 15, 2013 4:08 pm

Thanks a lot for the interest of that thread guys.

@Yann your approach is good for using z ordering only when i have to move buildings or character. Unfortunately my game is supposed to be more like tower defense with many units, so there will always be units going up and down.
Would be nice if i could move up and down in a layer only a certain class objects, having in mind the position of the others object in that layer, because most of the objects i have are static, but they need to be arranged every single time along with moving (units) objects. Since all the z ordering is structured by go to top and bottom of the layer that is impossible, I'm afraid.

@C-7 thanks for sharing this technique, its really simple, the way i like it, but unfortunately it wont work for me either :(. I need all the objects to be in one layer, ordering by z, so i can have taller units than the buildings. This works only if the characters are shorter than the building roofs. Anyways at least i can do that for the objects that surrounds the playable area like cliffs, woods etc, so they don't get arranged.
Btw your game looks fantastic.

When i got the game to alpha or something ill make some stress tests and decide for good what I'll do but for now i think I'll stick with the easiest way - leave shadows with the objects and let them stack :)

Thanks a lot guys for sharing your thoughts.
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Previous

Return to How do I....?

Who is online

Users browsing this forum: MarkThomas and 16 guests