DrawOnceTexture - Draw a Texture in JS via CanvasContext

A place to post your custom classes and engine extensions to share with the community.

DrawOnceTexture - Draw a Texture in JS via CanvasContext

Postby DrDynamic » Wed Apr 12, 2017 2:33 pm

Hi everyone,

I'm new to IsogenicEngine and wanted to create Textures in my JavaScript Source.
Especially in the early builds, it's nice to quickly draw a texture in JS to Test implementations etc...
You could possibly use a SmartTexture instead but I wanted to use it for a backgroundPattern and found, that this wont work with a SmartTexture.

To realize this, I have extended the IgeTexture Class and modified the image loading logic.

    - This Texture Class does not call ige.textureLoadStart() and ige.textureLoadEnd() => so if you only have DrawOnceTexture Classes the 'texturesLoaded' event won't fire!
    - Make sure to adjust the canvas size before you draw onto the context.

Here is a little snipped to show how to use the DrawOnceTexture class:
Code: Select all
var myTexture = new DrawOnceTexture()
            .create(function(canvas, ctx)
                canvas.height = 50;
                canvas.width = 50;

                ctx.fillStyle = '#6c6c6c';
                ctx.fillRect(0, 0, 50, 50);


Let me know what you think about it :)

btw. Sorry for the bad english (i'm no native speaker)
(2 KiB) Downloaded 712 times
Posts: 3
Joined: Tue Apr 11, 2017 12:39 pm

Return to Custom Code

Who is online

Users browsing this forum: No registered users and 1 guest