Skip to content

Commit

Permalink
On Tap Screen - node for handling touches (double, triple…)
Browse files Browse the repository at this point in the history
Input parameters:

Duration - time during which the number of touches is counted (default value is 0.3 seconds);
Interval - the time that must elapse between touches (default value is 0);
Repeat - the number of touches that need to be done to execute the event (default value is 2).
Output parameters:

Done - event for a successful completed action;
Fail - an event for a failed action;
Tap - event on each touch;
Tap Number - how many times the user has already touched the screen;
Coords - coordinates of the touch.
  • Loading branch information
e1e5en-dev committed Sep 18, 2020
1 parent 8ae493f commit 9ac4325
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
108 changes: 108 additions & 0 deletions Sources/armory/logicnode/OnTapScreen.hx
@@ -0,0 +1,108 @@
package armory.logicnode;

import iron.math.Vec4;

class OnTapScreen extends LogicNode {

var duration = 0.3;
var interval = 0.0;
var repeat = 2;

var timer_run = false;
var timer_duration = 0.0;
var timer_interval = 0.0;
var count_taps = 0;
var coords_last_tap = new Vec4();

// New (constructor)
public function new(tree: LogicTree) {
super(tree);
tree.notifyOnUpdate(update);
}

// Clear var
function clear_var() {
timer_run = false;
count_taps = 0;
timer_duration = 0.0;
timer_interval = 0.0;
}

// Save vector coords
function save_vector_coord(x: Float, y: Float) {
coords_last_tap.x = x;
coords_last_tap.y = y;
}

// Update
function update() {
var surface = iron.system.Input.getSurface();
// In parameters
if (surface.started() == true) {
duration = inputs[0].get();
interval = inputs[1].get();
repeat = inputs[2].get();
}
// Check
if ((repeat <= 0) || (duration <= 0)) {
clear_var();
return;
}
// timer_duration check
if (timer_run == true) {
timer_duration += iron.system.Time.delta;
if (interval > 0) timer_interval += iron.system.Time.delta;
}
// First Tap, start timer
if ((surface.started() == true) && (count_taps == 0)) {
clear_var();
count_taps += 1;
save_vector_coord(surface.x, surface.y);
runOutput(2); // action Tap
timer_run = true;
} else {
// Next Taps
if ((surface.started() == true) && (timer_duration < duration)) {
if (interval > 0) {
if (timer_interval >= interval) {
count_taps += 1;
save_vector_coord(surface.x, surface.y);
runOutput(2); // action Tap
timer_interval = 0;
}
} else {
count_taps += 1;
save_vector_coord(surface.x, surface.y);
runOutput(2); // action Tap
}
}
// Time passed
if (timer_duration >= duration) {
// Taps completed
if (count_taps >= repeat) {
save_vector_coord(surface.x, surface.y);
runOutput(0); // action Done
return;
}
clear_var();
runOutput(1); // action Fail
} else if (count_taps >= repeat) {
// Taps completed
save_vector_coord(surface.x, surface.y);
runOutput(0); // action Done
clear_var();
}
}
}

// Get - out
override function get(from: Int): Dynamic {
switch (from) {
// Out value - Tap Number
case 3: return count_taps;
// Out value - Coords last tap
case 4: return coords_last_tap;
}
return null;
}
}
25 changes: 25 additions & 0 deletions blender/arm/logicnode/input/LN_on_tap_screen.py
@@ -0,0 +1,25 @@
from arm.logicnode.arm_nodes import *

# Class OnTapScreen
class OnTapScreen(ArmLogicTreeNode):
"""On Tap Screen Node"""
bl_idname = 'LNOnTapScreen'
bl_label = 'On Tap Screen'
arm_version = 1

def init(self, context):
super(OnTapScreen, self).init(context)
self.add_input('NodeSocketFloat', 'Duration')
self.inputs[-1].default_value = 0.3
self.add_input('NodeSocketFloat', 'Interval')
self.inputs[-1].default_value = 0.0
self.add_input('NodeSocketInt', 'Repeat')
self.inputs[-1].default_value = 2
self.add_output('ArmNodeSocketAction', 'Done')
self.add_output('ArmNodeSocketAction', 'Fail')
self.add_output('ArmNodeSocketAction', 'Tap')
self.add_output('NodeSocketInt', 'Tap Number')
self.add_output('NodeSocketVector', 'Coords')

# Add Node
add_node(OnTapScreen, category=PKG_AS_CATEGORY, section='Input')

0 comments on commit 9ac4325

Please sign in to comment.