|
|
|
|
Reply From: |
YeOldeDM |
extends Particles2D
func _ready():
set_process_input(true)
func _input(event):
set_emitting( event.type == InputEvent.MOUSE_MOTION )
Maybe not the most efficient way, but probably the most direct way.
Thanks, but this isn’t working for me,I don’t know why?
maybe detecting mouse cursor speed?
mouse_speed = 0
mouse_speed = 1
Bishop | 2017-02-14 00:07
_input
won’t do anything without input so you can’t detect a no-input.
Add a variable to control the emission and set to true inside _input
the same way but set it to false at the end of each process (after using it for emission).
@eons Thanks but only with a script solution I still not get it… where put variables?..you can show on the example?..i’m still a novice in GD script.
Bishop | 2017-02-14 01:58
It should be a control/flag variable on the script.
Just think (and write if possible) what you want to do:
-If moving, it must emit particles
-In any other scenario must stop emitting
It means that you need a variable to register that “moving” event but be always off when not moving.
var moving = false #the variable
func _input(event):
if event.type == InputEvent.MOUSE_MOTION: #is moving
moving = true #should emit
func _process(delta):
set_emitting(moving) #if moving emit, if not, don't
moving = false #always false
#covers all the non moving situations, input will turn to true if moving
(you must turn on process and input, of course)
That is a simple way to turn on/off flags, useful in a many scenarios where no-events change behaviors.
Thanks guys for your help…that’s very helpful.
… in the input (event) function must be at the end of the code … set _ emitting (true) for emitting particles
…We have two options 1) use animation player + script
2) only script… this option probably is better for framerate?
This works great:
extends Particles2D
var moving = false #the variable
func _ready():
set_process_input(true)
set_process(true)
func _input(event):
if event.type == InputEvent.MOUSE_MOTION:
moving = true
set_emitting(true)
func _process(delta):
var ms = get_global_mouse_pos()
set_global_pos(Vector2(ms))
set_emitting(moving)
moving = false
Bishop | 2017-02-14 14:57