R0J0hound's Forum Posts

  • I think the drawingCanvas example would be the simplest one since it just uses the z order of the objects.

    Do you have an example project of how you set up the objects? If the shadows and objects are in one family then that’s fairly simple. If instead it’s an assorted variety of objects then that is a bit less simple.

    The verbose pseudo code of what we want to do is this:

    For each object ordered by zorder
    — is a shadow? Make visible and set opacity to 100
    — is not a shadow? Set blend to destinationOut
    — paste object
    — set blend mode to normal
    — is shadow? Make invisible

    But with events there are some simplifications.

    Anyways, with an example of how your objects are setup I could make a more specific example.

  • So here are some ideas. For an example I had a few solid green balls that are in front of and behind some blue clouds. The goal is for the clouds to be uniformly blended together. I went for the simple case of one object type, so you'd either have to use a family or do something more complex for multiple types.

    The first basically clones the first layer onto a second. Then all the objects are given 100% opacity and the solid objects have destination out.

    dropbox.com/s/vhegleb8dry4l15/shadow_blend_clones.capx

    The second C2 example uses the third party paster plugin. All the objects are drawn to the paster, but the solid are erased.

    dropbox.com/s/q893tdqvcaqmgu5/shadow_blend_paster.capx

    The C3 version using the drawing canvas. Basically the same as the paster one.

    dropbox.com/s/i7nl6hvrgdlkyhy/shadow_blend_c3_canvas.c3p

  • I’ll try to make an example tomorrow. Basically one layer would be just the objects, and the other layer would have objects and shadows, but the objects are subtracted away.

  • Besides a layer I suppose you could use a canvas instead.

    Draw all the shadows to the canvas with full opacity and all the other objects with a “destination out” blend. Then you can set the canvas’ opacity.

    I’m a bit iffy if the paste action be used like that in c3. You’d need to draw things in order.

    Another idea that would work is a layer. All the shadows are there and clones of all the objects with “destination out” blends. May be a bit tedious to work with though.

    What it comes down to is if we want multiple shadows to be equally transparent, even in the overlapping areas, we need to draw them full opacity together first and then make them transparent.

  • Here's one possible solution.

    For each of your items you'll want to store a "mask" of what squares it occupies within it's rectangle. So for a gun it could be:

    1111
    1000

    So when you drop an item into an inventory you'd only need to see if the 1 places were unoccupied as well as inside the array. If all the 1 were then you could then place the object in the inventory.

    Here is an example without arrays, although you could certainly use arrays instead. I'm just using "is overlapping point" instead of an array lookup. It handles placing and removing items, as well as throwing them out if they are placed in an invalid spot. Perhaps some of the ideas here are useful.

    dropbox.com/s/tpwx74fq1c43auc/Fit_shapes_into_slots.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I suppose one way would be to use these system expressions.

    CanvasToLayerX(layer, x, y)

    CanvasToLayerY(layer, x, y)

    LayerToCanvasX(layer, x, y)

    LayerToCanvasY(layer, x, y)

    Cx = LayerToCanvasX(sprite.layer, sprite.x, sprite.y)
    Cy = ...
    Lx = CanvasToLayerX(sprite2.layer, cx, cy)
    Ly = ...
    D = distance(sprite2.x,sprite2.y, lx,ly)

    Another is to come up with the formula to do the parallax. It may end up being simpler but may take a bit of fiddling to get it right.

    Off the top of my head if there’s no rotation then

    X2 = ((x-scrollx)*parallax+scrollx)*scale

    Could be a possible start

  • You'll still need to find the angle of the surface. This is often called the collision normal. Construct calculates that internally to some extent for the bounce and the push out. But besides that you'll have to calculate that yourself.

    However, why not just use the bullet behaviors bounce? No need to replicate it. You can add it to the object but have it disabled. Move the object with custom and when you want to bounce do this:

    1. bullet: enable
    2. bullet: set speed to custom.speed
    3. bullet: set angle of motion to custom.angleOfMotion
    4. bullet: bounce
    5. custom: set speed to bullet.speed
    6. custom: set angle of motion to bullet.angleOfMotion
    7. bullet:disable

    Or at lest something along those lines.

    You can go the other route of finding the normal of a collision, but you'll have to calculate that per shape type which can add up. Or you can guesstemate the angle by sampling a bunch of points around the object's edge and averaging the overlapping points, but that's a rough approximation.

  • Try it I suppose. Actually I just read your issue again. You’re using a 60pixel square and in the capx I use a 64pixel one. You just need to find the 32s in the events are replace them with 30s to fix it.

    It’s just half the width

  • Here's one way to do it. Namely event 4. The rest is physics and such which isn't needed.

    Basically it treats the objects as circles and moves them away from each other if too close. Works between object of the same type. You can change the radius in the set dist action. Currently it uses 24 but you can change that.

    dropbox.com/s/mlm73dkgtjvvw42/againstTheCrowd.capx

  • So here is a slightly different example.

    * The rotation is driven by pressing a key.

    * It now lets you use any value for the rotation speed.

    * I moved the variables into the sprite so we can have multiple rolling squares.

    * Lastly, it rounds the angle and position to the nearest integer when a 90 degree rotation is done. Do to rounding errors the position and angle wouldn't be slightly off a perfect value.

    dropbox.com/s/4vfgdw3mzx6lwkb/box_roll2.capx

  • Well k is just an arbitrary number. Having k=1 may make the perspective effect too severe, but a higher number such as 500 would make it more subtle in a reasonable way. If more careful about the units it relates to the field of vision of the camera.

    z is the third dimensional position of an object. I know we are dealing in 2d but to have the perspective we need to know how far into the screen an object is to scale it.

    a is just the amount of degrees you wanted to rotate.

    Here is a possible example but i got a bit carried away beyond the basic ideas. I guess 3d tends to snowball depending what you're doing. The meat of it is event 15. It sets the camera orientation, transforms the object positions from that orientation, applies a perspective transform, and finally zsorts everything.

    dropbox.com/s/oggk1776al45ka1/3d_camera_events.capx

  • So you just want to change the view? You can use the 3d camera object to do that to some extent. You can position objects xy and zElevation.

    Control wise all the movement behaviors are 2d on the xy plane so you'll need to do the z axis motion with events.

    If you don't want to use 3d and instead want to do the rotation/perspective with math and just sort the objects in 2d then the two building blocks for that are:

    1. Rotation of a position around a center. Here it does it on the xy plane but you can do it on the xz or yz plane too. The equations are the same, just change what axis is used.

    newX = (x-centerX)*cos(a) - (y-centerY)*sin(a) + centerX

    newY = (x-centerX)*sin(a) + (y-centerY)*cos(a) + centerY

    2. perspective transform and scaling. Here k is some scaling factor that adjusts the perspective. Keep in mind you'll want to hide objects with a z<1 as they are behind the camera, and you'll need to sort the objects by z.

    screenX = k*(x-scrollx)/z + scrollx

    screenY = k*(y-scrolly)/z + scrolly

    objScale = k/z

  • That was a bit older example, and I was going for a certain look but as you pointed out it doesn't move accurately. I'd probably need to figure out the formulas again to account for that. Probably simpler to use the other capx though.

    Like in that video the box is rotated around a corner and every time the box lands on an edge (every 90 degrees) it changes which corner to rotate around.

  • dropbox.com/s/q3fejozejh7s2ix/closest_value_in_list.capx

    As a similar idea to yours just loop over the list and you can see how close two values are with abs(value1-value2). So the code below would first use the first item in the list as the closest then it would select any item that was closer than the current closest.

    var list="1,44,33,66,7"
    var item=0
    var value=33
    var closest=0
    repeat tokencount(list, ",") times
    -- set item to int(tokenat(list, loopindex, ","))
    -- if loopindex=0 or abs(item-value)<abs(closest-value)
    -- -- set closest to item

    This checks all the values and works if the list isn't sorted.

    Yours stops as needed since your list is sorted.

  • Can you explain what you’re after a bit more? It’s not clear to me.

    Your images are different views of 3D meshes. So if you placed cubes down and adjusted the camera you can get the same look. But your descriptions made it seem like you’re after something else