Android : android program freezes/glitches for half second every 6-8 seconds

on Thursday, January 8, 2015


I'm fairly new to Android and Java and I'm working on my first game.


The game seems to temporarily stop every 6-8 seconds for about half a second. I'm working on a platform game where timing is everything, so glitches make the game unplayable :(


Is this a known issue with garbage collection, or some background task? I've tried booting to safe mode and using a different phone but does the same thing.


Loading the sprite:



public void load() {
mysprite = new Sprite(this);
mysprite_image = new Texture(this);
if (!mysprite_image.loadFromAsset("mysprite_sprite_sheet.png")) {
fatalError("Error loading sprite_sheet");
}
mysprite.setTexture(mysprite_image);
}


The main loop of my test program just does this:



public void draw() {
canvas = getCanvas();

canvas.drawColor(Color.BLACK);

for (int i=0; i<20; i++) {
if (x[i] + vx[i] <= 0 || x[i] + vx[i] + 60 >= screenWidth) vx[i] *= -1;
if (y[i] + vy[i] <= 0 || y[i] + vy[i] + 60 >= screenHeight) vy[i] *= -1;
x[i] += vx[i];
y[i] += vy[i];

mysprite.position = new Point(x[i], y[i]);
drawSheetFrame(mysprite, 20, 29, 1, myspriteFrame, 4);
}
}


draw() is called in-between locking and unlocking the canvas.


0 comments:

Post a Comment