Azzera filtri
Azzera filtri

so I'm making a videogame

2 visualizzazioni (ultimi 30 giorni)
Stephen
Stephen il 24 Mag 2012
I have a vector of enemy handles so that I can assign visibility to certain enemies and not others, but once I update all of their positions (xdata and ydata), the visibility gets messed up and all become visible in the entire map. Anyone know why? I tried to use get(e,'visible') but it returns a cell of 'on' or 'off' that sucks to feed into set

Risposte (3)

Stephen
Stephen il 24 Mag 2012
y=get(h,'ydata');
x=get(h,'xdata');
hy = hypot(ye-y,xe-x)<8;
set(e(hy),'visible','on')
this gets the player position and makes certain enemies visible
xs=sign(xe-x)*randint;
ys=sign(ye-y)*randint;
hy = hypot(ye-y,xe-x)<6;
hy = logical(hy.*(loc==zones(y,x)));
xe(hy)=xe(hy)-xs(hy);
ye(hy)=ye(hy)-ys(hy);
set(e,'xdata',xe,'ydata',ye)
This updates the enemies position and ruins everything

Matt Kindig
Matt Kindig il 24 Mag 2012
Do you have any calls to 'drawnow'? I don't think that simply changing the xdata/ydata is supposed to change handle visibility. Some other commands, such as 'figure', 'pause', and others automatically call drawnow.
One way you could quickly set all visibilities is to pass in a vector of handles to the set command. Something like:
set( HandlesOfHiddenObjects, 'Visible', 'off');
set( HandlesOfVisibleObjects, 'Visible', 'on');
  2 Commenti
Walter Roberson
Walter Roberson il 24 Mag 2012
drawnow() should not affect the visibility of anything.
Stephen
Stephen il 24 Mag 2012
I have drawnow in the main while loop of the game

Accedi per commentare.


Walter Roberson
Walter Roberson il 24 Mag 2012
You cannot set the visibility of individual points in a line object. Your visibility with that code is going to be set according to the last value that happens to be in the array.
  2 Commenti
Stephen
Stephen il 24 Mag 2012
it isn't one line object, but several single point objects whose handles I packed into a single vector, e. I'll try some different syntax
Stephen
Stephen il 24 Mag 2012
also, the visibility line works, it's just that once I update the positions it resets all visibilities

Accedi per commentare.

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by