Răsfoiți Sursa

added Sprite.drawTo(texture)

ncannasse 10 ani în urmă
părinte
comite
7b1288f7d7
2 a modificat fișierele cu 22 adăugiri și 0 ștergeri
  1. 16 0
      h2d/Scene.hx
  2. 6 0
      h2d/Sprite.hx

+ 16 - 0
h2d/Scene.hx

@@ -386,6 +386,22 @@ class Scene extends Layers implements h3d.IDrawable {
 		ctx.elapsedTime = v;
 	}
 
+	function drawImplTo( s : Sprite, t : h3d.mat.Texture ) {
+
+		if( !t.flags.has(Target) ) throw "Can only draw to texture created with Target flag";
+
+		ctx.engine = h3d.Engine.getCurrent();
+		ctx.engine.begin();
+		ctx.globalAlpha = alpha;
+		ctx.begin();
+		ctx.pushTarget(t);
+		if( !t.flags.has(WasCleared) )
+			ctx.engine.driver.clear(new h3d.Vector(0, 0, 0, 0),1,0);
+		s.drawRec(ctx);
+		ctx.popTarget();
+		ctx.engine.driver.clear(new h3d.Vector(0, 0, 0, 0),1,0);
+	}
+
 	public function render( engine : h3d.Engine ) {
 		ctx.engine = engine;
 		ctx.frame++;

+ 6 - 0
h2d/Sprite.hx

@@ -247,6 +247,12 @@ class Sprite {
 		if( this != null && parent != null ) parent.removeChild(this);
 	}
 
+	public function drawTo( t : h3d.mat.Texture ) {
+		var s = getScene();
+		if( s == null ) s = new h2d.Scene();
+		@:privateAccess s.drawImplTo(this, t);
+	}
+
 	function draw( ctx : RenderContext ) {
 	}