R0J0hound's Forum Posts

  • That would have to be done inside the plugin, and that’s what save/load actually does. However, no, there’s nothing implemented on that front.

    You can use the canvas.asjson expression to get some json that can be loaded into the array object, but it’s not reversible.

  • I think you mean imagepoint? All objects have an origin and I didn’t think you could rename it.

    If you just access an imagepoint x or y with an expression and if it’s equal to 0 the will mean it doesn’t exist. Usually at least, if you have the sprite near the top left edges of the layout the imagepoint could have zero coordinates. In that case you’d want to move the sprite to a location far away first, then after your check move it back.

  • To mirror around the center of the screen:

    scrollx-(mouse.x-scrollx)

    I've also used

    640-mouse.x

    Where 640 is the screen width, and the you don't do any scrolling.

  • Here's another idea too. The crux is a compare like the following to see if any of the text matches what was typed.

    compare textbox.text = left(text.text, len(textbox.text))

    dropbox.com/s/55xlnwskmv7dy0d/search_system_test.capx

    And then I realized some simplifications:

    dropbox.com/s/9gwsv0q7yugzv1c/search_system_test_2.capx

  • Worst case you can use canvas.imageUrl to get a save of the canvas image. Then to load it you’d take a sprite at the same position as the canvas, load the imageUrl into an animation frame of the sprite, set the sprite size to the same size as the canvas, clear the canvas, and finally paste the sprite into the canvas.

    On a side note the plugin did save/load the image at some point. It possibly could have been disabled in code since it was slow, but I don’t recall. I don’t use the plugin anymore and have ceased any development on the plugin itself to fix issues that crop up.

    I am happy to try to help with usage questions when I can. Probably not with examples, since I don’t have it installed, but maybe I can help point you in the right direction.

  • I agree, the shunting yard algorithm, and reverse polish notation wouldn't be suitable for anything beyond expressions. I've found recursive decent to be awkward and abstract when dealing with precedence, could be just me though. I'm not sure what class of parser I currently utilize falls under but if I wanted to generate a ast I've used the following which I'll drop for reference. It looks similar to the shunting yard algo.

    en.wikipedia.org/wiki/Operator-precedence_parser

    There are pros and cons to different methods for sure. A lot comes down to personal preference. The method I used seems to make it fairly easy to change up the syntax rules and add stuff. Here i added some math functions and 2d vector types to the expression. Along with type checking, but the error messages could be nicer.

    dropbox.com/s/paqwch9pke1pvms/parser_test5_with_vec.capx

  • Parsing is a matter of converting text to a list of tokens, and verifying there were no syntax errors. Actually I've found the error checking to be the more involved part.

    Anyways here's my two cents on top of what has been mentioned. I'd go this route:

    1. Convert text to a list of tokens. Basically numbers and operators (+-*/).

    2. Convert the list of tokens from infix notation to reverse polish notation (RPN) using:

    en.wikipedia.org/wiki/Shunting-yard_algorithm

    That will eliminate the parenthesis and make it much simpler to calculate the result. An expression tree is another option but the code to do so in Construct will be more involved.

    3. Evaluate the RPN expression to get the result.

    Here's the current way I've gone about it. 61 fairly organized events although I can see shaving that down further. Handles decimal numbers, the five math operations (+-*/^), parenthesis and negation.

    dropbox.com/s/f7lzeykvp98j1mw/parser_test3.capx

    Older stuff:

    106 events. Same capabilities as the one above. The approach is fairly different. Error checking is done by looking at neighboring tokens to see if it makes sense.

    dropbox.com/s/36fg2ook2g0850o/parser.capx

    70 events with a similar error checking method. Doesn't have ^ but it lets you write expressions like you do on paper with some variables. ex: 2(3), 4x+5y, etc...

    dropbox.com/s/29i3dv40hk4ll1b/simpleEval.capx

    You can also just use the browser.execjs() expression to evaluate the expression. The main disadvantage of that is the user can run any js with it. Not really an ideal situation. You could use a complicated regex expression to verify it only contains stuff you want, or maybe there's other approaches. The second disadvantage is you lose the ability to show good error messages if a bad expression is written.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry for the late reply. I can’t say what’s amiss. I have the bad habit lately of not verifying my ideas work correctly. I just haven’t had time to test or debug anything.

    I don’t think I’m much help very often on here anymore. The issue could be with how the conversions are applied, or maybe the conversions are off, or could be the top of my head math and logic are flawed. I’ve buried myself to solve all that and I’m not able to work though it at this time.

  • No idea what topic it was.

    As a quick idea you can loop over all the tile positions, place a square sprite on the tile, and then check for an overlap between that sprite and the other object. If it overlaps, then the current tile is touching the object.

  • Here’s the math for it where dist is the distance to move before stopping and f is the braking force.

    Global number f = -200

    Global number dist = 2000

    Start of layout

    — apply impulse self.mass*sqrt(-2*dist*f/self.mass)

    Velocityx > 0

    — apply force f

    Anyways that would work fairly well. However the units are off with the physics behavior. Here is the info on how to convert the units so the formulas above would work.

    construct.net/en/forum/construct-2/general-discussion-17/math-physics-83966

    As a personal view I find it annoying to convert even though I found the conversions. It’s often simpler to just not use the physics behavior.

    For instance if you used the bullet behavior instead you could set the acceleration to -200 and set the initial velocity to sqrt(-2*dist*-200) and get the same result.

  • I stumbled upon this cool tweet here:

    twitter.com/3blue1brown/status/1145344403210289155

    It's a way to draw shapes with just rotating vectors, or just basically sine waves.

    Here's my initial test. It will scribble random pictures again and again. Nothing too interesting but I found it fun to watch.

    dropbox.com/s/hryifbtpsgdskhm/scribble.capx

    Second go utilizing a user made path. Use the mouse to draw a new path while it runs.

    dropbox.com/s/ruzajg48xq1qb6n/scribble2.capx

    The cool thing about this is it can be easily used to approximate a path with less data points and still be smooth.

    At the very least it is entertaining and actually has a sketchy look to it.

  • Here is an update with rotations, contact point calculations and friction. Although the friction model seems to not be working because when objects are pushed apart it causes sliding. Maybe next time I'll go deeper down the physics rabbit hole.

    dropbox.com/s/fssu2ujynyj3zia/simple_event_based_physics.capx

  • Glad it works! I always thought it was a cool equation.

    There are a few ways to improve it later.

    For one I just used the angle from one object to the other for the collision normal. Realistically it should be the angle from one contact surface to the other.

    The other thing you can do is actually calculate the point or points of collision and then adding the rotational motion stuff.

  • Here’s the actual math to do it. Equation 5 to calculate the impulse and 1a,1b to set the new speeds.

    en.m.wikipedia.org/wiki/Collision_response

    You don’t have to do the angular stuff so it can be simpler.

    Sprite collides with other

    Set a to angle(sprite.x,sprite.y,other.x,other.y)

    set j to -(1+e)*((other.vx-sprite.vx)*cos(a)+(other.vy-sprite.vy)*sin(a))/(1/Sprite.mass+1/other.mass)

    Sprite: set vx to self.vx-j/self.mass*cos(a)

    Sprite: set vy to self.-j/self.mass*sin(a)

    Other: set vx to self.vx+j/self.mass*cos(a)

    Other: set vy to self.vy+j/self.mass*sin(a)

    That’s with three variables

    a = the angle from sprite to other

    e = bounce amount. 0 to 1 range

    j = the impulse

    Also I used vx and vy for the velocities. You can get that from angle and speed with:

    Vx=speed*cos(angle)

    Vy=speed*sin(angle)

    And vice versa

    Speed = distance(0,0,vx,vy)

    Angle = angle(0,0,vx,vy)

    Anyways hope that helps.

  • Hi, here are some further thoughts and experiments.

    Road types and intersections:

    It's probably simpler to use uniform width roads initially anyway. Here is one hack attempt to do the roads with edges and center dashed line. The dashed lines could be made to go to the center of intersections by using another object with this setup, although i realize that's not how intersections look. Any look can probably be achieved with some thought. doing the drawing with polygons could be a cleaner idea possibly.

    dropbox.com/s/kpdxx2xge14fztx/road_gen.capx

    Different levels would probably be easier with 3d polygons, but those don't really exist in construct. I see you did a layering+zelevation way of doing it in your other posts though.

    Also, by drawing roads in game, i meant it as an idea to make a dev tool in your game to make placing and designing roads easier for yourself. They could be used for the player to utilize later i suppose, but primarily it would be so you wouldn't have to do it all in construct's editor.

    Finally here are some tests about dealing with a large amount of roads. I wasn't going to design all that but i did find that i could get real road layouts with Open Street Map. It lets you export an osm file of the current view. It's just xml inside, and i could convert the relevant parts to something i could parse in construct easier.

    dropbox.com/s/rxus2szbpsfzlrv/loader_and_plot.capx

    That's clearly a lot of sprites to draw, so I scaled it up and did an initial first pass at splitting the map into grid chunks, and only drawing the chunk the player is on. Normally the transition would be seamless, but it was only a rough test. I wonder though if Construct's built in hashing would be acceptable enough.

    dropbox.com/s/bya1jhzdtkrrufo/loader_and_plot_gridhash.capx

    Anyways i thought those capx were fun to share. I do think i missed the mark in making something completely useful. Hopefully it's helpful or interesting.