This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very basic problem

 
vishwas bhatt
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I want to scroll image on keyrepeated function for that i am incrementing x axis of image in keyrepeated function and drawing the image in paint method
public void paint(Graphics g)
{
g.drawImage(img,x,0,Graphics.TOP|Graphics.TOP);
display.callSerially(this)l
}
public void KeyRepeated(int keycode)
{
if(getGameAction(keycode) == RIGHT)
{
x++;
}
}
code is working is fine but on keyrepeat action it gives me a jerking scroll it not smooth. but if i use x++ in paint method then it gives me perfect smooth scroll. i want the same smooth scroll in keyrepeated action pls tell me how to do this.
thanx
wating for reply
 
David Price
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you calling 'repaint' each time you do 'x++'? Maybe you could just add the method call 'repaint();' after that 'x++;' line in your method keyRepeated? If you call repaint less frequently than you do x++, then naturally the result will be jerky.
Remember that not all phones support key repeats (you can check by calling Canvas's method 'hasRepeatEvents'). And different phones generate repeat events at different rates, which might be a problem for your scrolling.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic