fisholith's Forum Posts

  • Hey Dalal,

    Two possible approaches come to mind.

    Import the music as a sound

    You can import the music into the sound folder, and play it as if it were a sound, which would cause it to behave like a sound file for playback rate purposes. This also means the music would not be streamed though, so the end user would have to wait for the song to fully download before the game would start. If the song is short that shouldn't be that much of a problem, and if your distributing to desktop it's really not a problem. This is probably worth trying at least, to see if it adds an unacceptably long wait to the loading time of the game. My guess is that it won't change the loading time very much, as long as it's not a 10 minute song.

    Multiple files for each music variation

    If the music only ever has to play at the original rate and one other rate, (e.g. for a MarioKart normal-lap vs final-lap type of situation) then you could actually save a second copy of the music at the alternate rate, and include both copies in your game, switching to the alternate as needed.

    Obviously this method is not so good if you want a smooth transition of the playback rate, or a bunch of different playback rates.

  • Hey sadsack,

    In a graphic editor that can save png files, you'll want to select all pixels that match the background color, and delete them.

    Below are instructions for doing this in both Photoshop, and in Pixlr (a free online Photoshop-like editor).

    The instructions are almost identical for both programs.

    Photoshop

    In Photoshop, you can do this with the "Magic Wand" tool:

    • With the image open in Photoshop, double-click the image's layer in the layer panel to convert it from a background layer to a normal layer. (Background layers can't have transparency.)
    • Choose the Magic Wand tool, and in the options bar (top of screen), disable "contiguous" and "Anti-alias", and set "Tolerance" to "0".
    • On the image, click the background color to select all pixels matching that color.
    • Press delete to remove them. This leaves a transparent hole where they were.
    • Save the modified image as a png to preserve the transparency.

    Pixlr

    In Pixlr, you can do this with the "Wand" tool:

    • Choose the Wand tool, and in the options bar (top of screen), disable "contiguous" and "Anti-alias", and set "Tolerance" to "0".
    • On the image, click the background color to select all pixels matching that color.
    • Press delete to remove them. This leaves a transparent hole where they were.
    • Save the modified image as a png to preserve the transparency.

    Result

    Since I walked through the process in both programs to make sure I wasn't forgetting anything important, I ended up with the resulting image, which I figured I might as well include.

    [attachment=0:23rp6ggf][/attachment:23rp6ggf]

  • Good suggestion lennaert,

    I don't know if you're familiar with lerp() ThunderLion, but Lennaert is using it in his formula above to smooth out changes in the layoutScale over time.

    "lerp()" is a super handy function, which I'll try to explain a bit below. It can be found in the System's expressions in the math section, or you can just type "lerp()" in an expression.

    lerp()

    The lerp() function helps you pick numbers between a starting value and an ending value.

    So lerp() answers the following kind of question...

    Suppose you're on a road, starting at the 300 mile marker, and you're travelling to the 400 mile marker.

    Once you've travelled 50% of the way to your destination, what mile marker are you standing next to?

    Well, 50% of the way from 300 to 400, you'd be right in between them at 350.

    lerp( start , end , percentage )

    (The percentage in this case is expressed as 0 to 1, instead of 0% to 100%)

    lerp( 300 , 400 , 0.50 ) returns 350.

    Here are some examples:

    e.g. Some different percentages.

    lerp( 300 , 400 , 0.75 ) = 375

    lerp( 300 , 400 , 1.00 ) = 400

    lerp( 300 , 400 , 0.00 ) = 300

    e.g. Starting with a big number and ending at a small one.

    lerp( 400 , 300 , 0.75 ) = 325

    e.g. Some different values.

    lerp( 3 , 4 , 0.50 ) = 3.5

    lerp( -10 , 10 , 0.50 ) = 0

    lerp( -10 , 10 , 0.25 ) = -5

    lerp( -10 , 10 , 0.75 ) = 5

    e.g. Percentages outside the 0to 1 range.

    Using a percentage larger than 1.0, (i.e. larger than 100%), returns a number as if you overshot your destination and just kept travelling at the same speed.

    lerp( 300 , 400 , 1.50 ) = 450

    lerp( 300 , 400 , 2.00 ) = 500

    lerp( 300 , 400 , -0.50 ) = 250

    lerp( 300 , 400 , -0.75 ) = 225

    lerp( 300 , 400 , -1.00 ) = 200

    Using lerp() to smooth out a value over time

    In lennaert's example, he's using the lerp() function to make the layoutScale value change over time smoothly, from the value it currently is, to the value it currently should be.

    Suppose that layoutScale is currently 1, but you've moved to the corner, so it currently should be 2.

    If we want layoutScale to smoothly move from it's current value to a target value, instead of just setting it directly to the target value (not smooth), we can move it part way to the target value every tick.

    Let's move layoutScale's current value half way to the target value each tick.

    (A little fast, but it makes the example numbers easier to follow.)

    So we should expect to see the following, if we start at "1" and head for a target of "2".

    Tick 0: layoutScale = 1.00

    Tick 1: layoutScale = 1.50

    Tick 2: layoutScale = 1.75

    Tick 3: layoutScale = 1.875

    etc...

    We get closer and closer to 2 every tick.

    How can we use lerp() to do this?

    Every tick: Set layoutScale to lerp( layoutScale , 2 , 0.5 ).

    The first tick layoutScale will get set from 1 to 1.5.

    On the second tick layoutScale will get set from 1.5 to 1.75.

    etc...

    The only problem with the above lerp() is that we don't want the target to always be "2", so we can replace it with the formula that tells us what the zoom should currently be based on player position in the layout.

    Every tick: Set layoutScale to lerp( layoutScale , layoutScaleTargetValue , 0.5 ).

    If you want the approach speed to be slower you can use a smaller percentage.

    Every tick: Set layoutScale to lerp( layoutScale , layoutScaleTargetValue , 0.1).

    Frame (tick) rate independence

    So far so good, but notice that the speed we approach the target value is partly dependant on the number of ticks.

    With an approach rate of 50%, after 2 ticks we're 75% of the way to the destination. The problem is, it doesn't matter if we are playing the game at 30 ticks (frames) per second or 120 ticks per second, it always takes 2ticks.

    Imagine we use a small approach rate percentage, so that the value transition takes 60 ticks to get all the way (99.9%) to the destination, If the game runs at 60 ticks per second, the transition will take 1 second, but if the game runs at 30 ticks per second, the transition will take 2 seconds, because the transition still takes 60 ticks, and now the ticks are occurring half as often.

    What we need is a way to double the lerp()'s approach percentage, when the time between ticks doubles, (e.g. when the game slows down due to CPU load).

    We need to make the approach percentage proportional to the time between ticks.

    Fortunately, Construct gives us a variable "dt" (delta time) which gives us the time between the current tick and the last tick, in seconds, which is exactly what we need.

    So we just multiply the approach percentage by dt, to get the tick rate proportionality we're looking for.

    Every tick: Set layoutScale to lerp( layoutScale , layoutScaleTargetValue , 0.5 * dt ).

    Remember though that "dt" is tick time in seconds, so at 60 ticks per second dt will usually be about 1/60 ~= 0.0167, which is a smallish number. So you may need to compensate by adjusting the constant part of your original approach percentage, (i.e. the "0.5" in our case).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No problem.

  • Hey ThunderLion,

    One way you might do this is by changing the zoom level based on the player's distance from the center of the layout.

    You can get the distance between points with C2's built-in distance() function.

    e.g. Below is the distance from the center of the layout to the player:

    distance( layoutWidth / 2 , layoutHeight / 2 , Player.X , Player.Y )

    let's call this "playerDistance".

    Below is the distance from the center of the layout to a corner of the layout, (the max possible distance from the center):

    distance( 0 , 0 , layoutWidth / 2 , layoutHeight / 2 )

    let's call this "maxDistance".

    If the layout is 1000 x 1000 pixels, then the farthest you can get from the middle is 500 px at the middle of a layout edge, and about 700 px in the layout corner.

    (The 700 in this case comes from distance( 0 , 0 , 1000 , 1000 ) ~= 707 ~= 700.)

    So the maxDistance would be about 700.

    Thus, your playerDistance value is going to range from 0 (when the player is in the middle) to 700 (when the player is in the corner), roughly.

    So, if you divide your playerDistance by maxDistance, you get a result that ranges from 0 to 1. (i.e. 0/700 to 700/700)

    Lets call this "normalizedDistance".

    You can set your zoom level to 100 + ( 100 * normalizedDistance )

    With the player in the center of the layout, that expression becomes:

    zoom = 100 + ( 100 * 0 ) ... = 100 + ( 0 ) ... = 100

    With the player in the corner of the layout, that expression becomes:

    zoom = 100 + ( 100 * 1 ) ... = 100 + ( 100 ) ... = 200

    This means your zoom level will smoothly go from 100% to 200%, as the player goes from the center to the corner of the level.

    So the final formula would be:

    zoom = 100 + ( 100 * ( distance( layoutWidth / 2 , layoutHeight / 2 , Player.X , Player.Y ) / distance( 0 , 0 , layoutWidth / 2 , layoutHeight / 2 ) ) )

    Thinking of it in terms of the intermediate variables I described above, the expression evaluates as follows:

    zoom = 100 + ( 100 * ( distance( layoutWidth / 2 , layoutHeight / 2 , Player.X , Player.Y ) / distance( 0 , 0 , layoutWidth / 2 , layoutHeight / 2 ) ) )

    zoom = 100 + ( 100 * ( playerDistance / maxDistance ) )

    zoom = 100 + ( 100 * ( normalizedDistance ) )

    zoom = Some number ranging from 100 to 200 depending on the player's distance from the center of the layout.

  • Ah, I see what you mean.

    And also, thanks.

  • I could be wrong, but I think, in C2 terms, the items that get placed on a layout are "instances" of an object type. So if you copy an instance of an object, you get another instance of that same object type.

  • Depending on the complexity of the detection you want to do, instead of using dedicated detector objects, you could try using the "Is overlapping at offset" condition. It will temporarily move your object to an offset from it's current position and test to see if it's overlapping something there, then move the object back to it's original position before any other events run.

  • Awesome! Glad to help out.

  • Hey ex32,

    I may be misinterpreting the question, but there are two main ways an object can be copied.

    Duplicate instance

    Select an object instance in the layout, type Ctrl + C to copy the instance, and then Ctrl + V and click to paste the instance.

    This results in a new instance, which will be affected by the same events that affected the old instance.

    Duplicate object

    Right-click an object instance in the layout, from the context menu that pops up, choose "Clone object type", and click to place the first instance of the new object.

    This results in an instance of a new object, which will not be affected by the events that affected the old instance you initially right-clicked.

  • One possibility to prevent the enemy from jumping, when it can't jump far enough to make it over the gap, you can add two more detector objects, placed even farther out.

    After-gap solid detector

    This detector confirms that there's a near-enough solid object on the other side of the gap, that the enemy could get to it by jumping.

    Notice, though, that this will detect a flat landing spot as a solid, but it will also detect a vertical wall the same way, so it's not good enough by itself. (Unless you don't mind the occasional mid air face-plant into a wall)

    Clear jump path detector

    This detector confirms that there's open air above the landing spot, and open air in the jump arc the enemy would take to get there.

    This helps the enemy distinguish between a true landing spot, and a vertical wall. It also prevents them from jumping if the ceiling is too low to make the jump.

  • Hey chromaticcodex,

    One possible approach:

    1. For the exit objects, add a private text variable named "exitName".

    2. For each exit object, set "exitName" to a unique name. ... (e.g. "snakeTunnel", "lavaTunnel", "spikeTunnel", "comfyPillowTunnel")

    3. Do this for each layout, making sure the doors that are supposed to be linked between layouts have matching names.

    4. Now, create a global variable named "gLastExitUsed". ... (globals are unchanged between layouts)

    5. When the player leaves through an exit object, get the text in the exit's "exitName" and store it in the "gLastExitUsed" global.

    6. Jump to the new layout.

    7. On start of layout, pick the exit object with the "exitName" that matches the "gLastExitUsed" global. Place the player at that door, as if they just entered through it.

  • Hey Keijimura,

    You could place the events that handle player controlled movement inside a group, and then disable that group when the text pops up. When the player acknowledges the text, or it finishes displaying, you can then enable the group again allowing the player to move.

    If you don't want to use groups, you could use a Boolean (e.g. bPlayerMovementAllowed) that can be toggled off or on by NPC text events. In the events that handle player movement you would include checks of that Boolean to make sure bPlayerMovementAllowed is true.

  • Hi all, :)

    Regarding ACEs, is there a best practice for implementing a formula that returns a vector?

    I'm building a math plugin, and I was interested in adding an expression to return the intersection point between two lines.

    To return a point, I need to return the X and Y value for that point.

    The issue I'm running into is that C2 Expressions can't return vectors, and even if they could, there's no vector variable type in C2 to my knowledge, so there'd be nowhere to put the vector anyway. So I'm thinking I may have to use a combination of actions and expressions, to set parameters and retrieve the vector components individually.

    Is there a good or standard way to do this?

    Am I overlooking a way to do this purely with expressions?

    It seems technically possible to make an expression that sets internal variables rather than returning a value, but I suspect using the execution of an expression to change the internal state of an object is not encouraged. :D

  • You can do this with two layers, which I'll refer to as "Foreground" and "Background".

    The Foreground layer is arranged above the Background layer, as you'd probably guess.

    On the Foreground layer, place the CharTiles and ColorTiles.

    If we just stop here, the problem is that the Background layer will be tinted by the ColorTiles too, even though the ColorTiles are on a different layer. fortunately there's a solution.

    In the layer panel, select the Foreground layer, and in the property panel, enable "Force own texture".

    This will prevent the multiply blend of the ColorTiles from affecting any other layer, and so the ColorTiles will only colorize the CharTiles.

    For this to work, the char tiles will need to be white text on a transparent background. The ColorTiles will have no effect where they overlap transparency.

    Now you can put whatever you want in on the Background layer and it will show up behind your colorized ANSI characters.

    Since your CharTiles will be under your ColorTiles, you may need to temporarily switch their Z-orders to edit one or the other.

    More on "Force own texture"

    This setting will force the layer to render it's contents starting from a transparent background, instead of starting from the rendered result of all the layers below it. When a "Force own texture" layer has rendered all it's contents, it will then be pasted on top of the rendered result of all the layers below it. This is why blend effects for objects on a "Force own texture" layer will be isolated from other layers.

    Using Black on transparent text

    If you'd rather work with black text on a transparent background, you can replace the ColorTiles' "Multiply" blend effect to a "Screen" blend effect.

    "Screen" blend is identical to "Multiply" blend except flipped upside down in the 0 to 1 color value space. Screen inverts the inputs, multiplies them, and inverts the result.

    i.e. screen( a , b ) = 1 - mult( 1 - a , 1 - b )

    If you screen any image with white(1,1,1,) you'll always get white. Screen an image with black(0,0,0) and you'll always get the original image unchanged. Screen with middle-gray(0.5, 0.5, 0.5), and you'll get all the image's brightness values moved 50% closer to white. Light-gray(0.9, 0.9, 0.9) will move the image's brightness values 90% closer to white.