I am failing the task: "The nextFrame() method must increase the frameIndex field by one." Why?
We'll create the nextFrame method in the Ship class to switch to the next animation frame. It sets the matrix field to the next animation frame, if possible. We'll extend the functionality of the draw method by overriding it so that it calls the superclass's method for drawing and the nextFrame method for changing animation frames.
Requirements:
The Ship class must have a public void nextFrame() method.
The nextFrame() method must increase the frameIndex field by one.
The nextFrame() method must not do anything if frameIndex is greater than or equal to the number of frames in the frames list.
The nextFrame() method must set the matrix field equal to the frame in the frames list whose index is equal to frameIndex.
In the Ship class, the void draw(Game) method of the parent class must be overridden.
The Ship class's draw(Game game) method must call the superclass's method with game as the argument.
The Ship class's draw(Game game) method must call the nextFrame() method.
The Ship class must import the com.codegym.engine.cell.Game class.
package com.codegym.games.spaceinvaders;
public enum Direction {
RIGHT,LEFT,UP,DOWN;
}
You can see it in the window above in the ship class.
public void nextFrame() {
frameIndex += 1;
if(frameIndex >= frames.size())
return;
super.setMatrix(frames.get(frameIndex));
}
Thanks for your help Roman. The following sounds rude but I'm just trying to help others out.
I did try that and it didn't work. It also doesn't follow the process in the lesson. HOWEVER, if I remove the lines below that set the width and height then it does pass testing.
I think there's an issue with the validator here and somehow your inaccurate (doesn't set the width and height) code passes it. (I understand that the width and height don't actually change.)
public void nextFrame() {
this.frameIndex++;
if(frameIndex >= frames.size())
return;
//super.setMatrix(frames.get(frameIndex));
matrix = frames.get(frameIndex);
width = matrix[0].length;
height = matrix.length;
}
0
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.