ctx.drawimage in construct2 how to ?

0 favourites
  • 12 posts
From the Asset Store
Creating Artificial Intelligence Games Using Construct2 and Construct3.
  • I'm trying to make a plugin where i need to draw a image on the canvas runtime. Examples of javascript on the internet shows ctx.drawimage etc. But that does not work with Construct2. I did a quick look in the official sprite plugin. And used the method in "Load image from url". It works but offcourse it's buggy. How can i simple draw something on the canvas is there a documentation or example of this ?

  • You could use one of these:

  • You could use one of these:

    Great plugins, looking now in your source to learn what you did

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "Load image from URL" should work fine. The most common problem is cross-domain security restrictions - the server you load from has to explicitly allow you to load the image remotely.

    By default Construct 2 uses WebGL rendering, so will call your plugin's drawGL function instead of draw (which is for canvas2d). You need to write both and have them render the identical thing.

  • "Load image from URL" should work fine. The most common problem is cross-domain security restrictions - the server you load from has to explicitly allow you to load the image remotely.

    By default Construct 2 uses WebGL rendering, so will call your plugin's drawGL function instead of draw (which is for canvas2d). You need to write both and have them render the identical thing.

    Offcourse "Load Image from URL" works great, the bug was somewhere else. Just did a clean code with the example of R0J0hound and got the same problem :

    What i'm doing :

    acts.OpenCam = function ()
    {
    var img = CocoonJS["Camera"]["startCapturing"](0, this.width, this.height, 30);
    var ctx=this.ctx;
    ctx.drawImage(img,0,0,this.width,this.height);
    this.runtime.redraw = true;
    this.update_tex = true;
    }[/code:qpnzdexg]
    
    Funny enough this works only if i don't add an object to the game (Sprite, text etc).
    If it's only the Canvas plugin in the project and i fire the OpenCam function on start of layout it works great.
    I'm exporting in CocoonJS mode, the plugin is for cocoonjs camera.
    
    I'm trying to get the camera from IOS for AR effect to use as background, and CocoonJS Camera function is working with IOS.
    Also tried this to get the camera for IOS but that failed:
  • You can't draw anywhere other than in your plugin's draw() or drawGL() callback. If you draw in an action it will ignore the object's scrolling and Z order, and overdraw it with the rest of the game.

  • Ashley

    How should i draw it to keep the camera on ? Because the way i'm doing it, the camera stops when another object spawns. I made a quick demo of the problem.

    Can you please check what I'm doing wrong in this plugin ( includes the plugin & capx project in the .zip ) :

    https://yadi.sk/d/DenXnfBEbdGUZ

    For a demo of the plugin open this url in cocoonjs canvas+ launcher:

    http://www.weebe.nl/camera

  • I'm not sure what you mean by "keep the camera on", but if you mean keeping it always on-screen, don't code your plugin to do that. The user will put it on a 0-parallax layer if they want that.

  • Ashley

    The problem is, the camera shuts off and shows its sprite color when another object gets spawned. So it only works if it's the only object in the layout. I don't want to keep the camera always on, but i want him to not stop without users command. It's a weird bug. The demo should first show the back camera of the mobile device in cocoonjs, after 5 seconds i spawn a blue sprite and the camera stops. :S

  • One easy way is making a behavior of rojo's canvas plugin, to display something on the canvas, so that you don't need to maintain the code of canvas-to-engine side.

  • One easy way is making a behavior of rojo's canvas plugin, to display something on the canvas, so that you don't need to maintain the code of canvas-to-engine side.

    Can you give a demo, or write a code how to do what i'm trying in behavior ?

  • For example,

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