set blur strength to sprite speed

For questions about using Classic.

Post » Mon Oct 22, 2012 12:20 pm

hi folks!

sorry if this sounds a little vague, but i was just wondering different possibilities regarding some kind of (motion) blur.

now, i was fiddling with the built in motion blur, which looks oh so nice, but is also REALLY heavy on the computer.
i was thinking of using a little more modest implementation through effects, layer effects mostly, since i would like to be able to choose which layers are blurred.
BUT, the big question:

is there any possible way to make even just the basic blur strenth adjustments in relation to the sprite's speed? meaning that the faster the player goes the more blur is applied to a specific layer.
would clamping be the way to go?
i know how i could make it work when the player crosses a certain speed the blur gets applied, but its blocky and doesnt look good. i would like it to be (completely) seamless, hence i was thinking clamping. but i just dont know a proper conditioning or events needed for that.

so, if anyone has any great ideas i would be very interested to hear them.

thanks for reading!
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Mon Oct 22, 2012 12:35 pm

To establish a relation between the sprite's speed and the blur's strength, you first need two anchor points. For example, the min and max speed values, where the blur is at zero and full strength.

You then calculate a relative value with

(current - min) / (max - min)

where current is the sprite's current speed, and min and max the anchor points of the speed. If min happens to be 0 you can omit it in the calculation.
The relative value is in the range [0,1] (but can exceed 1, if current will exceed max), so you might need to convert it to the value range that is needed for the blur's strength.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Oct 22, 2012 2:24 pm

once again, thanks for replying, tulamide!

hmm, sorry to sound like a complete idiot, but how exactly would that translate into a working condition/event? do i need to use private variables?
i'd appreciate a rough example of code to give some guidelines
this could be really useful info to implement to somewhere else also i think.
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Mon Oct 22, 2012 6:50 pm

Here is an example that takes the speed of the car behavior and transforms it into a percentage value (ranged 0-100%), the width of a bar (ranged 0-500 px) and an angle (ranged 90-360)

Hope it helps :)

http://db.tt/RXruUIYx
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Oct 22, 2012 8:31 pm

awesome, much appreciated! that works like a charm.

although, TWO things:

ever since i started using construct, ive had a hard time with speed and conditions needed to compare it.

first, how would that code work with just a sprite? meaning, how would i compare the speed value? and the max speed value?

second, i started wondering how would that be translated into using a physics behavior?

i think i understand the basic logic you showed in that example, though the car behavior makes it (sort of) easy,because it already has the conditions for the speeds of the object. sorry to bother this much,but ive noticed ive stumbled upon this same (compare any kind of speed)issue for countless of times now, and i would be really happy to get rid of it by learning how to properly compare speed in any possible situation.    
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Mon Oct 22, 2012 10:24 pm

So, the real question isn't how to set two values in relation, but how to determine speed?

I already answered that in a thread somewhere here on the forums, but I'll try to summarize it (although I can't guarantee that it will be the simplest description. I tend to say more than would be needed^^)

Speed is "distance over time". To measure speed, you can either set a fixed distance and measure the time passed, or set a fixed time and measure the distance passed.

When you move your sprite with your own events you don't need to measure anything - you already know the speed. For example, if moving a sprite by

Sprite.X = Sprite.X + 10 * TimeDelta

then the speed is 10 px/s at any time. It almost looks like a rule: n * TimeDelta = n px/s

You may also have acceleration/decceleration, but let's not make it too complicated. I just mention that these dynamics are a part of n. Something like
(10 + 20 * TimeDelta) * TimeDelta
still can be reduced to
n = (10 + 20 * TimeDelta)
and therefore the rule still applies.

If you don't have access to the values, you need to measure the speed. The simplest way is to just measure the distance moved per tick. Create three PVs (lastX, lastY, dist), set the first two to the position of the sprite at start of layout and then
+ Always
-> Set dist to distance(lastX, lastY, Sprite.X, Sprite.Y)
-> Set lastX to Sprite.X
-> Set lastY to Sprite.Y

You now have a speed value at any time. dist is the speed, expressed as px/tick. You can even extrapolate that to px/s by using TimeDelta:
-> Set Text to FormatDecimal((Sprite('dist') / TimeDelta), 1) & " px/s"

The rest is up to you. You have to decide at which speed value the blur has to be at full strength, either by calculating or by trial and error.

EDIT: The simple example above as a .cap -> http://db.tt/enNzNAQrtulamide2012-10-22 22:31:04
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 23, 2012 12:09 pm

thanks so much for explaining it so well!

oh and both the relation and the speed comparison were really helpful and pretty much crucial for what im trying to do.

i have used lastx and lasty before, but only for determining movement angles. that dist variable now makes alot more sense, ive seen it used before but really didnt know what exactly it was used for.

well, i guess i'll be fooling around with this new knowledge for the rest of the day, see if i can get anything done with it. im still a little confused on how to translate all that knowledge into a working set of conditions and event, but eh, i guess i'll just have to GET it.
but thanks again, i think i gained +2 int from this thread already clodius6662012-10-23 12:09:27
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Tue Oct 23, 2012 1:36 pm

spoke too soon i guess...

"The rest is up to you. You have to decide at which speed value the blur has to be at full strength, either by calculating or by trial and error."

thats exactly where i get lost
im not eally sure how the code should look when applying the max value of speed(dist)

in this code its easy to understand, since i already have the max speed value ready to be used in expressions:

FormatDecimal(Sprite[Car].Speed / Sprite[Car].MaxSpeed * 100, 1) & "%"

but using the dist value, i dont have the max speed, so, should i just use (Sprite('dist') / TimeDelta) two times to measure the start speed AND max speed, or should there be a different expression? i guess im just cofused about the code formula itself, even though i understand basically what im trying to achieve and how.

sorry if i sound like everything has to be explained in the way a child would understand
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Tue Oct 23, 2012 1:46 pm

Hmm, I just don't know how to explain it other than "by trial and error"

dist is just a variable, and like all variables it can be of different values. It may be at 2 or at 10 or at 20 and changing a lot throughout the game. You'd first run the game and have a look at what situation you want the blur to be most prominent. With the events implemented, you could constantly fill a text box with the current speed value. This way you see the current speed at the moment where you want the blur to be at full strength. This value is your max-speed-value.

Example: You experiment with your game and see that the sprite has a current speed of 20 at the moment where you want the blur to be at full strength. And you decide the minimum speed to be 0.

Then the calculation would be
dist / 20

and that will produce a relative number in the range [0, 1] for 0 <= dist <= 20
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 23, 2012 2:47 pm

i just meant that im not sure about the way the code should be made, i tried some variations, but didnt get any results.


but if we go by your example in your post:

max speed is 20
condition----> always
event---->    sprite-set blur to FormatDecimal((Sprite('dist') / 20), 1) going by your code, is this correct or am i missing something completely obvious? clodius6662012-10-23 14:49:54
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests