R0J0hound's Forum Posts

  • 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.

  • Try Construct 3

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

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

    You can improve the rendering speed of the tilemaps by setting "seamless mode" to off in the tilemap properties.

    In addition to that set "pixel rounding" to on and "fullscreen scaling" to low quality.

    Here's the latest of my capx that saves chunks that were modified.

    https://dl.dropboxusercontent.com/u/542 ... lemap.capx

  • Using the "is within angle" should do it.

    Angle(player.x, player.y, object.x, object.y is within 90 degrees of player.angle

    ---- (object is in front)

    Else

    --- (object is behind)

    That's for one player and one object. To work with multiple of each, add a "for each" player and object condition and put the events above as sub-events.

  • There's an example here that draws the path of the object.

    It doesn't do collisions though.

  • Prominent

    That should work. I'll have to look at it tomorrow to see why it doesn't.

  • Glad it was useful. I'll take a look at what your capx tomorrow.

    I thought of a simple way to save changes to the array.

    Basically just change the tiles on the tilemap like normal, but when you do, set a Boolean variable to save that tilemap.

    When that Boolean is set and before moving a tilemap that moved off screen, store that tilemap in a dictionary object.

    With this key

    X&" "y

    And this value:

    Tilemap.asjson

    Then after moving check if the current tilemap position is in the dictionary. If it is, load that json. If it isn't call update.

    That way only tilemaps that are changed are saved.

    Enemies could be tricky if they're off screen since they would no longer have a tilemap to interact with. Two ways around that come to mind. One would be to put the object to sleep if offscreen. Another would be to maintain some tilemaps around the enemies, however this could prove complex.

  • Ok, here's the result:

    https://dl.dropboxusercontent.com/u/542 ... lemap.capx

    Probably should have called it spelunking turtle.

    I set it up with 64x64 tilemaps with 4x4 tile size and it works decently. I get about 30fps on my machine, so I assume most others will get a higher fps. I briefly tried 128x128 tiles but it seemed to stall a bit more. Also I had some more fun with perlin noise in this one. I found you can combine it in various ways to create some interesting terrain.

    It can be made faster I think if I use some javascript to do what the update function does, and create a json that can be loaded into the tilemap. But for now it's decent.

  • You may be able to work around that by resizing the sprites first so they overlap before that check. Then afterwards resizing them back.

    Or you could move the imagepoints a bit further off the collision polygon.

  • What could be done is a chunk based approach so the tilemap could be used. The idea would be to do the same as my example but use multiple tilemap objects that you move around and update the tiles in them when they're moved around.

    I'll try to give that a go tomorrow, it sounds promising.

    The next problem to consider is a way to keep track of terrain changes if you want to be able to add/remove tiles as the game runs.

  • Using a tilemap for this could be tricky and may not give any gains since it looks like you'd have to update the whole tilemap every time you scroll. I'll have to think about it some more though.

    Scrolling in other directions will only take one event a piece, and will look much like the one to scroll right. I'm away from my PC atm.

    Only the randomize seed action sets the state. The perlin2 expression will always give the same value for an xy if the seed is the same.