Skip to content

Instantly share code, notes, and snippets.

@PrimaryFeather
Created March 8, 2018 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrimaryFeather/fde2aff4e27fcf06d016c5e03f8926c8 to your computer and use it in GitHub Desktop.
Save PrimaryFeather/fde2aff4e27fcf06d016c5e03f8926c8 to your computer and use it in GitHub Desktop.
package starling
{
import flash.utils.getTimer;
import starling.display.Image;
import starling.display.Quad;
import starling.display.Sprite;
import starling.events.Event;
import starling.events.TouchEvent;
import starling.events.Touch;
import starling.textures.RenderTexture;
/**
* ...
* @author Daniel Sperl
*/
public class TouchExperiments extends Sprite
{
private var _background:Image;
private var _brush:Quad;
private var _renderTexture:RenderTexture;
public function TouchExperiments()
{
super();
addEventListener(Event.ADDED_TO_STAGE, init);
}
public function start():void
{
}
private function init(e:Event):void
{
_brush = new Quad(5, 5)
_renderTexture = new RenderTexture(stage.stageWidth, stage.stageHeight);
_background = new Image(_renderTexture);
addChild(_background);
removeEventListener(Event.ADDED_TO_STAGE, init);
addEventListener(TouchEvent.TOUCH, onTouch);
}
private function onTouch(e:TouchEvent):void
{
var time:int = getTimer();
var touches:Vector.<Touch> = e.getTouches(this);
_renderTexture.drawBundled(function():void
{
for (var i:int = 0; i < touches.length ; i++)
{
//trace(time, touches.length, touches[i].phase);
var touch:Touch = touches[i];
_brush.x = touch.globalX;
_brush.y = touch.globalY;
_brush.color = Math.random() * 0xffffff;
_renderTexture.draw(_brush);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment