Jump to content

Problem with button.events.inputDown.add()


Recommended Posts

I'm in the process of making a point and click demo. So far I have text that appears when you hover over a character. In addition, when you hover over, a "Next arrow image" button appears so that you can finish the dialogue.

//I have the button declared globally for now.

//I also have the dialogue and initialized as an array.

var button;

var ingramDialogue = [
        "What's up?",
        "You know you should really consider doing something original.",
        "Let Policenauts be what it was.",
        "A series is good when people are left wanting more",
        "Why ruin that, ya know?",
        ""
    ];

In create() I have

create(){

button = game.add.button(675, 450, 'white-arrow', null, this, 1, 0, 2);
button.visible = false;

}

In update(), I have

update(){

if(character.input.pointerOver()){
            playCharacterDialogue(ingramDialogue);
        }

}

//Here is what playCharacterDialogue looks like

//Essentially. It plays the initial line of dialogue

//Then it allows the user to go to the next part of the dialogue with each click of the button that appeared

//The function nextLine() then runs through each line of dialogue and prints it out as the user clicks the button

//There is a counter within nextLine() that is used to determine which line should be printed, and if the dialogue is over.

//THIS IS WHERE THE PROBLEM OCCURS

//For some reason, instead of going to the next line of dialogue in the array, the

//Program runs through the dialogue several times within milliseconds.

//I think it has something to do with placing button.events.onInputDown.add in "update()", since that is checked every frame

//What I'm trying to ask is. Is there something I can use other than "button.events.onInputDown.add" that would go through

each line of the dialogue one click at a time?

//Im not sure if this makes any sense. Any ideas would be appreciated

function playCharacterDialogue(generalDialogue){
         displayText.setText(generalDialogue[dialogueCounter], textStyle);
         button.visible = true;
         button.events.onInputDown.add(function(){
            nextText(generalDialogue);
         });

index-alternate-version-2.html

dialogueBox.jpg

ingram.png

otaku-room.jpg

white-arrow.jpg

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...