So i have a canvas, that is the resolution of my device's screen, but i want to make a pixelated effect... Kinda like what is happening in the game: Eliss Infinity.
I have tried to make an int[][] and then draw the colors with a 'for' loop in my render method, but that makes my pretty high end device(Oneplus One) slow down to 20 - 30 fps instead of 60.
This is what i've done:
package com.ccxi11.protecter;
import android.graphics.Canvas;
import android.graphics.Paint;
public class PixelHandler {
private float widthScale, heightScale;
private int width, height;
private int[][] colors;
public PixelHandler(int width, int height) {
widthScale = Display.getScreenWidth() / width;
heightScale = Display.getScreenHeight() / height;
this.width = width;
this.height = height;
colors = new int[width][height];
}
public void render(Canvas c, Paint p) {
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++) {
p.setColor(colors[x][y]);
c.drawRect(x * widthScale, y * heightScale, x * widthScale + widthScale, y * heightScale + heightScale, p);
}
}
}
public void setColor(int x, int y, int color) {
colors[x][y] = color;
}
public int getColor(int x, int y) {
return colors[x][y];
}
}
Is there a way where i can draw the individual pixels without everything being laggy?
-Rasmus
0 comments:
Post a Comment