Pause until input from one of two buttons

조회 수: 2 (최근 30일)
Brian Clyde
Brian Clyde 2020년 3월 31일
댓글: Brian Clyde 2020년 4월 1일
I am trying to create a simple game that runs after hitting the start button, but at various times will pause for the user to click one of the two buttons before continuing. I can't figure out how to get it to pause for that, though, as "pause" is just a timer and "uiwait" seems to only work with images closing. How would I go about doing this?
Please don't be too complicated. I'm new to MATLAB app designer
properties (Access = private)
Playerimage= ["start_1.png" , "start_2.png", "start_3.png","start_4.png","standing.png", "jump.png", "travel.png"];
Enemyimage= [];
Jump = 0;
Scenario = "attack"
PlayerHP = [];
EnemyHP = [];
end
function StartButtonPushed(app, event)
%
%
%intro stuff
%
%
%right here I want to have some code that pauses until I activate one of the two function callbacks
% for the two buttons I made (as seen in the functions below) so the user can choose
% whether or not the character jumps
%if statement for whether or not the player jumps
if app.Jump == 1;
im1.Position = [100 250 120 120]
im1.ImageSource = app.Playerimage(6)
elseif app.Jump == 0;
im1.Position = [100 200 120 120]
im1.ImageSource = app.Playerimage(5)
end
end
% Button pushed function: JumpButton
function JumpButtonPushed(app, event)
%makes the character either jump dodge or jump attack
app.Jump = 1;
end
% Button pushed function: GroundButton
function GroundButtonPushed(app, event)
%makes the character either stay on the ground or do a ground
%attack
app.Jump = 0;
end

채택된 답변

Rik
Rik 2020년 3월 31일
You can also unpause uiwait with uiresume, not just by closing the figure.
  댓글 수: 5
Rik
Rik 2020년 3월 31일
I haven't worked with AppDesigner, so I'm guessing a bit here, but based on this doc page the handle to your uifigure is probably app.UIFigure.
uiwait(app.UIFigure)
Brian Clyde
Brian Clyde 2020년 4월 1일
that worked, thank you!
I just put that in and then uiresume(app.UIFigure) in the fuctions and it works. Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by