Skip to main content
deleted 210 characters in body
Source Link
Stevanicus
  • 141
  • 1
  • 1
  • 5

UPDATE & SOLUTION

I've identified the problem. And it is the fact that my player updates the same rate as the background scrolls (making it look choppy). from top to bottom. This is because both get drawn in the same function. I'm not really sure how to tackle this and would be gratefulThank you for any help. ieveryone helping me.e so that player movement is handled separately from the map scrolling

Also how can I control the speed at which onDraw(canvas) get called?came across this:

Thanks in advance.post http://stackoverflow.com/questions/1430741/how-to-draw-lots-of-bitmaps-on-screen-in-an-android-game-without-slow-performance

Helped my problem a lot. However, Seemed I have patched together a different run loop for anyone havingwas creating bitmaps in the same problem. ThisonDraw every time is partially fromwas caused, meaning that was doing 95% of the jetboy example on googleslowing down. oops :)

Below is my inner class in my surfaceview for reference purposes

UPDATE

I've identified the problem. And it is the fact that my player updates the same rate as the background scrolls (making it look choppy). from top to bottom. This is because both get drawn in the same function. I'm not really sure how to tackle this and would be grateful for any help. i.e so that player movement is handled separately from the map scrolling

Also how can I control the speed at which onDraw(canvas) get called?

Thanks in advance.

However, I have patched together a different run loop for anyone having the same problem. This is partially from the jetboy example on google.

Below is my inner class in my surfaceview

UPDATE & SOLUTION

Thank you for everyone helping me. I came across this:

post http://stackoverflow.com/questions/1430741/how-to-draw-lots-of-bitmaps-on-screen-in-an-android-game-without-slow-performance

Helped my problem a lot. However, Seemed I was creating bitmaps in the onDraw every time is was caused, meaning that was doing 95% of the slowing down. oops :)

Below is my inner class in my surfaceview for reference purposes

updated question; added 89 characters in body; added 23 characters in body
Source Link
Stevanicus
  • 141
  • 1
  • 1
  • 5

UPDATE

I've identified the problem. And it is the fact that my player updates the same rate as the background scrolls (making it look choppy). from top to bottom. This is because both get drawn in the same function. I'm not really sure how to tackle this and would be grateful for any help. i.e so that player movement is handled separately from the map scrolling

Also how can I control the speed at which onDraw(canvas) get called?

Thanks in advance.

However, I have patched together a different run loop for anyone having the same problem. This is partially from the jetboy example on google.

Below is my inner class in my surfaceview

class MapThread extends Thread{
    private Map map;
    private SurfaceHolder holder;
    private boolean run = false;
    
    public MapThread(Map map, SurfaceHolder holder){
        this.holder = holder;
        this.map = map;
        setRunning(true);
    }
    
    public void setRunning(boolean run){
        this.run = run;
    }
    
    @Override
    public void run(){
        while(run){
            try{
                Canvas c = null;

                 try {
                       c = holder.lockCanvas(null);
                       synchronized (holder) {
                            map.onDraw(c);
                     }
                 } finally {

                     if (c != null) {
                         holder.unlockCanvasAndPost(c);
                     }
                 }
        }
    }
}

UPDATE

I've identified the problem. And it is the fact that my player updates the same rate as the background scrolls (making it look choppy). from top to bottom. This is because both get drawn in the same function. I'm not really sure how to tackle this and would be grateful for any help. i.e so that player movement is handled separately from the map scrolling

Also how can I control the speed at which onDraw(canvas) get called?

Thanks in advance.

However, I have patched together a different run loop for anyone having the same problem. This is partially from the jetboy example on google.

Below is my inner class in my surfaceview

class MapThread extends Thread{
    private Map map;
    private SurfaceHolder holder;
    private boolean run = false;
    
    public MapThread(Map map, SurfaceHolder holder){
        this.holder = holder;
        this.map = map;
        setRunning(true);
    }
    
    public void setRunning(boolean run){
        this.run = run;
    }
    
    @Override
    public void run(){
        while(run){
            try{
                Canvas c = null;

                 try {
                       c = holder.lockCanvas(null);
                       synchronized (holder) {
                            map.onDraw(c);
                     }
                 } finally {

                     if (c != null) {
                         holder.unlockCanvasAndPost(c);
                     }
                 }
        }
    }
}
Source Link
Stevanicus
  • 141
  • 1
  • 1
  • 5
Loading