0 Favourites

How do I change image for a button

  • In my game,I have a pause button with "pause" icon.If we click this button,game will pause and pause button will change to "play" icon (means if we click this button ,the game will resume).So how to do th at

  • Ha! It's freaking easy, dude..

    Let's consider that first state is play. And music is playing. So..

    var Button.State = 'play';
    <...>
    On Button clicked -->
         If Button.State = 'play' then {
              <pause music>;
              Button.State = 'pause';
              Button.Text = ' ► ';
              }
         Else if Button.State = 'pause' then {
              <resume playing music>;
              Button.State = 'play';
              Button.Text := ' ▌▌'
    [/code:hq50qlw4]
  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Sorry but i `m newbie with construct.so i `m not sure what you mean?So we must code in construct???how to do that???.You can explain more me?Button text can be an image: " Button.Text = ' ► '; "?

  • No, my code above is PSEUDOcode.

    So I understand you in programmable manner a sequence of your actions to do smth.

    To make this in C2 you need (let's disassemble my example):

    1. For object Button create string instance variable with name State. Its initial value must be initial state of your music. If pause - 'pause', if play - 'play'.

    2. Then create Event when you tap (with Touch plugin) or click (with Mouse plugin) this Button

    3. 1st sub-event of 2. event will be Button -- Compare instance variable with comparison Button.State = 'play'

    4. All sub-events of 3. event will be:

    4.1 Button -- Set value, pick State and set its value to 'pause'

    4.2 Button -- Set text and set text to ' ? '

    4.3 Any other actions to pause your music

    5. Then add another sub-event to 2. event: System -- Else and add new condition below Else - Button -- Compare instance variable with comparison Button.State = 'pause'

    6. All sub-events of 5. event will be:

    6.1 Button -- Set value, pick State and set its value to 'play'

    6.2 Button -- Set text and set text to ' ¦¦'

    6.3 Any other actions to play your music

    Do you understand so?

    Teach C2 and try to understand another's pseudocodes. I'll not write it so detail next time.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)