Frames
Hey, i am doing a stategic game for my java project, and i encountered a problem. You see, when i try to move a picture, with frames ( means that i can see the charater slowly get the requested location).
Last time i posted some body told me about DND and aftera little research found out that he didnt realized me.
well, i cant see why this isnt working. At first, i tried to repaint() the screen every time the chara moves. it is a futile :\. However, it "might" be not efficent, so if you have any other suggestments i'd be happy to hear :]
well
ill give you the code and tell me please what is wrong :\.
CODE:
//This is a listener to mouse clicks
this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e1) {
//getting the point where i want to charater go
Point point=new Point(e1.getPoint());
//distinguishing between the right and left buttons
if (e1.getButton()==1) {
//update X,Y of the chara "p" location untill e1.getPoint() and p location are the same
while ((point.equals(p.getLocation())==false)) {
if (point.getX()>p.getX()) {
p.setX(p.getX()+p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("1:"+p.getLocation()+ point+" "+(point.equals(p.getLocation())));
}//end of if
else {
if (point.getX()<p.getX()) {
p.setX(p.getX()-p.getSpeed());
try{Thread.sleep(2); } catch (Exception e) {};
System.out.println("2:"+p.getLocation()+point+" "+ (point.equals(p.getLocation())));
}//end of if
}//end of else
if (point.getY()>p.getY()) {
p.setY(p.getY()+p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("4:"+p.getLocation()+point+" "+(point.equals(p.getLocation())));
} //end of if
else{
if (point.getY()<p.getY()) {
p.setY(p.getY()-p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("3:"+p.getLocation()+point+(point.equals(p.getLocation())));
} //end of if
}//end of else
repaint();
}//end of while
}//end of the first if
//not working also but this isn't important for the topic.
//Supposed to show a list of possiblities for the player but fails
else {
String[] JCBtext = {"Guard", "Move", "Attack"};
JComboBox JCB=new JComboBox(JCBtext);
add(JCB,BorderLayout.CENTER);
JCB.setSelectedIndex(0);
JCB.setVisible(true);
}
//setFocus(this); //getting focus on the JComboBox (wrong command
}//end of public listener
});//end of listener
}
HELP :(>
[2724 byte] By [
Aviva] at [2007-10-2 3:14:01]

Hey, i am doing a stategic game for my java project, and i encountered a problem. You see, when i try to move a picture, with frames ( means that i can see the charater slowly get the requested location).
Last time i posted some body told me about DND and aftera little research found out that he didnt realized me.
well, i cant see why this isnt working. At first, i tried to repaint() the screen every time the chara moves. it is a futile :\. However, it "might" be not efficent, so if you have any other suggestments i'd be happy to hear :]
well
ill give you the code and tell me please what is wrong :\.
CODE:
//This is a listener to mouse clicks
this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e1) {
//getting the point where i want to charater go
Point point=new Point(e1.getPoint());
//distinguishing between the right and left buttons
if (e1.getButton()==1) {
//update X,Y of the chara "p" location untill e1.getPoint() and p location are the same
while ((point.equals(p.getLocation())==false)) {
if (point.getX()>p.getX()) {
p.setX(p.getX()+p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("1:"+p.getLocation()+ point+" "+(point.equals(p.getLocation())));
}//end of if
else {
if (point.getX()<p.getX()) {
p.setX(p.getX()-p.getSpeed());
try{Thread.sleep(2); } catch (Exception e) {};
System.out.println("2:"+p.getLocation()+point+" "+ (point.equals(p.getLocation())));
}//end of if
}//end of else
if (point.getY()>p.getY()) {
p.setY(p.getY()+p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("4:"+p.getLocation()+point+" "+(point.equals(p.getLocation())));
} //end of if
else{
if (point.getY()<p.getY()) {
p.setY(p.getY()-p.getSpeed());
try{Thread.sleep(2);} catch (Exception e) {};
System.out.println("3:"+p.getLocation()+point+(point.equals(p.getLocation())));
} //end of if
}//end of else
repaint();
}//end of while
}//end of the first if
//not working also but this isn't important for the topic.
//Supposed to show a list of possiblities for the player but fails
else {
String[] JCBtext = {"Guard", "Move", "Attack"};
JComboBox JCB=new JComboBox(JCBtext);
add(JCB,BorderLayout.CENTER);
JCB.setSelectedIndex(0);
JCB.setVisible(true);
}
//setFocus(this); //getting focus on the JComboBox (wrong command
}//end of public listener
});//end of listener
}
HELP :(>
sorry, thought code tags are the commets in the code...
well not its refixed..
sorry for the inconvenience...
Aviva at 2007-7-15 21:41:09 >
