Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

Request: Render canvas to bitmap

Open proyb6 opened this issue 10 years ago • 3 comments

If redraw canvas on every "Draw" event is unnecessary, I need a way to draw and transform shapes dynamically into a canvas layer and flatten into a bitmap or sprite for frames that can be added to stage.

Currently, as far as my knowledge in creating component with canvasLayer with 100+ variations e.g. abstract arts animations.

Crafty.c("drawPlank", {
    init:function(){
        this.addComponent("2D,Canvas");
        this.bind("Draw", this.sdraw);  //Does it need to keep rendering with expensive call?
        this.ready=true
    },
    sdraw: function(e) {
        var ctx=Crafty.canvasLayer.context; 
        var tan360=Math.tan( 0.2 );  //different angles/variations
        ctx.setTransform(1, tan360, 0,1,0,0);
        ctx.lineWidth = 8;
        ctx.beginPath();
        ctx.moveTo(e.pos._x, e.pos._y+20);
        ctx.lineTo(e.pos._x+50, e.pos._y+20);
        ctx.stroke();
     }
});

proyb6 avatar Dec 12 '15 16:12 proyb6

Lokstar's answer might be interesting for Crafty.

http://stackoverflow.com/questions/23468218/draw-10-000-objects-on-canvas-javascript

http://www.professorcloud.com/mainsite/cache-canvas.htm

proyb6 avatar Dec 12 '15 16:12 proyb6

I'm definitely interested in the idea of a way to render a component to a canvas, and then just use that as a texture. I don't think it's conceptually very difficult, but it might require some refactoring under the hood.

I'm currently working on making the way we render to graphics layers a bit more flexible, this is a use case I'll try to keep in mind.

starwed avatar Dec 13 '15 18:12 starwed

Great, creating awesome engine from the conceptual idea in your avatar + Google doodle style. Why don't you start drawing an owl to Egypt to Roman to China that will fly in span of 3,000 years?

or illusion animation using Layers.

Use pixel animation or distortion or even skew motion http://www.effectgames.com/demos/canvascycle/

Lines http://www.mta.me/

I think this song will give you much inspiration: https://soundcloud.com/roni1990roni/e-s-posthumus-nara

Crafty.js need to expand into a bigger engine since you have the advantage that other game engines have forgotten or are too complicated to maintain, Phaser is an example.

proyb6 avatar Dec 15 '15 13:12 proyb6