NicotineLL's Recent Forum Activity

  • Alright, I figured it out!

    Since "Trigger once" is actually triggered every tick, that means that it is incapable of memorizing whether a button has been pressed or not. However an array can remember that

    So I've created another array called "Active" that is pretty much the same as "Controls":

    "Controls"

    • A cell is 0 by default
    • When a button is pressed it becomes 1
    • When it's released the cell becomes 0 again

    "Active"

    • A cell is 0 by default
    • When a button is pressed it becomes 1
    • When it's released the cell becomes 0 again

    Now I can actually compare both:

    Controls - Active - State

    0 - 0 - no button pressed (default)

    1 - 0 - button is pressed, but could also be down

    1 - 1 - button is definitely down (pressed will not trigger again)

    0 - 1 - button is released (pressed has been reset)

    So the script goes like this:

    if(controls[0,0] != 0) {
        if(active[0,0] == 0) {
            // do something like move left
            active[0,0] = 1;
        }
    } else {
        active[0,0] = 0;
    }
    [/code:1jn16bma]
    
    An example image:
    [img="https://40.media.tumblr.com/3dd749d159c2d5647112712db649abae/tumblr_nvcb5yj4ji1tbcgxno1_1280.jpg"]
    
    Now I'm 95% positive I can merge "Controls" and "Active" arrays into one and shove the logic directly into the "Controls" function itself which will simplify things by a whole lot.
  • Optimize your game:

    Layout

    • Run in Debug mode and at the top see how many objects are currently active. Try to remove some by using clones instead of new objects for every sprite.
    • Too many effects and big images with alpha channel can go heavy on mobile devices

    Events sheet

    1. Use groups to group similar actions in your event sheets

    2. Use Debug mode -> Profile to see which groups are using the most CPU

    3. Try to improve the code by removing or replacing conditions and actions (use functions, less events that trigger on every tick, etc.)

    Only a single thing can cause a big problem.

    I've made a little game like this in the past and by adding a transparent background image (that changes colors randomly) with lighting effects I was able to add 0.5 seconds of lag to the controls.

  • Tap is equal to Keyboard Key Pressed condition;

    Touch is equal to Keyboard Key Down condition.

    You should probably use tap for a button.

  • Set a global variable "WalkLeftAnimation" equal to "walk1a".

    On left button down -> Play "WalkLeftAnimation"

    Then on collision with item (or however you check if the player got the item) set "WalkLeftAnimation" to "walk1b".

    Another way of doing it is to add an instance variable to the player object to replace the global variable.

  • nimos100 That's not quite how it works. 4 players can be:

    4 on gamepad 0 on keyboard

    3 on gamepad 1 on keyboard

    2 on gamepad 2 on keyboard

    1 on gamepad 3 on keyboard

    0 on gamepad 4 on keyboard

    That said, it is not always practical, but it's a possibility.

    Then the other plus is that you can assign Player to Movement functions. Imagine a title screen where you choose a character. Some characters move up and down, others move left and right. With my setup you can tell how a character moves with the Controls function and then assign a Player (e.g. gamepad index) to it. So with one controller you can be either one character.

    ramones thank you very much for clearing this out for me. Now that I know I can't use Trigger once in functions, I'll look for another way to simulate the "On Pressed" condition.

    I've something in mind and I'll test it tomorrow to see if it works and post it here.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I agree it's a big excessive, but I've done much more complicated stuff (JS, PHP, etc) and was able to keep up with them. I haven't fully caught up with the capabilities of Construct and that's why I've so much trouble. After all I've no more than 2 weeks (combined) experience in "game making"

    Imagine this scenario with your suggestion:

    4 players assigned to a single object that differs only by instance variables have to control each one with their controller and/or keyboard. You'll need the following code:

    Function "Move Left"
    Function "Move Right"
    Function "Jump"
    
    // Function Param 0 on all of them is instance variable "Player"
    //Then you'll need to call these functions for each Player, so you either have to do it manually
    
    Get "Object" with "Player" = 0
        On Gamepad "0" Button "D-pad Left"  Pressed
            OR
        On Keyboard "A" Pressed
            -> Call function "Move Left"
        On Gamepad "0" Button "D-pad Right"  Pressed
            OR
        On Keyboard "D" Pressed
            -> Call function "Move Left"
        On Gamepad "0" Button "A"  Pressed
            OR
        On Keyboard "Space" Pressed
            -> Call function "Jump"
    
    // Then repeat 3 more times for the other players
    // Or use a Loop
    
    For each "Object"
         On Gamepad "Object.Player" Button "D-pad Left"  Pressed
            OR
        On Keyboard "A" Pressed
            -> Call function "Move Left"
    // but oh, it doesn't work...
    // First we're assigning key button A as "left" for all players, so if we really want to go with this approach we still need to use an array and call "left" by Object.Player as X and keyboard key codes as Y
    // Second and to be fair more importantly, you cannot have triggers inside a loop, so the whole idea is out the window
    [/code:wly9mfde]
    
    I think you're missing the point that every gamepad key has a key on the keyboard that mimics it. You CAN do it manually, but it will be a lot of repeating code and if something needs to be change it'd be a headache.
    
    I really need to take a break...    I'll leave everything for the weekend or even a whole week and come back to it with fresh mind later. Thanks @nimos100 for the great suggestions!
  • nimos100

    You are right. But I don't think the problem comes from the "Controls" group/function. I really don't think that it is that complicated. Just pull inputs from devices and store them in an array.

    It's the "Player" function (yes there were 2 conditions that didn't do anything - leftovers from previous testing). I think it's not comparing enough stuff and needs more conditions, that's all.

    Look at this (it's the exact same function, but Player0 and Player1 branches are split and it works just fine):

    Lordshiva1948

    Yes I am. All button groups are deactivated by default (no reason to run them all for a game that requires 3 buttons for example). On layer start I enable only the ones which are required. I don't really see how this could affect anything unless there is some kind of a bug in Construct 2?

  • The idea is to do all this with a single function:

    1. Handle all gamepads (potentially 4x less code)

    2. Choose which buttons to be active (potentially 4x less code + save CPU)

    3. Map keyboard buttons to match all gamepads buttons

    At first I was simulating "On button pressed" directly into the "Controls" function by adding a Z-index to the "Controls" array (0 for "Is Pressed and 1 for "Is Down"), but that doubled and even tripled the CPU time so I went with a simply XY array instead.

    The activity is stored in an array so it can be easily set as condition, for example "Value at (X,Y) > 0" will mean that the button is pressed (That is the same as using the built in gamepad "Is button down" condition).

    To understand the problem run the capx and do this: "if you press A a couple of times you'll see Player0 moving a few pixels to the left. If you repeat this with the LeftArrow the Player1 will do much of the same. However if you hold on A and press the LeftArrow Player1 will go left as if the "trigger once" does not exist." This should not happen. It means that while Player0 button is pressed the function continues to return TRUE and Player1 instead of moving a pixel to the left and stopping is shooting through the screen.

  • I've made a function that tracks activity on different input devices (keyboard & controllers) and saves them into an array. I then take and compare the values to determine which key is down. Being a function I cannot use triggers so all values are saved on "Is button down" and then I use "Trigger once while true" to simulate "On button pressed".

    I've had a few major issues, but I managed to solve them. However, I've been banging my head the last few days trying to figure out why I cannot use the same function (with a single parameter) to track multiple objects and inputs. Even though I did it from scratch I don't quite understand how everything works so I might be talking nonsense right now so I'll try to explain it with an example.

    Here's the file: https://www.dropbox.com/s/0p9eu81286cwi ... .capx?dl=0

    Since there's a lot of event's I'll try to explain really quickly:

    • The "Controls" group is where I setup the keyboard key codes, the actual function that tracks inputs and which keys are active (there's nothing wrong with it, no need to go any further).
    • The "Players" group is where I setup a basic example (see how some events have "Trigger once"? That's to simulate the built in "On button pressed" trigger)
    • The "Connect" group is just to attach the Player function to the given objects

    To control Player 0 use A and D

    To control Player 1 use LeftArrow and RightArrow

    Now for the actual problem - if you press A a couple of times you'll see Player0 moving a few pixels to the left. If you repeat this with the LeftArrow the Player1 will do much of the same. However if you hold on A and press the LeftArrow Player1 will go left as if the "trigger once" does not exist.

    I know it has something to do with the way the Player function is designed and/or called, but I really have no clue where.

    Any ideas?

    I'm attaching an image just in case:

  • Just a side note: on initial "Run layout" (on webkit browsers, Firefox works fine) all gamepad buttons are inactive until A, B, X or Y are pressed. But I have no .capx to prove it so might be lying.

  • Problem Description

    Controller indexes switch places on webkit browsers

    Attach a Capx

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

    Description of Capx

    4 platformer objects set to react (jump) on A button (Xbox360 controller) pressed

    Steps to Reproduce Bug

    • Get 4 xBox 360 controllers
    • Open attached capx
    • run in Chrome or Opera
    • press A on different controllers and observe behavior

    Observed Result

    Most of the time index 1 is not detected; 0 works fine, 2 is 1 and 3 is 2.

    So it goes something like this:

    Pressing A on controller with index 0 makes the plaformer with instance variable "Player" set to 0 to jump;

    Pressing A on controller with index 1 does nothing at all;

    Pressing A on controller with index 2 makes the plaformer with instance variable "Player" set to 1 to jump;

    Pressing A on controller with index 3 makes the plaformer with instance variable "Player" set to 2 to jump;

    I've also gotten a result where index 0 is not detected and 0,1,2 were offset to 1,2,3 and 3 was not working becase there's no index 4.

    Expected Result

    Pressing A on controller with index 0 to make the plaformer with instance variable "Player" set to 0 to jump;

    Pressing A on controller with index 1 to make the plaformer with instance variable "Player" set to 1 to jump;

    Pressing A on controller with index 2 to make the plaformer with instance variable "Player" set to 2 to jump;

    Pressing A on controller with index 3 to make the plaformer with instance variable "Player" set to 3 to jump;

    Affected Browsers

    • Chrome: YES
    • FireFox: NO
    • Internet Explorer: YES (Does not work at all (controllers are not supported))

    Operating System and Service Pack

    Windows 8.1

    Construct 2 Version ID

    Release 212.2 (64bit)

NicotineLL's avatar

NicotineLL

Member since 4 Jan, 2015

Twitter
NicotineLL has 2 followers

Trophy Case

  • 9-Year Club
  • Popular Game One of your games has over 1,000 players
  • Famous Game One of your games has over 10,000 players
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • x2
    Quick Draw First 5 people to up-vote a new Construct 3 release
  • Email Verified

Progress

15/44
How to earn trophies