instanceProto.draw won't work

0 favourites
  • 9 posts
From the Asset Store
You need this package if you want to program a Street Fighter or battle game.
  • I am doing the simplest tutorial:

    goo.gl/20ixH0

    but it won't execute "draw" method, no matter what I do.

    I even put "alert(111)" inside the body of the function, it won't fire.

    Any ideas?

  • draw() is only called in canvas2d mode, and drawGL() is called in WebGL mode. Almost everywhere runs WebGL by default.

  • Alright, so to draw anyway, I do this:

    instanceProto.drawGL = function (glw){
        this.draw(this.runtime.overlay_ctx);
    }[/code:kw3xbeg3]
    but in this case .draw()'s parameter "ctx" is null...
    How can I pass the real 2D canvas to .draw?
    I tried "this.runtime.canvas" as well as "this.runtime.overlay_canvas" - nothing is working...
  • You might see rojo's canvas plugin.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That's all wrong, you definitely cannot forward drawGL() to draw(). drawGL uses the GLWrap class, which has a completely different API to canvas2d. So it is incorrect to call one from the other. Also overlay_ctx is only used to display the loading bar. It no longer exists once the game starts, from that point on you only have a WebGL context wrapped by GLWrap and there is no canvas2d surface available.

  • Ashley, I merely saw it in a video tutorial about "How to create a Grid plugin".

    Does it mean (I ask for the sake of good coding practice) that I have to write two different chunks of code that do the same thing in those two methods? Or should I only rely on webGL and skip the "draw"?

    What I do right now is I write this:

      var sorryShown=false;
    	instanceProto.drawGL = function (glw){
        if(!sorryShown){
            alert('Sorry, but this plugin cannot be used with WebGL on.\n'
                +'To turn it off, go to Project->Enable WebGL and set it to "Off".');
          sorryShown=true;
        }
      };[/code:3vdzbl64]
    So that people won't wonder why nothing happens if they are in GL mode.
    
    Or maybe I could take advantage on a cross-context lib, like Two.js?
  • Yes, you need to write the rendering twice. All features in C2 do this. It is necessary to support both the canvas2d renderer and WebGL renderer, there isn't much we can do about that. Our long-term plan is to drop support for the canvas2d renderer, so it would be a poor choice to choose canvas2d only (especially when it can be up to 10x slower and does not support effects).

  • there isn't much we can do about that.

    What about using an existing rendering lib, like pixijs.com They claim it's a "2D webGL renderer with canvas fallback"

    Or two.js: "It is renderer agnostic enabling the same api to draw in multiple contexts: svg, canvas, and webgl."

  • Using third party libraries, in general, means we tie the fate of our product to their library, bring in lots of code we don't understand ourselves, and inherit their bugs and limitations. There is more to lose than there is to gain, so we've always avoided that and used our own libraries. Besides, it's far too late now.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)