Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualwarnexus

Posted 30 March 2013 - 10:17 PM

I am still in the process of learning how to animate images more efficiently on the screen. I want to bring my monster to life after seeing the monster move up and down statically for 2 months.

 

My thought process on animating the monster is to use a dynamic array like an ArrayList. While the animation looks correct on screen, the monster certainly moves like the monsters from the Mario game on NES. But I don't think the code implementation below is the way most people would do it most commonly. 

 

The image frames below are stored in an ArrayList of Images manually.

 

The Ghost uses 3 separate image frames of animation(meaning it is not using a sprite sheet for a simplistic learning experience) 

Ghost1_zps65e205e5.png

Ghost2_zpsc07170b1.png

Ghost3_zps32222b2c.png

 

The code draws a different images depending on what position the monster is on the screen. Once the position has been reached, the game draws a new image. The way the monster gets a new image is by using the get method while providing a hard-coded index argument of the image elements from the ArrayList of Images.

 

 

 
public class Ghost extends Sprite {
 
 
private Image image;

private ArrayList<Image> arrayListOfImages;
 

public Ghost(double x, double y) {
// TODO Auto-generated constructor stub
position = new Vector2D(x,y);
velocity = new Vector2D();
 
 
arrayListOfImages = new ArrayList<Image>();
 
try 
{
image = ImageIO.read(new File("src/Ghost/Ghost1.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost2.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost3.PNG"));
arrayListOfImages.add(image);
} 
catch (IOException e) {
e.printStackTrace();
}
 
}
 

public void draw(Graphics g) {
// Draw the monster image at our position
 
if(position.y >= 0)
{
g.drawImage(arrayListOfImages.get(0), (int)position.x, (int)position.y, null);
 
}
if(position.y >= 50)
{
g.drawImage(arrayListOfImages.get(1), (int)position.x, (int)position.y, null);
}
if(position.y >= 100)
{
g.drawImage(arrayListOfImages.get(2), (int)position.x, (int)position.y, null);
}
 
}
}

#8warnexus

Posted 30 March 2013 - 10:16 PM

I am still in the process of learning how to animate images more efficiently on the screen. I want to bring my monster to life after seeing the monster move up and down statically for 2 months.

 

My thought process on animating the monster is to use a dynamic array like an ArrayList. While the animation looks correct on screen, the monster certainly moves like the monsters from the Mario game on NES. But I don't think the code implementation below is the way most people would do it most commonly. 

 

The image frames below are stored in an ArrayList of Images manually.

 

The Ghost uses 3 separate image frames of animation which I quickly create using Paint: 

Ghost1_zps65e205e5.png

Ghost2_zpsc07170b1.png

Ghost3_zps32222b2c.png

 

The code draws a different images depending on what position the monster is on the screen. Once the position has been reached, the game draws a new image. The way the monster gets a new image is by using the get method while providing a hard-coded index argument of the image elements from the ArrayList of Images.

 

 

 
public class Ghost extends Sprite {
 
 
private Image image;

private ArrayList<Image> arrayListOfImages;
 

public Ghost(double x, double y) {
// TODO Auto-generated constructor stub
position = new Vector2D(x,y);
velocity = new Vector2D();
 
 
arrayListOfImages = new ArrayList<Image>();
 
try 
{
image = ImageIO.read(new File("src/Ghost/Ghost1.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost2.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost3.PNG"));
arrayListOfImages.add(image);
} 
catch (IOException e) {
e.printStackTrace();
}
 
}
 

public void draw(Graphics g) {
// Draw the monster image at our position
 
if(position.y >= 0)
{
g.drawImage(arrayListOfImages.get(0), (int)position.x, (int)position.y, null);
 
}
if(position.y >= 50)
{
g.drawImage(arrayListOfImages.get(1), (int)position.x, (int)position.y, null);
}
if(position.y >= 100)
{
g.drawImage(arrayListOfImages.get(2), (int)position.x, (int)position.y, null);
}
 
}
}

#7warnexus

Posted 30 March 2013 - 10:15 PM

I am still in the process of learning how to animate images more efficiently on the screen. I want to bring my monster to life after seeing the monster move up and down statically for 2 months.

 

My thought process on animating the monster is to use a dynamic array like an ArrayList. While the animation looks correct on screen, the monster certainly moves like the monsters from the Mario game on NES. But I don't think the code implementation below is the way most people would do it most commonly. 

 

The image frames below are stored in an ArrayList of Images manually.

 

The Ghost uses 3 frames of animation which I quickly create using Paint: 

Ghost1_zps65e205e5.png

Ghost2_zpsc07170b1.png

Ghost3_zps32222b2c.png

 

The code draws a different images depending on what position the monster is on the screen. Once the position has been reached, the game draws a new image. The way the monster gets a new image is by using the get method while providing a hard-coded index argument of the image elements from the ArrayList of Images.

 

 

 
public class Ghost extends Sprite {
 
 
private Image image;

private ArrayList<Image> arrayListOfImages;
 

public Ghost(double x, double y) {
// TODO Auto-generated constructor stub
position = new Vector2D(x,y);
velocity = new Vector2D();
 
 
arrayListOfImages = new ArrayList<Image>();
 
try 
{
image = ImageIO.read(new File("src/Ghost/Ghost1.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost2.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost3.PNG"));
arrayListOfImages.add(image);
} 
catch (IOException e) {
e.printStackTrace();
}
 
}
 

public void draw(Graphics g) {
// Draw the monster image at our position
 
if(position.y >= 0)
{
g.drawImage(arrayListOfImages.get(0), (int)position.x, (int)position.y, null);
 
}
if(position.y >= 50)
{
g.drawImage(arrayListOfImages.get(1), (int)position.x, (int)position.y, null);
}
if(position.y >= 100)
{
g.drawImage(arrayListOfImages.get(2), (int)position.x, (int)position.y, null);
}
 
}
}

#6warnexus

Posted 30 March 2013 - 10:14 PM

I am still in the process of learning how to animate images more efficiently on the screen. I want to bring my monster to life after seeing the monster move up and down statically for 2 months.

 

My thought process on animating the monster is to use a dynamic array like an ArrayList. While the animation looks correct on screen, I don't think the code implementation below is the way most people would do it most commonly. 

 

The image frames below are stored in an ArrayList of Images manually.

 

The Ghost uses 3 frames of animation which I quickly create using Paint: 

Ghost1_zps65e205e5.png

Ghost2_zpsc07170b1.png

Ghost3_zps32222b2c.png

 

The code draws a different images depending on what position the monster is on the screen. Once the position has been reached, the game draws a new image. The way the monster gets a new image is by using the get method while providing a hard-coded index argument of the image elements from the ArrayList of Images.

 

 

 
public class Ghost extends Sprite {
 
 
private Image image;

private ArrayList<Image> arrayListOfImages;
 

public Ghost(double x, double y) {
// TODO Auto-generated constructor stub
position = new Vector2D(x,y);
velocity = new Vector2D();
 
 
arrayListOfImages = new ArrayList<Image>();
 
try 
{
image = ImageIO.read(new File("src/Ghost/Ghost1.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost2.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost3.PNG"));
arrayListOfImages.add(image);
} 
catch (IOException e) {
e.printStackTrace();
}
 
}
 

public void draw(Graphics g) {
// Draw the monster image at our position
 
if(position.y >= 0)
{
g.drawImage(arrayListOfImages.get(0), (int)position.x, (int)position.y, null);
 
}
if(position.y >= 50)
{
g.drawImage(arrayListOfImages.get(1), (int)position.x, (int)position.y, null);
}
if(position.y >= 100)
{
g.drawImage(arrayListOfImages.get(2), (int)position.x, (int)position.y, null);
}
 
}
}

#5warnexus

Posted 30 March 2013 - 10:10 PM

I am still in the process of learning how to animate images more efficiently on the screen. I want to bring my monster to life after seeing the monster move up and down statically for 2 months.

 

My thought process on animating the monster is to use a dynamic array like an ArrayList. While the animation looks correct on screen, I don't think the code implementation below is the way most people would do it most commonly. 

 

On a side note: can anyone tell me how the game Galaga and Space Invaders handle their animation? Those monsters animate themselves even when the monsters are fixed on screen!

 

The image frames below are stored in an ArrayList of Images manually.

 

The Ghost uses 3 frames of animation which I quickly create using Paint: 

Ghost1_zps65e205e5.png

Ghost2_zpsc07170b1.png

Ghost3_zps32222b2c.png

 

The code draws a different images depending on what position the monster is on the screen. Once the position has been reached, the game draws a new image. The way the monster gets a new image is by using the get method while providing a hard-coded index argument of the image elements from the ArrayList of Images.

 

 

 
public class Ghost extends Sprite {
 
 
private Image image;

private ArrayList<Image> arrayListOfImages;
 

public Ghost(double x, double y) {
// TODO Auto-generated constructor stub
position = new Vector2D(x,y);
velocity = new Vector2D();
 
 
arrayListOfImages = new ArrayList<Image>();
 
try 
{
image = ImageIO.read(new File("src/Ghost/Ghost1.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost2.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost3.PNG"));
arrayListOfImages.add(image);
} 
catch (IOException e) {
e.printStackTrace();
}
 
}
 

public void draw(Graphics g) {
// Draw the monster image at our position
 
if(position.y >= 0)
{
g.drawImage(arrayListOfImages.get(0), (int)position.x, (int)position.y, null);
 
}
if(position.y >= 50)
{
g.drawImage(arrayListOfImages.get(1), (int)position.x, (int)position.y, null);
}
if(position.y >= 100)
{
g.drawImage(arrayListOfImages.get(2), (int)position.x, (int)position.y, null);
}
 
}
}

#4warnexus

Posted 30 March 2013 - 10:06 PM

I am still in the process of learning how to animate images more efficiently on the screen. I want to bring my monster to life after seeing the monster move up and down statically for 2 months.

 

My thought process on animating the monster is to use a dynamic array like an ArrayList. While the animation looks correct on screen, I don't think the code implementation below is the way most people would do it most commonly. 

 

The image frames below are stored in an ArrayList of Images manually.

 

The Ghost uses 3 frames of animation which I quickly create using Paint: 

Ghost1_zps65e205e5.png

Ghost2_zpsc07170b1.png

Ghost3_zps32222b2c.png

 

The code draws a different images depending on what position the monster is on the screen. Once the position has been reached, the game draws a new image. The way the monster gets a new image is by using the get method while providing a hard-coded index argument of the image elements from the ArrayList of Images.

 

 

 
public class Ghost extends Sprite {
 
 
private Image image;

private ArrayList<Image> arrayListOfImages;
 

public Ghost(double x, double y) {
// TODO Auto-generated constructor stub
position = new Vector2D(x,y);
velocity = new Vector2D();
 
 
arrayListOfImages = new ArrayList<Image>();
 
try 
{
image = ImageIO.read(new File("src/Ghost/Ghost1.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost2.PNG"));
arrayListOfImages.add(image);
 
image = ImageIO.read(new File("src/Ghost/Ghost3.PNG"));
arrayListOfImages.add(image);
} 
catch (IOException e) {
e.printStackTrace();
}
 
}
 

public void draw(Graphics g) {
// Draw the monster image at our position
 
if(position.y >= 0)
{
g.drawImage(arrayListOfImages.get(0), (int)position.x, (int)position.y, null);
 
}
if(position.y >= 50)
{
g.drawImage(arrayListOfImages.get(1), (int)position.x, (int)position.y, null);
}
if(position.y >= 100)
{
g.drawImage(arrayListOfImages.get(2), (int)position.x, (int)position.y, null);
}
 
}
}

PARTNERS