R0J0hound's Recent Forum Activity

  • If you want to do that in the editor you can select the objects, right click on that, and select wrap selection (shortcut key is return I think).

    If you want to do it when running the game you can do this:

    Global number scale=0.5

    Global number centerx=320

    Global number centery=240

    Start of layout

    — sprite: set x to (self.x-centerx)*scale +centerx

    — sprite: set y to (self.y-centery)*scale +centery

    — sprite: set width to self.width*scale

    — sprite: set height to self.height*scale

    That will scale around any center instead of just the object centers.

    To have actual resize handles at runtime is a bit more involved. There is a resize handle example you should be able to find with the search I think.

  • A couple ideas come to mind. One is to dynamically create some extra walls to help to box fall into the hole. Another is to check if there’s a hole below a box and have it shift a bit to align with it to drop in.

    The second idea seems a bit simpler to do. If everything is aligned on a grid then it’s a bit easier. So say the blocks are 32x32 and the ground is a grid of those boxes. I’m also assuming the boxes have their origin centered. You can calculate the closest grid position the box is on with:

    gridx=int((box.X-16)/32) *32+16

    gridy=int((box.y-16)/32) *32+16

    Then to see if there’s a hole below it check the point (gridx, gridy+32) to see if it’s overlapping anything.

    If it’s not you can then check if the x difference is close enough to make it shift into the hole. Here it would move into place if it was within 4 pixels.

    Compare Gridx > box.x

    Compare gridx-box.x <4

    — set x to min(box.x+1, gridx)

    Compare gridx<box.x

    Compare box.x-gridx <4

    — set x to max(box.x-1, gridx)

  • Ah ok. Seems like image tracing is what you want to do. Carry on.

    beguinner

    It's black because reading pixels with the canvas plugin takes so long. Give it a little bit.

    dop2000

    I made this a while back, It's much faster at reading the pixels, and avoids using the canvas plugin. It can't get the image from a sprite though.

    uc04737fbcd2641633d944283136.dl.dropboxusercontent.com/cd/0/get/Ch8d00sk6Ls_paUyffNCpG0jYZNrSa2OduWxBH_GOPOJoHEzsYU-h86kglgrlNjvwiGJxz24oPhwpTIOsQm2h0KieHGPtQid9aQux7VehZ6ZjuGH5ibRMPU-JfBDLfUxzRA/file

    Even faster would be to save the tilemap to a file and load that later. At least as far as loading times go.

  • Well, cosp() is just a sine wave under the hood which is hard to adjust like that. It's probably too much math than what it's worth to find the polynomial that fits that curve, and while utilizing multiple bezier curves could work too it would still require some math solving.

    You could do a more visual method. I loaded your graph image as a sprite, and put the origin to the top left axis. Then turning on a 16x16 grid in the editor i added a 16x16 square sprite with the origin at the bottom left. I then placed copies one by one left to right over your graph image. The final step was to turn off the grid and resize the squares so the bottom left is on the curve on the image. Actually it worked out great since you seemed to use a 16x16 grid. An viola, we have manually defined the curve.

    ucadad69d41a2a8e283899ab16bc.dl.dropboxusercontent.com/cd/0/get/CiBy8OciM07g7dbszDSLSY01vWG3UGv1bjrGSl1i3JaKqodl-ILtBnvVxQyitqWTmkphXH2o1Uw_RSprL7T_urcY8xA0zlFCxu-q945iAUii24-jw5n0hHC6f6y5aEk12cI/file

    There are probably simplifications of this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I guess I’m having trouble following what is being asked.

    The op asks how to cover one object with another and the latest solution looks to be tracing the image of the red object to create a tilemap for collisions.

    Visually all that would change by covering one object by the other would be color. I’d think a different colored animation frame, or a color effect, or even a blend mode would work fine.

    If you do actually want that area replicated with blue rectangles, and that area is already made up of rectangles. Then you could also create a blue sprite for each red one and set the size and position to be the same.

    Any of those would be cheap instead of looping over the pixels to create a tilemap.

    In short I guess I’d want more details of what you want to do. You have a simple example, how about a deluxe one too. It would prolly better show what you want.

  • The simplest would be a condition to see if the variable is less than 5.

    Global number var=0

    On click

    Var < 5

    — add 1 to var

    If you want something more deluxe like being able to increase the var by other means then you’ll have to use another var as well.

    Global number var=0

    Global number clickcount=0

    Global number keypresscount=0

    On click

    Clickcount < 5

    — add 1 to var

    — add 1 to clickcount

    On key press

    Keypresscount < 5

    — add 1 to var

    — add 1 to keypresscount

  • Temp =cosp(low, high, month*2/12)

    Should do it if month is 1-12

  • Very cool tweak!

  • Arrays aren't always needed, but they can be useful if you want to keep track of a bunch of numbers. In this case I used it to keep track of the two end positions of a bunch of line segments. Most of the cool stuff is from math and logic.

    Anyways, I found a simpler way without much of the math stuff that works with colored bubbles. It uses the paster third party plugin. Basically it uses the "destination out" blend mode to slice off parts of the circles. You could do it without the paster plugin if you had a layer per bubble, but that would be harder to work with. Paster lets you draw to a image so you can use it for more complicated layer composition stuff.

    ucb6ec2ce00b10ba0e311e6f3347.dl.dropboxusercontent.com/cd/0/get/Ch7-jWW4O6GKgirUnAxRpBCHsQR9zmGHoqUQ_yYS6ZxL8CL1WYmKlHoA8RgTgEBhfwWmSF5f2Urco3HpX77zRFD1ILLwVSpttIgyvhDGqWhGKe98xdzny2kbwGQgutVe3vM/file

    Edit:

    It may be satisfactory as is, but some more work is needed to make clicking select the correct bubble. AKA we'd want to do out own collision detection.

    The more I fiddle with ideas, the more impressive the game in the op's video is. They clearly put a lot of work into it.

    Edit2:

    I tried adding an effect to make a the bubbles more soft, but eh, it doesn't look great.

    I'm more convinced a the bubble would look better with soft body physics instead of rigid. A simple way could be to make a bubble out of multiple smaller rigid bodies connected with springs and some forces to keep them from collapsing on themselves. Then we'd stretch the bubble over that so it looks distorted. The paster plugin's draw quad action could help with that. The bubble intersection logic would have to be reworked again though.

    It may be enough to just make the collision solver more spongy though. I guess that's the advantage of rolling our own physics, we can tweak stuff like that.

    Here are some older topics about soft body physics for possible reference.

    construct.net/en/forum/construct-2/how-do-i-18/bouncy-jelly-effect-43593

    construct.net/en/forum/construct-2/how-do-i-18/how-do-i-jelly-floor-from-the-85899

  • One idea is to make the collision polygon slightly smaller in the image editor.

    The crop button adds a transparent line of pixels around the image. So that would create a gap if the colored pixels went to the edge of the image before.

    The physics engine also adds a small gap between objects called “slop” that increases stability. We don’t have access to tweak that though.

  • Here's a test. Basically physics with a collision radius smaller than the circle and some code to calculate the edges in between for a visual. Physics was done from scratch but the behavior could be used. For that you'd need two objects, one for the physics and one bigger one for the visual.

    uc92941268f0229c018a1317df3e.dl.dropboxusercontent.com/cd/0/get/Ch424sQbkuZ08pm0aeNfPmZBOMh_IUggjXTO_DE3vYjD8Ow1A6NjxlzimbEY9nYucoUDIpBesqHS_nkuYm86hYOv2ztgtjCtdG9_t086n_vJsdd_SR38_0VFf5L9eGoZ740/file

    The edge detection has issues though. It's probably as far as I want to go for now. I guess the next idea to tackle is coming up with a way to color each bubble individually or make the edges between circles curved.

  • It never hurts to go a bit more realistic. Buoyancy force is proportional to the area of the object underwater.

    So a very rough calculation utilizing the sprite's bounding box could be:

    apply force 0, -k*(sprite.bboxright-sprite.bboxleft)*max(0, sprite.bboxbottom-waterY)

    where waterY is the y of the water level and "k" is some number to tune it. You could probably start by setting k to 1 and go from there. I had to fiddle with it quite a bit to get something i was happy with.

    The only drawback is no torque is applied so I utilized imagepoints to be the centers of the box divided into four, and doing the approximate force for each. It actually gave very pleasing results and long planks would level out. To avoid bouning out of the water I cranked up the damping when in contact with water.

    dropbox.com/scl/fi/zweqaf1pcui7tm4my1aep/approx_buoyancy.capx

    Here's an old topic with a few more ideas:

    construct.net/en/forum/construct-2/how-do-i-18/physics-float-in-water-133996

    One was to use sine which may work depending on what you're looking for.

    The second was to calculate the actual area under the water, and the Center of mass of that area. It's much more realistic. The box2d example bounces a bit much, but turning up the angular damping helps.

R0J0hound's avatar

R0J0hound

Member since 15 Jun, 2009

Twitter
R0J0hound has 156 followers

Connect with R0J0hound