Deleting plotted image from a figure if conditions are met
4 次查看(过去 30 天)
显示 更早的评论
Hi, I am trying to make a game where one progresses vertically upwards by bouncing off platforms and the platforms underneath disappear once they are off the screen. I reckon this should be done by deleting them from the plot, but I don't know how to do this. This is my platform generating loop which makes 50 random platforms:
%Generate platform field
xpf = [];
ypf = [];
platformrecord = [];
for n = 1:1:50
hold on
xpf = [xpf randi(512)];
ypf = [ypf randi(30)];
platformcentre = [xpf(n) ypf(n)+70*(n-1)];
pfgen(48,16);
end
where pfgen() draws the platform image out of a random selection of 4 images, as below
function pfgen(x,y)
%generates a platform at specified x and y coordinates.
global platformcentre
n = randi(4);
d = randi(2);
platforms = [".\Assets\art\bin\simpleplatform-48x16-v1.png"...
".\Assets\art\bin\simpleplatform-48x16-v2.png"...
".\Assets\art\bin\simpleplatform-48x16-v3.png"...
".\Assets\art\bin\simpleplatform-48x16-v4.png"
];
if d == 1
[pfimage, map, alphachannel] = imread(platforms(n));
imagesc('XData',[platformcentre(1)-x/2 platformcentre(1)+x/2], ...
'YData',[platformcentre(2)-y/2 platformcentre(2)+y/2], ...
'CData',flip(pfimage,1), ...
'AlphaData',flip(alphachannel,1));
else
[pfimage, map, alphachannel] = imread(platforms(n));
pfimage = flip(pfimage,1);
alphachannel = flip(alphachannel,1);
imagesc('XData',[platformcentre(1)-x/2 platformcentre(1)+x/2], ...
'YData',[platformcentre(2)-y/2 platformcentre(2)+y/2], ...
'CData',flip(pfimage,2), ...
'AlphaData',flip(alphachannel,2));
end
Is there a way to say if the y-coordinate of my platform is less than the lowest y-coordinate visible, to remove said platform from the plot? Thanks.
0 个评论
采纳的回答
Philippe Lebel
2019-12-11
编辑:Philippe Lebel
2019-12-11
If you get the handle of the plot like so:
h = plot(1,1,'Xr')
you can just delete the handle and the data disapears
delete(h)
like wise for imagesc you can do:
doge = true;
h = imagesc
% wow such image
% very pixel
if doge
delete(h)
end
% such blank
% many empty
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!