distance/position related opacity, masks and stuf

For questions about using Classic.

Post » Thu Dec 08, 2011 8:26 pm

hi guys!

after a long break i decided to start doing something again.
i'm starting a big project (for me), but before that i need to figure out some simple stuff. i tried to find examples or threads for my problems but couldn't really find anything.

ok so

1. about bone behavior:
is it recommended to use, instead of traditional animated frames?
or is there any known, severe problems/bugs while using it?
i once made a character using bone animation, but there were some strange animation issues and i gave up. the reason id like to use it, is i could use different frames in limbs to change my character easily (blood decals and such).

2. this is difficult to explain properly, but id like to know how to change objects opacity gradually. for example: an object is invisible at first, then starts to get gradually visible the closer another object gets to it. in short, distance based opacity..?




3. i really dont know a good way to make blood. particles wont do. im trying to make it so that the blood texture/sprite shows only in specific surfaces. for example, in walls and on the floor, but not on th e backround. could this be achieved with some kind of masking effect? i admit i dont know much about masking objects.
picture below may explain it better.



anyway, i hope someone can help me with these issues,i cant seem to figure those out.oh and sorry for my grammar.clodius6662011-12-08 20:30:01
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Thu Dec 08, 2011 11:10 pm

Here an example for your 2. question.

http://dl.dropbox.com/u/26932498/distance_visibility.cap

If there are any questions about it, just reply.

For the blood I found 2 posts from other forum users:

http://www.scirra.com/forum/permanent-blood-stains-overhead-view_topic42504.html

and from the old forum the .cap from "AsparagusTrevor", he made this from quazis blob^^:
blood.cap

I hope he don't mind if I link his .cap here again.

edit: I see some problems with the old version of the blood.cap.
If it happens to you also, try this version:
http://dl.dropbox.com/u/26932498/blood.cap

For the bone behavior, maybe "Android-Music" could help you.
He made a good example in this topic:
http://www.scirra.com/forum/bone-behavior-advanced_topic45222.html
You could ask him how he made it.

Also: http://www.scirra.com/forum/anbu-character-with-bone-behaviour_topic44620.html

By the way, I used google and typed: "site:www.scirra.com bone behavior"
without the quotes zyblade2011-12-08 23:30:44
B
24
S
9
G
2
Posts: 294
Reputation: 3,160

Post » Thu Dec 08, 2011 11:56 pm

thanks for the reply, i just tried that dist visibility cap and its just what i was looking for. only one thing: can you give me a little rundown/explanation on the piece of code you did? im just trying to understand it better, so i can use it on other things too maybe. i havent used clamp before.

and about that blood thing, yes i have tried that blood.cap before, but im not sure if its simple enough for my intentions. and the fact that its using a lot of physics objects makes me want to avoid it, for the sake of frame rate and cpu,that is. i was thinking something a little more simpler. maybe a single sprite, with phys behav and varying frames to represent a blood squirt or something. problem is that i dont know how to restrict that sprites visibility to only specific surfaces. mainly floor and walls, if near.

oh and yes i have tried bone behavior before, but i think im gonna stick to traditional animations for now, im not really convinced it works as well as basic animation.

but anyway, thanks for helping, im gonna study that visibility thing now.
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Fri Dec 09, 2011 3:00 am

I didn't have a look at zyblade's cap, but generally you just have to map the distance to the opacity by making it a relative value.

1) First you decide, which values correspond to 0% and 100%.
2) Now with those min and max values you convert the distance to a relative value.

Example:
minDistance (corresponds to 100%) 60 pixel
maxDistance (corresponds to 0%) 500 pixel
now you see that you need to map a range of 440 with an offset of 60

t-value (the relative value you want to know)
1 - (distance - minDistance) / (maxDistance - minDistance)

Let's assume distance is 280 at the moment:
1 - (280 - 60) / (500 - 60) = 1 - 220 / 440 = 1 - 0.5 = 0.5

Or distance is 170 at the moment:
1 - (170 - 60) / (500 - 60) = 1 - 110 / 440 = 1 - 0.25 = 0.75

The term "(distance - minDistance) / (maxDistance - minDistance)
" will always calculate a relative value from lowest to highest, so that in this example 60 corresponds to 0.0 and 500 to 1.0, but you need it the other way round. That's why "1 - " is added in the beginning. It reverses the result.

You now have to multiply the result by 100 to get an opacity value in the range [0, 100].

If you would use the above formula like that, you would also get values, if distance is outside your limits 60 and 500. For example, if distance is 610 at the moment:
1 - (610 - 60) / (500 - 60) = 1 - 550 / 440 = 1 - 1.25 = -0.25

But opacity only knows values between 0.0 and 1.0 (or 0% and 100%). That's why you can use clamp (it isn't really needed in this particular scenario, because opacity automatically clamps any value to the range [0, 100], but it doesn't hurt either and is good practice)

clamp(t-value * 100, 0, 100)
sets "t-value * 100" to 100 for any value that is higher than 100, and to 0 for any value that is lower than 0

If you don't feel like calculating the t-value for yourself, there's the math plugin by lucid, which, if I remember correctly, has a function to retrieve a t-value.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Dec 09, 2011 8:57 am

Exactly what tulamide says
Clamp isn't nessessary. It's just "more clean" to me.
If I want to hold a number between a min/max value, then I use clamp.
clamp(value that needs to be clamped, min, max).
So, clamp(speed, 10,100) would mean, you allways have min. the speed 10, because if you go lower, the clamp give you anyway 10^^ Same with 100 if you go higher.

I used:
100 - clamp(distance(Sprite2.x, Sprite2.y, Sprite3.x, Sprite3.y)/4,0,100)
So it's a very simple example. The only thing you can tweak is the "/4" in this formula. Put it to a lower number, then your "chest" will appear a bit later. Putting a higher value than 4 wont' really affect it.

In Tulamides example, you have the full control about when it appears/disappears. It's just a little more complex.zyblade2011-12-09 09:02:45
B
24
S
9
G
2
Posts: 294
Reputation: 3,160

Post » Mon Dec 12, 2011 12:22 am

thanks for the hints guys! i made a small quick .cap of what i was (kinda) aiming for:

http://dl.dropbox.com/u/11157144/distance_visibility.cap

theres a problem though. that "dirty lens" effect i used doesnt "follow" even though its on a different layer and the layer scroll rate set to 0. id want it so that the effect shows just like it is at first,before scrolling, but with always being relative to the sun's position on the screen. cant figure out how to do that. also, was thinking of making the lens flare angle to always point to center bottom of the layer, but im not sure how..

sure these are pretty small,pointless details, but i have always been terribly fascinated by all kinds of lens and post processing effects, be it in photography or video games.

also, now that im starting my big project sooner or later, i wanted to ask your opinions on which is ultimately best:
make less layouts full of stuff, or keep them small and make lots of layouts?

does the editor get slow when you have lots of layouts in a project?
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Wed Dec 14, 2011 9:39 pm

didnt want to make a new thread,since my question is kinda related:

i started testing a mechanic similar to sonic(surprise). that move when he starts to roll, and keeps the momentum gained from running. i thought i could somehow use a round physics object to kinda simulate that move.

now i have it so that when arrow down ke is being pressed, it spawns a different sprite (round physics object),and destroys the player sprite. when the down key is released it spawns back the player sprite and destroys the physics object.

its working ok and all, except that the physics object doesnt keep the momentum the player sprite had (which i knew would happen). so we're back with the relative value thing:

i need to somehow get the speed value of the player sprite upon key press, and translate it to a (rough?) relative force value for the physics object?

or am i completely lost and not making any sense at all?

any help would be greatly appreciated.
B
4
S
2
G
2
Posts: 109
Reputation: 1,318


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests