thepeach's Recent Forum Activity

  • Can anyone offer advice on using gamepads in a script-based project? I understand it's necessary to use an event sheet because the Gamepad plugin isn't accessible to the scripting interface. Here are some of my goals for the implementation:

    1. Pass Gamepad plugin data to a script file from an event sheet.
    2. Avoid introducing side effects in the event sheet.
    3. Avoid mutable global variables.

    Here's my latest attempt for the event sheet. This would be fine if I could return the data to my script file.

  • The current solution is to call an event sheet function returning the value(s) you want. Here is an example that returns the default width for a Sprite Font object named "SpriteFont":

    const width = runtime.callFunction('GetCharacterWidth');
    
  • For posterity, the suggestion can be voted on here.

  • Thanks for your reply! Is it possible to set the time scale to 0 for testing without using an event sheet? It seems like it's not based on this discussion.

  • Just for clarity, this.#runtime.objects.Camera.getFirstPickedInstance() is a sprite with the scrollTo behavior enabled.

  • Ashley's 2017 article on delta-time says:

    Don't forget behaviors already use dt. If you use behaviors to control all motion in your game, you don't have to worry about dt at all!

    So, can I ignore delta-time when using the lerp function to position a sprite with the ScrollTo behavior? For context, see the comments in my code below:

    const lerp = (start, stop, amount) => amount * (stop - start) + start;
    
    export default class Game {
     #runtime;
     #camera;
     #player;
    
     start(runtime) {
     this.#runtime = runtime;
     this.#camera = this.#runtime.objects.Camera.getFirstPickedInstance();
     this.#player = this.#runtime.objects.Player.getFirstPickedInstance();
     this.#runtime.addEventListener('tick', () => this.#onTick());
     }
    
     #onTick() {
     // Do I need `this.#runtime.dt` here?
     // Or, does the scrollTo behavior already use it?
     const amount = 0.3 * this.#runtime.dt;
     // Move the camera to the player's position using lerp.
     this.#camera.x = lerp(this.#camera.x, this.#player.x, amount);
     this.#camera.y = lerp(this.#camera.y, this.#player.y, amount);
     }
    }
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have a layout that uses the default Sprite Font object. The character width and height are both set to 16 in the editor. Is it possible to get the corresponding property values in a script file? For example, something like the following where `SpriteFont` is the object's name:

    `runtime.objects.SpriteFont.getFirstInstance().characterSize.width`

thepeach's avatar

thepeach

Member since 10 Dec, 2022

None one is following thepeach yet!

Connect with thepeach