Skip to content

Instantly share code, notes, and snippets.

@haxiomic
Last active August 29, 2015 14:16
Show Gist options
  • Save haxiomic/b0128482fa1d8dfbced0 to your computer and use it in GitHub Desktop.
Save haxiomic/b0128482fa1d8dfbced0 to your computer and use it in GitHub Desktop.
Working features touch_events
import luxe.Color;
import luxe.Input;
import luxe.Screen;
class Main extends luxe.Game {
var colors:Array<Color>;
override function config(config:luxe.AppConfig) {
#if web
config.window.fullscreen = true;
#end
return config;
}
override function onwindowsized( e:WindowEvent ) {
Luxe.camera.viewport = new luxe.Rectangle( 0, 0, e.event.x, e.event.y);
}
var r = 8.0;
override function ready() {
Luxe.renderer.clear_color.rgb(0x121212);
r = Luxe.screen.h * 0.01;
colors = [
new Color().rgb(0xf6007b),
new Color().rgb(0x007bf6),
new Color().rgb(0xe2f44d),
new Color().rgb(0xf94b04),
new Color().rgb(0xf67b00),
new Color().rgb(0xffffff),
];
} //ready
//fix to ensure all platforms have the same touch_index the value of touch_id
var touches = new Array<Null<Int>>();
function add_touch(touch_id:Int) : Void {
var i = touches.indexOf(null);
if(i > -1) touches[i] = touch_id;
else touches.push(touch_id);
}
function remove_touch(touch_id:Int) : Void {
touches[touches.indexOf(touch_id)] = null;
}
function get_touch_index(touch_id:Int) : Int {
return touches.indexOf(touch_id);
}
//
function getColor(i:Int){
if(i>colors.length-1 || i<0){
trace("Color i out of range", i);
return colors[0].clone();
}
return colors[i].clone();
}
override function onkeyup( e:KeyEvent ) {
if(e.keycode == Key.escape) {
Luxe.shutdown();
}
} //onkeyup
override function ontouchdown(e:TouchEvent) {
trace(e.touch_id);
add_touch(e.touch_id);
var touch_index = get_touch_index(e.touch_id);
Luxe.renderer.clear_color.tween(0.5, {r:0.1, g:0.1, b:0.1});
var g = Luxe.draw.ring({
r:r,
color: getColor(touch_index),
x:e.x * Luxe.screen.w,
y:e.y * Luxe.screen.h,
});
Luxe.timer.schedule(2, function(){ g.color.tween(1, {a:0}).onComplete(function(){ g.drop(); }); });
}
override function ontouchup(e:TouchEvent) {
var touch_index = get_touch_index(e.touch_id);
remove_touch(e.touch_id);
Luxe.renderer.clear_color.tween(0.5, {r:0.05, g:0.05, b:0.05});
var g = Luxe.draw.ring({
r:r,
color: getColor(touch_index),
x:e.x * Luxe.screen.w,
y:e.y * Luxe.screen.h,
});
Luxe.timer.schedule(2, function(){ g.color.tween(1, {a:0}).onComplete(function(){ g.drop(); }); });
}
override function ontouchmove(e:TouchEvent) {
var touch_index = get_touch_index(e.touch_id);
var g = Luxe.draw.ring({
r:r/2,
color: getColor(touch_index),
x:e.x * Luxe.screen.w,
y:e.y * Luxe.screen.h,
});
Luxe.timer.schedule(2, function(){ g.color.tween(1, {a:0}).onComplete(function(){ g.drop(); }); });
}
} //Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment