R0J0hound's Forum Posts

  • C2 uses degrees instead of radians so t should be 360*random(). With 2pi it would only be about 6 degrees which is what your first pic looks like.

  • Ah, I misunderstood. So if it only happens in the debugger I'd say that can be expected since the debugger does more stuff such as displaying all the values in the array.

  • If you're loading the array once, you'd at most get a pause depending how big the array is. If it's impacting the fps then that sounds like you're loading the array every tick.

  • jojoe

    % gives you the remainder after a division.

    Ex

    5%5=0

    4%5=4

    15%5=0

    33%5=3

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • While it never is 1 exactly, it can be pretty close. ex: 0.99999999999 which is practically 1.

    Do you have a use case in mind? I've only ever needed 1 included if the number was an integer.

  • Tokinsom

    C2's webgl renderer looks like it was updated to have more parameters for effects. Looking at that particular line it looks like time is now passed to the effects.

    Looking at line 408 in paster/runtime.js

    glw.setProgramParameters(this.temp_texture, 	// backTex
    	 1.0 / inst.width,		// pixelWidth
    	 1.0 / inst.height,		// pixelHeight
    	 0, 1, 					// destStartX, destStartY,
    	 1, 0,					// destEndX, destEndY,
    	 1,						// this.getScale(),
    	 0,						// this.getAngle(),
    	 0, 0,					// this.viewLeft, this.viewTop,
    	 0.5, 0.5,				// (this.viewLeft + this.viewRight) / 2, (this.viewTop + this.viewBottom) / 2,
    	 inst.effect_params[etindex]);[/code:3p0kd6dd]
    
    Add this line: "this.runtime.kahanTime.sum,"
    [code:3p0kd6dd]glw.setProgramParameters(this.temp_texture, 	// backTex
    	 1.0 / inst.width,		// pixelWidth
    	 1.0 / inst.height,		// pixelHeight
    	 0, 1, 					// destStartX, destStartY,
    	 1, 0,					// destEndX, destEndY,
    	 1,						// this.getScale(),
    	 0,						// this.getAngle(),
    	 0, 0,					// this.viewLeft, this.viewTop,
    	 0.5, 0.5,				// (this.viewLeft + this.viewRight) / 2, (this.viewTop + this.viewBottom) / 2,
    	 this.runtime.kahanTime.sum,
    	 inst.effect_params[etindex]);[/code:3p0kd6dd]
    And that should fix it.  I can't test, webgl no longer works on my pc.
  • I've seen it, even installed and messed with it a little. I never made anything with it though.

    It's the only python game library that can make mobile games last I checked. Their docs have steps to do the exports and it comes with examples so I'd say export an example and see how it performs.

  • The canvas or paster plugins are helpful for this.

    The canvas plugin can make things easier due to it's "paste layer" action, but pasting things like tilemaps will cause an error if webgl is on. Actually the performance is much better when using the canvas object if webgl is off.

    The paster plugin could be used as well. It was written to utilize webgl more efficiently than canvas, and it allows pasting objects with effects applied (at least mostly). One drawback is it doesn't have a "paste layer" action, so you'll have to paste objects individually.

    With either object pasting tilemaps and particles is a problem since those objects for efficiency only draw what is on screen. The post here has a solution for both that may help.

  • Glad you found it interesting.

    Here are some older examples that use various mod playing libraries. The loading could be simplified, but it deals with multiple js libraries that need to be loaded in order.

    Also on the topic of hacks, here is a benchmark I did with a hack to replace a sprite's texture with a html5 canvas.

    It requires webgl to be off, then you create a sprite and directly after run this js:

    "window.canvas=document.createElement('canvas');
    this.runtime.createRow[0].curFrame.texture_img = canvas;"[/code:1td1srg5]
    After that the js variable "canvas" can be used with html5 canvas drawing you like.
  • Yeah, just making it faster changes where the ball would go and how much it bounces. It wouldn't match the path the ball would actually follow.

    Here's a way to predict where the ball would go, including bounces. The drawback is it doesn't work with the physics behavior, instead I just used a js physics library so I could do many simulation steps at once. The second issue is that's all I made it do. For a complete game it would need to switch between predicting the path and actually moving.

  • Prominent

    I started a topic here about a way to use a third party library without writing a plugin:

    There are pros and cons of doing it that way. A pro is you can access everything a library has to offer instead of going through a wrapper that may not allow everything. A con is you're limited to what you can access from events.

    Actually making a plugin is similar, but you have to design the ACE's in a way that's usable for C2.

  • Sometimes it's nice to be able to just try out using some JavaScript library in your project without going through the steps to create a plugin and behavior. I could be you just want to experiment, or you're just not familiar enough with the library to design a add-on in a good way. Here's a way you can do that.

    The basic process is:

    1. add the JavaScript library to the "files" folder of your project. Or just get a url to the library.

    2. Load the library. It's similar to using ajax in that the file can take time to load, and it must be loaded before you can use it.

    Using the browser object, run this javascript at the start of layout to load a library. In this case "p2.min.js".

    "var js = document.createElement('script');
    js.type = 'text/javascript'; 
    js.src = 'p2.min.js';
    document.body.appendChild(js);
    window.libraryLoaded = false;
    js.onreadystatechange = js.onload = function()
    {
    libraryLoaded=true;
    };"[/code:1spjps9k]
    When it's loaded it will set the javascript variable "libraryLoaded" to true.
    
    3. Once the library is loaded you can pretty much use it like the documentation of the library.  Keep in mind that without the sdk we're limited what we can access, so we can only communicate numbers and strings back and forth.
    
    On a side note it is possible to access more but it is considered very hacky and will break if you export minified.  Still it could be useful in some cases to try out an idea for a plugin.
    
    [h2]Example[/h2]
    Here's an example to implement a physics library so that we can do something that's not possible to do with the physics behavior or even my chipmunk behavior: [b]Draw the path an object will follow, including it's bounces off obstacles.[/b]  Basically it requires doing multiple simulation steps at a time, which would require significant changes to the existing behaviors to do.
    
    So first we pick a library.  I picked this one which has pretty good documentation:
    [url=https://github.com/schteppe/p2.js]https://github.com/schteppe/p2.js[/url]
    
    And here's the example capx:
    [url=https://www.dropbox.com/s/j76abx1fu5l91mb/js_p2_physics.capx?dl=1]https://www.dropbox.com/s/j76abx1fu5l91 ... .capx?dl=1[/url]
    /examples30/js_p2_physics.capx
    It's pretty basic and only does what we need and doesn't do much else.
    
    One quick note in the capx you'll see js like this:  "window.foo = value;" instead of "var foo=value;".  The reason is "window.foo" makes a global variable and "var" can't be accessed in another execJs action.  Both can be accessed with "foo" elsewhere.
    
    I won't cover what I did exactly, you can look at the capx for that, but I basically just followed the examples for p2.js.
    Part of it is we need to pass object locations to js. To do that just use "&" to make the text with values:
    "window.c2pos = ["& ball.X &","& ball.Y &"]"
    Instead of typing the values directly:
    "window.c2pos = [100,50]"
    
    And that's basically it to pass values to js.  The other way, js to C2, can be done with the Browser.execJS() expression.
    
    [h2]Debugging[/h2]
    By using JavaScript you no longer have the luxury of C2 verifying what you typed was correct.  You'll likely make typos when you're writing it so you'll want to have the browser's javascript console open to see errors.  The shortcut for chrome is shirt+ctrl+c.
    
    [h2]Limitations[/h2]
    As stated before without the sdk you're limited what you can access.  For something like physics one big one is you can't access an object's collision polygon.  For stuff that should draw stuff in your game you have to use the sdk, because the runtime chooses when to draw.
  • Yeah, i'd use a family to handle two instances of the same type.

  • Prominent

    It only doesn't work for joints that were just added in a post collide. It has to do with chipmunk not allowing anything to be added or removed during a pre or post collide, so instead the plugin delays it slightly. The unfortunate drawback is it causes a lot of bugs related to stuff just added in those triggers.

    I don't have a simple fix for it, so it's an open issue for now.

  • Collisions would basically mean re-creating the physics behavior with events to be able to step the physics multiple times. Which isn't ideal at all. The way peggle probably did it was leverage the physics engine itself to do many simulation steps at once to instantly trace a path. C2's physics behavior only steps automatically per frame. It's not possible to step it manually.

    For now you could get away with continuously launching balls to trace the path. It wouldn't be instant but it would show the path.