This week's book giveaway is in the Security forum.
We're giving away four copies of Securing DevOps and have Julien Vehent on-line!
See this thread for details.
Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Very basic problem  RSS feed

 
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
 
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.
 
BWA HA HA HA HA HA HA! Tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!