testing is player is jumping or not jumping. falling or not falling.
i want to how when is my player is jumping, statding, or falling. for some reason it only goes in fall == true if statment.
in my paint method iam printing different images. bc testing what is player is doing.
i have main_class and player_class.
Code :
//in player class
public void paint(Graphics g)
{
if(jump == false)
{
//..print stand image
}
else if(jump == true)
{
//..print jump image
}
else if(fall == true)
{
//print fall image here
}
-------------------------------------------------------------------------------------------------------------
Code :
boolean jump = false;
boolean fall = true; //bc when game start player will fall down first
private double dy = 6.0; //change in y over time
private double gravity = 0.2;
in main method i keypress method. if i presss up key it will run hitJump() method from player_class
Code :
public void keyPressed(KeyEvent e)
{
int keys = e.getKeyCode();
if (keys == KeyEvent.VK_UP)
{
player_class.hitJUMP(ground_class);
}
//in player_class seting up hitJump method. this just set jump to true only if only is not jumping.
public void hitJUMP(Ground g)
{
if(jump == false)//if on ground
{
jump = true; //go in jump true if statment
dy = 6.0; //reset
}
}
Code :
//than also in player_class iam creating so my player will go up and down
//this method is in while loop. so it will keep on going.
public void PLAYER_MOVE(Main m, Ground g) //player move's
{
if(jump == true) //move dy up ..and than down..
{
dy -= gravity;
y -= dy;
if(y + height >= g.getY()) //if on ground set jump to false
{
jump = false;
fall = false;
}
}
else if(jump == false) //if player is not jumping so that mean player is falling
{
y += 4; //player falling speed
fall = true;
}
}
mostly i need help in paint method and player_move method. i know how to test when is my player is jumping or not jumping. but falling part is confusing to me. i need some ideas how can i test in paint method and player_move method when is my player is falling or not.
Re: testing is player is jumping or not jumping. falling or not falling.
Quote:
in my paint method iam printing different images. bc testing what is player is doing.
You should prepare and update an image based on what the player is doing when the player does something, not when it is time to paint the screen.
I press space bar, player jumps, image updates, speedY updates, everything changes...
When the paint method is called, you just paint the image made earlier with a call like:
player.drawYourself(g);
or:
g.drawImage(player.getImage(), player.posX, player.posY, observer);
Quote:
i need some ideas how can i test in paint method
Any time this thought crosses your mind, remember never make decisions on what to draw while drawing. Just draw what has been prepared. Prepare what to draw as the changes are made rather than during drawing time.