openfl / starling

Known as the "Cross-Platform Game Engine", Starling is a popular Stage3D framework for OpenFL and Haxe
Other
236 stars 68 forks source link

RenderTexture not working on HTML5 target #108

Closed varadig closed 5 years ago

varadig commented 6 years ago

Thre render textureing is not work properly under html5 target. On flash is working. with rendertexture.draw on touch is working I made a simple test to represent the issue:

Main.hx:

package;

import openfl.display.Sprite;
import starling.core.Starling;
import View;

class Main extends Sprite {
    var starling:Starling;

    public function new () {

        super ();
        this.starling = new Starling(View, this.stage);
        this.starling.start();
    }
}

View.hx

package;
import starling.display.*;
import starling.textures.RenderTexture;

class View extends Sprite {
    public function new() {
        super();

        var quad:Quad = new Quad(100,100,0xFF0000);
        var renderTexture:RenderTexture = new RenderTexture(100,100);

        var image:Image = new Image(renderTexture);
        renderTexture.draw(quad);
        this.addChild(image);

    }
}

project.xml

<?xml version="1.0" encoding="utf-8"?>
<project>

    <meta title="TestStarling" package="com.sample.teststarling" version="1.0.0" company="Company Name" />
    <app main="Main" path="Export" file="TestStarling" />

    <source path="Source" />

    <haxelib name="openfl" />
    <haxelib name="starling" />

    <assets path="Assets" rename="assets" />

</project>

html5 screenshot: https://www.dropbox.com/s/i40lw6nphoxcue9/Screenshot%202018-07-20%2013.40.55.png?dl=0

flash screenshot: https://www.dropbox.com/s/kt50ixc2bgmjw74/Screenshot%202018-07-20%2013.41.24.png?dl=0

varadig commented 6 years ago

Here is the extended sample:

View.hx

package;
import starling.display.*;
import starling.textures.RenderTexture;
import starling.events.*;
import starling.core.Starling;

class View extends Sprite {
    private var quad:Quad;
    private var renderTexture:RenderTexture;
    public function new() {
        super();

        this.quad= new Quad(100,100,0xFF0000);
        renderTexture= new RenderTexture(100,100);

        var image:Image = new Image(renderTexture);
        renderTexture.draw(quad);
        this.addChild(image);

        Starling.current.stage.addEventListener(TouchEvent.TOUCH,function(event:TouchEvent):Void{
                var touch:Touch = event.getTouch(this,TouchPhase.BEGAN);
                if(touch==null) return;

                this.quad.x =touch.getLocation(this).x;
                this.quad.y =touch.getLocation(this).y;     
                this.renderTexture.draw(this.quad);     
        });

    }
}

https://www.youtube.com/watch?v=ErAQK3xSCQA

jgranick commented 5 years ago

This is working on HTML5 with the current version of Starling 2, sorry for the delay, but glad to see it working :smile: