R0J0hound's Recent Forum Activity

  • Here's a rough reference on loading and saving binary files. Untested but it has the relavant sources. In the examples i skipped over some more robust error checking and cross browser compatability.

    Ajax way

    https://developer.mozilla.org/en-US/doc ... ng_Started

    https://developer.mozilla.org/en-US/doc ... rrayBuffer

    https://stackoverflow.com/questions/234 ... -a-browser

    xhttp = new XMLHttpRequest();
    xhttp.responseType = 'arraybuffer';  //default is text
    xhttp.open('GET', 'old.eps');
    xhttp.onreadystatechange = function()
    {
    	if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) 
    	{
    		var byteview = new Int8Array(xhttp.response);
    		// do stuff. view is an array of bytes.
    		
    		saveByteArray([byteview], 'new.eps');  // from the third link above
    	}
    }
    xhttp.send();
    [/code:1w600qbz]
    
    nwjs way
    [url=https://nodejs.org/api/fs.html]https://nodejs.org/api/fs.html[/url]
    [url=https://nodejs.org/api/buffer.html#buffer_class_buffer]https://nodejs.org/api/buffer.html#buffer_class_buffer[/url]
    
    [code:1w600qbz]
    fs = require('fs');
    
    fs.readFile('test.eps', (err, data) => {
    	if (err)
    		throw err;
    	// do something with data.  data is an array of bytes
    	fs.writeFile('test_modified.eps', data, (err) => {
    		if (err) 
    			throw err;
    	});
    });
    [/code:1w600qbz]
    
    As for the eps file format itself i found this:
    [url=http://www.fileformat.info/format/eps/egff.htm#EPSF-DMYID.2]http://www.fileformat.info/format/eps/e ... SF-DMYID.2[/url]
    an eps file can either be all text or start with a binary header showing where things are in the file: the text ps portion, and a wmf and tiff portion which is a simple thumbnail of what the image looks like.
    
    I'm guessing the metadata you want to add would be lines that start with "%".  So you could look at the header, get that portion of the file (which is all text) and add additional lines in.  Looks like they would have to be after the initial % line as that has special meaning, also the text would have to jeust be ascii per the spec it look like.  Then before saving the file you'd have to redo the header with the new sizes and offsets of everything.  So you'd probably have to create an entirely new buffer to save to.  Seems kind of low level but the links about buffers should be an acceptable reference.
    
    Anyways perhaps some of that is useful.  I'll be sure to use it as a reference later regardless.
    
    Edit: i suppose i did skip the part on how this can be used.  Typically it would be done in a plugin or with some clever usage of the browser execjs action.  Debugging with either has a learning curve but it can be done.
  • This seems to work well:

    Set scale to 0.5*OriginalWindowWidth/min(min(camera.X, layoutwidth-camera.X), min(camera.y, layoutheight-camera.y)*OriginalWindowWidth/OriginalWindowHeight)

    min(camera.X, layoutwidth-camera.X)

    and

    min(camera.y, layoutheight-camera.y)

    are the closest x and y distances to the edge of the layout

    using the aspect ratio I can then convert the y distance to a x distance:

    y*OriginalWindowWidth/OriginalWindowHeight

    So now there are two x distances, and we can get the smaller one with another min.

    min(x, y*aspectratio)

    and to convert the x distance to a scale we multiply by 2 and divide by the window width:

    2*xdist/originalWindowWidth

    As an additional idea you can also limit the zoom if it gets much too close near edges.

    min(scale, 4)

    or whatever max scale you want.

  • I don't use nwjs, but I tried loading a binary file with ajax and saving it with the browser object. The file doesn't load. It looks like saving and loading as text will not work. Nwjs saves and loads as text as well.

    To save and load as binary will require an entirely new plugin to do so or to use javascript to do it in the browser execjs action. There's a fair amount of stuff to look up to do that.

    But then if you get past that, there's the matter of modifying the file in a way that doesn't break it. It depends on how the file format is laid out.

  • It’s a bad idea to add data to a file like that. It would

    Break it. The write file feature focuses on text files but that’s not the issue. Basically you need to know or have a JavaScript library know how the data is stored in the files. And even then many formats don’t allow you to add unrelated data in it.

    Here’s a different idea. You could create your own file in the folder and store the extra data there.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I’ve done x0 for first, and x1 for last. Or xi for initial x and xf for final x.

    I’ve used x0 from previous, x1 for current and x2 for next as well.

  • The chipmunk physics behavior is another way. You just specify the uid of the other object to connect to with it.

  • You have your on function events and then events right after that. Those right after aren’t part of the function event, so they will run as normal. So it’s not a case of the function triggering, it’s just events running as normal.

    If those events were sub-events I’d the function then they would be part of the function and wouldn’t run without the function being called.

  • Had a quick look. I can't open the capx because it uses plugins i don't have and likely will never install. Anyways looked in the event sheet xmls. You have functions that do some things but you also have events that will run that aren't part of the functions. Are you sure it's not just those events that are running and making you think it's the functions?

  • Post the capx, and i'll narrow it down if it's a bug. Disable actions don't run, if the functions run, then they must be called from somewhere. I can't guess anything from a screenshot of events.

  • That shouldn’t happen. If you’re sure you’re not calling the functions, then I guess it may be a bug. All I can say is I’ve used functions a lot and they only run when I call them.

  • It’s a computer thing. In base 10 numbers it adds up to 1, but in base 2 the number 0.1 can’t be perfectly represented. It’s actually a tiny bit smaller and after adding it 10 times The error is a bit bigger.

    Anyways you can read more about it by looking up floating point numbers on Wikipedia. You don’t see it in some software because when they display numbers they use less decimal digits so it rounds to 1, at least when it’s displayed. When dealing with decimals in general there is a small amount of approximation so you can’t expect numbers to be exact values.

    Anyways, rounding the number is one solution, as you have done. Another is to just add 1 every time and divide by 10 when you want to use the value.

    A third, albeit needlessly elaborate solution would be to do all the math in a base 10 way and store a decimal as two integers.

  • Say n is the number you want to display

    int(n)&”.”&zeropad(int(n*1000)%1000, 3)

R0J0hound's avatar

R0J0hound

Member since 15 Jun, 2009

Twitter
R0J0hound has 157 followers

Connect with R0J0hound