How to make a static image dynamic in MATLAB App Designer?

조회 수: 42 (최근 30일)
Sanne van den Broek
Sanne van den Broek 2021년 9월 25일
답변: Shanmukha Voggu 2021년 9월 28일
Hi, I am trying to make a game in MATLAB App Designer and for this game, which basically looks similar to asteroids, I want to have images that move dynamically. In order to do so, I tried to create different positions for this image by using the 'rand' code (for random outputs). However, I am not sure whether this is feasible and I want to make this position time-dependent (so that for instants, the image is in the left-bottom of your screen for t=5s, and then changes to somewhere on the right for a few seconds, etc. etc.). This should act as an astroid which takes random places on your screen, but instead I would like to use the image.
Can anyone help me out?
Thanks in advance!

답변 (2개)

yanqi liu
yanqi liu 2021년 9월 28일
sir,may be use timer to crate

Shanmukha Voggu
Shanmukha Voggu 2021년 9월 28일
Hi,
This can be achieved by pausing the execution for some time by using pause, steps I followed are as follows
1)Add an image to the app
2)Add a button to the app and update the callback function of the button as follows
function ButtonPushed(app, event)% number of times the image position is being updated
for i=1:10
randomNumber1=randi(300);% creates a integer between 1 to 300
randomNumber2=randi(300);
app.Image.Position=[randomNumber1 randomNumber2 100 100];%updating position of Image
pause(5)% pauses the execution for 5 seconds and
% pause time can be randomized by using random
end
end
Refer to this for more information

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by