R0J0hound's Recent Forum Activity

  • Ah, I see. Yeah, doing what you want is much simpler than what I proposed. I'd say still use the drawingCanvas. You can even use it to make the shadows from the objects directly.

    This clears the canvas, rotates the trees 221 degrees, pastes trees to canvas, return the trees to 0 degrees, then draws a black rectangle with the "source in" blend.

    dropbox.com/s/3noo9ie08ckvx6r/shadow_blend_simple.c3p

    Or instead of rotation, you could use distort meshes to make a skew.

    dropbox.com/s/qczxy22l8tr936s/shadow_skew.c3p

  • 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

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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