How do I change image for a button

Get help using Construct 2

Post » Mon Mar 16, 2015 2:58 am

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
B
6
Posts: 31
Reputation: 312

Post » Mon Mar 16, 2015 5:33 am

Ha! It's freaking easy, dude..

Let's consider that first state is play. And music is playing. So..
Code: Select all
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 := ' ▌▌'
B
8
S
1
Posts: 72
Reputation: 606

Post » Mon Mar 16, 2015 11:49 am

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 = ' ► '; "?
B
6
Posts: 31
Reputation: 312

Post » Mon Mar 16, 2015 12:09 pm

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.
B
8
S
1
Posts: 72
Reputation: 606


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests