Graphic Editor Timed event

Started by
4 comments, last by ErnieDingo 7 years, 7 months ago

HI Guys,

I have an idea on how to solve my problem, but I would like to know whether there are better techniques.

Problem: When holding down the mouse in my 3d editor (.NET windows 10), I would like to use the length of time held down to trigger events repeatedly that add a value to another value.

Explicitly: When I hold the left mouse button(lmb) down, I would like to increase the alpha blend value of a point over the time I have held the lmb down for.

So if 0 to 1 on the blend scale takes 3 seconds to reach full value of "1". Then after one second it would be .33. I know it sounds a little bit inaccurate in terms of obtaining an exact alpha value, but I have other functions to deal with that in my editor. It's really just a alpha blend painting value.

I was going to use a timer to then fire off the mouse down event again, is this best?

Thanks in advance for any ideas, I don't believe I have the right answer, I have a functional one I believe ,just wondering if there are more elegant solutions.

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

Advertisement

I was going to use a timer to then fire off the mouse down event again, is this best?


That sounds fine to me. It's probably the simplest solution. Just make sure the mouse down handler that the timer calls doesn't restart the timer :)

Personally, I'd use a slider or a roller as it gives finer control.

Personally, I'd use a slider or a roller as it gives finer control.

Definitely a good option as well.

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

I think the best would be to:

OnMousePressed:

previous_time = current_time

start updating

OnMouseReleased:

stop updating

OnUpdate:

current_time = getCurrentTime();

setAlpha( getAlpha() + alpha_per_second * ( current_time - previous_time ) );

previous_time = current_time;

Essentialy: keep updating your object when mouse is pressed on it and in each update use duration of the mouse press from previous update to set desired value.

I think the best would be to:

OnMousePressed:
previous_time = current_time
start updating

OnMouseReleased:
stop updating

OnUpdate:
current_time = getCurrentTime();
setAlpha( getAlpha() + alpha_per_second * ( current_time - previous_time ) );
previous_time = current_time;

Essentialy: keep updating your object when mouse is pressed on it and in each update use duration of the mouse press from previous update to set desired value.


In the end I've used a timer every 25ms to update the alpha blend value. Works quite well but yes that would work also!

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

This topic is closed to new replies.

Advertisement