mekonbekon's Forum Posts

  • corlenbelspar

    Also you could use the bullet behaviour, using the "compare distance travelled" condition to stop movement after 16 pixels, setting the speed to 60 pixels per second.

  • Hi corlenbelspar,

    If you're using dt to modify the object's movement (e.g. every tick add 1*60*dt to object.X) then you're most likely not going to get it moving at exactly 1 pixel per frame, because dt usually isn't an exact 60th of a second.

    There are a number of 3rd party plugins that will allow you to move something an exact distance over time, such as the MoveTo plugin, but if you're just using the core behaviours, you could do something like this, using right movement as an example:

    Add an instance variable to your object, targetX and a boolean, moveRight

    is moveRight true:

    >>trigger once: set object.targetX to self.X+16

    >>Every tick if object.X<self.targetX, add self.X+1*60*dt to object

    If object.X>=self.targetX set object to self.targetX; set moveRight false

    This will at least ensure that you end up exactly 16 pixels away, factoring in dt, but you won't be moving exactly one pixel per frame.

    You can also turn on pixel rounding in the project properties and this will draw the sprite to integer pixel values, but the actual X of the object will be a float.

  • Laurent

    Maybe that would work. My concern, if I'm understanding you correctly, is that it might be hard to get the fading in and out working nicely as you would have to be constantly switching the speaker positions in and out. You may also end up skipping over sounds from narrow bands of tiles e.g. a river, because the speaker ends up on the far side of the narrow band.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Laurent - you could still use the tilemap system for one-shot and non-fading loop effects, e.g. different environmental footstep sounds, rustling bushes as you pass through them etc - a combination of the two systems should create quite an immersive audioscape

  • Laurent

    I've updated the capx; now the speakers switch themselves off if the sprite is more than 300px away:

    https://www.dropbox.com/s/kwh2ci35iikao ... .capx?dl=0

    I changed the audio tags so that they reference the UID of their speaker object instead of the tile - this prevents speakers playing the same sound from turning each other off.

    I added a distance parameter and on/off boolean to the speaker objects to control their state - this updates only every 0.1 sec to stop the checks eating up resources.

    If you run the capx in debug and click on the audio object you can follow the loops turning on and off as move towards/away from them.

  • Laurent

    Very kind of you to say so <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    I've updated the capx to include an example of speaker objects:

    https://www.dropbox.com/s/kwh2ci35iikao ... .capx?dl=0

    I created a Speaker object and added one on top of each group of tiles.

    On start, I set the Sprite to be a listener object, set each Speaker.TileNo to the tileNo the Speaker is sitting on. and being playing the corresponding loop at that object.

    This means that if there are a lot of speakers in the level you could end up with loads of sounds triggering at the same time on start. Most of them should be playing quietly, but be warned!

    The next thing I did was fiddle around with the audio object's "Positioned audio" properties; I still haven't quite got my head around how the listener Z height, reference distance, maximum distance and roll-off factor interrelate - have a play with them and see what shakes. It can be easier to test this with only two Speaker objects.

    You can find out more info in this section in the manual:

    https://www.scirra.com/manual/109/audio

  • Hi Youtopize

    Sorry for the delay in chasing this up. Not sure if you've already solved this or not, but I had a look at the converter that you linked to; it appears that the closest you can get to the right format for C2 arrays is the "JSON-Row Arrays" output option. You then have to convert it to this format, which means adding square brackets around each entry:

    {

    "c2array":true,

    "size":[2,3,1],

    "data":[ [ [ ], [ ], [ ] ],

    [

    [ ], [ ], [ ] ],

    ]

    }

    A potential downside is that it appears you can't convert 3D array data - i'm not sure if there is even a way to store 3D data in an Excel spreadsheet. Should be good for 2D arrays though!

  • Laurent

    No problem

    Yes, you can adjust the fade value to change the rate - a lower value results in a slower fade with more overlap. Note that you won't get the sound level remaining consistent with this system, but you should be able to get pretty close.

    This system doesn't limit the number of sounds you can have, you just import a new sound, making sure the filename ends with the corresponding tileNo.

    and it should work automatically without any code updates.

    If you want to increase the number of loops that can play concurrently, add another "volume" global, stepping up the final number, and duplicate event 4, adjusting the values in the new event and the final event to account for the extra variable.

    One way to get truly accurate environmental fades would be to add a "speaker" sprite to each of the different tile groups on the tilemap, tag it to the group using an instance variable and then start playing the sound for that tile group (using the "play at object" audio action) when the player enters the group. This solution would automatically adjust the volume based on the player's distance to the speaker object. This works okay if you build the maps in advance, but becomes trickier to implement if you are procedurally generating the tilemap, as you'd have to come up with a method for determining the approximate centre of a group of tiles. Not impossible though!

  • Laurent - you're welcome <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    I've updated the capx to provide a solution for multiple tile sounds:

    https://www.dropbox.com/s/kwh2ci35iikao ... .capx?dl=0

    There's no function, instead I use an array:

    There are 3 global volume variables. These control (1) the volume for the currently occupied tile type, (2) the volume for the previously occupied tile type, and (3) the volume for the type before that.

    Each time the sprite walks onto a new tile type a) Sprite.onTile is set to the tileNo, and b) the tileNo is pushed to the back of the array. This means that in the array we have a record of the order that the tile types have been stepped on - we can use this to determine which sounds to start, fade in, fade out and stop. By counting back from the end of the array we can identify the current and last two sounds played and apply the corresponding volume variables.

    The sound file is then called by name - each sound filename is suffixed with the corresponding tileNo so if you walk onto tile 1 for example, you can play "sound_1" by calling "sound_"&Sprite.onTile".

    The current volumes are then shifted one along: 2 to 3, 1 to 2 and 0 to 1, then volume 0 is reset to -40. This is so they correspond to the new positions in the array of the currently playing sounds.

    The loop volume for the currently stepped on tile types fades in from -40 to 0.

    The loop volumes for the previously stepped on tile types are gradually faded out - if the tag of a loop is more than 2 behind the newest tag then the sound is stopped.

  • Laurent

    I think I can help with the first part of your question; here's a capx based on your code:

    https://www.dropbox.com/s/kwh2ci35iikao ... .capx?dl=0

    I'm still considering the second part - do you mean that every tile type plays a different sound when the sprite moves over it? If so, should the sound continue to loop if the sprite moves over a group of the same tile type or start afresh for each tile in the group?

  • Swivels

    One way is to create a couple of extra globals e.g. lifeInit and timeInit, and set them to the reset values.

    When you want to reset "life" and "time" set them to lifeInit and timeInit.

  • Hi danispag

    You can set a variable in an action to a UID:

    On event: Set yourVariable to Object.UID

    You can add a condition to the event to pick a specific instance of the object e.g.:

    On event|Object.instanceVariable = 0: Set yourVariable to Object.UID

  • Chansen

    You can read about how to set parameters in the functions section of the manual: https://www.scirra.com/manual/149/function

    If you're going to be using functions a lot it's well worth familiarising yourself with parameters, they're very useful.

    Here's a capx of your code that includes a parameter on the "cubespawn" function call:

    https://www.dropbox.com/s/9rvwjo10rbvs2 ... .capx?dl=0

    In event 3 I use an action to pass the global variable Cube as parameter 0 on Function Call "cubespawn".

    You can add a parameter field to the Call function dialog by clicking the "Add parameter" highlight text. You can pass numbers, variables and strings as parameters.

    In event 4, On the "cubespawn" function being called, it uses the passed parameter 0 value of Cube in a repeat loop. This loop creates a sprite for each iteration, using the repeat loopindex to step up the sprites X position.

    I've also included another way to spawn a row of objects that may be of use, depending upon how flexible you need the system to be.

    You could also integrate "newrow" and "cubespawn", if there is a one to one relationship between them.

    Hope that helps! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Chansen

    Try passing Cube as paramater (0) from Function "newrow":

    On Function "newrow":

    System = Set Cube to :Choose(1,2,3,4,5,6,7)

    Function Call "cubespawn"(Cube)

  • RealMagisterLudi

    I use this for loading json files to arrays:

    Add the AJAX object to your project.

    Create yourArray object.

    Add your.json file to your project files.

    1) System| On (trigger): AJAX| Request your.json file (tag "your")

    2) AJAX| On "your" completed: yourArray| Load from JSON string AJAXLastData

    Make sure your json file is formatted like so for a 3D array:

    {

    "c2array":true,

    "size":[2,3,4],

    "data":[ [ [,,,],

    [,,,],

    [,,,]

    ],

    [

    [,,,],

    [,,,],

    [,,,]

    ]

    ]

    }