R0J0hound's Forum Posts

  • Can't look at the capx because it uses plugins I don't have installed. You can look in preview.js for the exact implementation but if you had to do dt and time with the event sheet this is what it would look like:

    global number time=0

    global number previoustime=0

    global number dt=0

    every tick

    --- set dt to min(0.1, wallclocktime-previoustime)

    --- set previoustime to wallclocktime

    --- add dt to time

  • Looks like the closest you can get to the runtime snapshot is to use pretick.

    Basically run this when the plugin is created:

    this.runtime.pretickMe(this);

    Then when you run the action to capture the pixel, you set a boolean in your plugin and tell the runtime to redraw.

    this.runtime.redraw=true;

    Then in pretick you'd grab it.

    I wouldn't call drawgl directly. I mean you could but it would be very slow. Getting pixels from the canvas is slow anyway. What we're doing is grabbing the entire canvas and loading it into an image, which can take several frames. If you called drawgl directly you'd just be making the runtime draw something it would draw anyway.

  • CreativeMind

    None to my knowledge, but I only use HTML export. However there shouldn't be since it's just math an JavaScript and JavaScript should ru the same everywhere.

  • How far have you got it? The cvs is just a file. You can use the AJAX object to get it into a text variable. You can then use the tokenat expression it get indavidual values from it.

  • Are you saying it is, or are you asking how?

  • I think the answer is in c2's runtime with it's capture action. It doesn't grab the canvas right there, instead it grabs it later (I think it's right after the next redraw).

    I was fiddling with that with the paster plugin before and you have some places in the plugin that's run at different times.

    Two that come to mind are the tick() and tick2() functions. I forget if there are others. One is run before the event sheet and one is done after. You do have to tell the runtime to call those functions with I think a tickme() call? Searching for tick2 probably would give a post with more info as I recall, as well as any I'm fogetting here. Anyways my guess is in those places might be better times to grab the canvas, but it's kind of test and see.

    Basically the process would be to set a Boolean with your action and in the tick function it would check if the Boolean is set and then do what your action does currently.

    The idea can probably be more definite, you just need to break down what the runtime is doing. Off hand I think it looks something like this? I'd have to verify where the capture is done.

    Tick()

    Events

    Tick2()

    Capture canvas

    Draw

    Repeat

  • One thing I didn't cover was in the action right before the callback you see the line:

    var self=this;

    Then inside the callback self is used instead of this. The reason for that is "this" is the object instance inside the action, but when the onload function is called "this" is instead the global variable space because the function is called without a object. You can find more information by googling "JavaScript this".

    Anyways that just means to just use self instead of this everywhere inside the onload function. If you used "this" instead it would explain why the instance variables aren't being changed.

  • ye7yakh

    Is the canvas size the same as the image size? If they're not that could explain the slightly off white next to the black from resizing I suppose.

  • In js as soon as you give a URL to img.src the image will be loaded asycronously and when it finishes it calls the function at img.onload. It's an html thing.

    Yeah you'd probably want to want to wait till the image load trigger to draw it to the canvas.

    It should work fine getting a 2d context because it's using the new canvas created right above it.

    The preserveDrawingBuffer setting is slower when it's on which is why it typically is off. The fact readpixels worked once with that flag off probably has to do with undefined behavior since it's not supposed to work when the flag is false. As far as I can tell, you can only set that flag when first getting the context, aka when the runtime creates it. But ya it's not really acceptable for a user to have to make that change when using such a plugin. :p

    If the image URL idea isn't working paste the code for that function and the trigger it calls. The events should look like this:

    On click

    --- get pixel at X,y

    On pixel got

    --- set redvar to pixel.red

  • I thought it was generated and run at the start of the game. It might still happen when the first script is run though, I'm not sure.

  • If the python files are outside the exe you can just ship the pyc fies generated instead of the py ones. The slowdown is from Construct generating the script to bind objects with python, then of course python also parsing and running it. I don't think it can be improved since the length of the script is proportionate to the number of objects. Unfortunately it can only be made when the game runs, and can't be pre-compiled.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 99Instances2Go

    I can't visualize the idea. It seems kind of non-intuitive. I'd have to see it in action.

  • ye7yakh

    I only use pc, but there must be some subtle scaling going on. Maybe try setting "full screen scaling" to "low quality", or using point sampling.

  • I found a pc to test webgl on, and it seems that you can't get both a webgl and 2d context on the same canvas. That explains why my code doesn't work.

    You can still save the entire canvas. Ex:

    var canvas = document.getElementById( 'c2canvas' );

    canvas.toDataURL("image/png")

    or

    canvas.toDataURL("image/jpeg", 0.75)

    That is all the runtime is doing, except it waits till after everything is drawn for that frame.

    From a plugin you can get the canvas with:

    this.runtime.canvas

    instead of

    document.getElementById( 'c2canvas' );

    So the process to get the color of a pixel that also works with webgl would be

    var img = new Image();
    var self = this;
    
    img.onload = function ()
    {
    	var canvas = document.createElement('canvas');
    	canvas.width = img.width;
    	canvas.height = img.height;
    	var ctx = canvas.getContext('2d');
    	ctx.drawImage(img,0,0);
    	var pixel = ctx.getImageData( x , y , 1 , 1 );
    	
    	// save the value in the plugin and call a trigger to use the color in your program
    	self.redvalue=pixel.data[ 0 ];
    	self.runtime.trigger(cr.plugins_.Sprite.prototype.cnds.OnURLLoaded, self);
    }
    
    img["crossOrigin"] = "anonymous";
    img.src = this.runtime.canvas.toDataURL("image/png")[/code:15nrlz3e]
    It's referenced from the loadUrl sprite action.
    
    Basically load toDataUrl to a image.  This is asynchronous so we need a callback when it finishes.  When it's done loading we can then create a canvas, draw the image to it and retrieve a pixel with a 2d context.  Then we save the pixel to a variable we can access from an expression and call a event sheet trigger.
    
    Whew, that's not exactly straightforward.  When webgl is off a pixel can be retrieved in place with the code in your op.
    
    Now to go the webgl route instead there's a nifty readpixels function so supposedly it's as simple as this:
    [url=https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/readPixels]https://developer.mozilla.org/en-US/doc ... readPixels[/url]
    [code:15nrlz3e]var canvas=document.getElementById('c2canvas');
    var gl=canvas.c2runtime.gl;
    var pixel = new Uint8Array(4);
    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
    pixel[0];[/code:15nrlz3e]
    which works only on frame 1 it seems. I don't know why, and my google fu hasn't been helped me yet.  But that could be a start.
    
    Edit:
    Here's the proper solution:
    [url=https://asalga.wordpress.com/2011/08/01/using-webgl-readpixels-turn-on-preservedrawingbuffer/]https://asalga.wordpress.com/2011/08/01 ... ingbuffer/[/url]
    But that requires modifying the runtime in preview.js.
  • Ashely

    I'd agree there about it being more like a programming language, which doesn't necessarily make it harder for a beginner. It's kind of more event sheet inspired at this point.

    The "filter" condition would act just like the "pick by comparison" condition of c2, it could be called "pick" as well but for now I'm leaving it for now. The idea for "sol" is it would be a more advanced feature to allow some additional control. Without it things would operate the same as most of C2's events already do.