user3897562
user3897562

Reputation:

MATLAB Game with GUIDE

I'm creating a game (similar to Space Invaders) in MATLAB using Guide, where the player's ship is controlled by an accelerometer. So far, my GUI is nearly complete and I have managed to import an image of a ship and move it along the x-axis of main axes with the accelerometer. However, I cannot get enemy ships to be generated on the axes at the same time. After adding just a second image, the first one never generates. The code that loads the images is as follows:

handles.spaceShipImg = flipdim(imread('spaceship.jpg'),1);
handles.enemyShipImg = flipdim(imread('enemy1.jpg'),1);

Here is the part where I attempt to display the images:

handles.step = handles.step + handles.gx;   %handles.gx is the reading from the accelerometer
axes(handles.magaxes)
image([handles.gx+handles.step 0.7+handles.gx+handles.step],[0 0.7],handles.spaceShipImg);
image([8 8.7],[8 8.7],handles.enemyShipImg);
set(gca,'YDir','normal')
axis([0 10 0 10]);

I'm wondering if it is possible to just use rectangular objects, and then paint them with an image instead. I also have to create collision detection, and I'm not sure how to implement that with images or rectangles. Any help is appreciated.

Upvotes: 0

Views: 336

Answers (1)

Austin
Austin

Reputation: 1020

Try using the hold on and hold off commands to prevent the axes from refreshing when painting the 2nd image. Put the hold on after axes(handles.magaxes) and use 'hold off` after axis([0 10 0 10]);

Upvotes: 0

Related Questions