Jump to content

GetPixel trouble.


Recommended Posts

Hi there, im develong a game with ink. They are some planets and you shoot ink on them and then you conquer them. I use a temporal bitmapdata do draw render texture planets on it to use bitmapdata getpixel method to get if the planet is completely of a color (or almost). Im wondering if theres a better method because this is so laggy.

Theres a way to get a pixel from renderTexture?

conquer: function(p) {
        //I draw planet renderTexture on bmd  bitmapdata to allow the getpixel function
        //Points of the planet to get pixels.
        col = [];
        col[0] = bmd.getPixelRGB(10,p.radio); //izquierda - centro
        col[1] = bmd.getPixelRGB(((p.radio*2)-10),p.radio);
        col[2] = bmd.getPixelRGB(p.radio,10); //centro - arriba
        col[3] = bmd.getPixelRGB(p.radio,((p.radio*2)-10));

        if (col[0].rgba === col[1].rgba && col[2].rgba === col[0].rgba && col[0].rgba === col[3].rgba){
            var c = 0;
            if(col[0].rgba === 'rgba(0,0,255,1)') c = 1;
            var colorPlanet = [];

            switch(c) {
                case 0:
                    colorPlanet[0] = 0x550000; //Shadow color
                    colorPlanet[1] = 0xAA0000; //Shadow color2
                    colorPlanet[2] = 0xFF0000;
                case 1:
                    colorPlanet[0] = 0x000055;
                    colorPlanet[1] = 0x0000AA;
                    colorPlanet[2] = 0x0000FF;
            //Shadow color
            pintData.drawCircle(0, 0, p.radio*2);
            //Shadow color 2
            pintData.drawCircle(0, 0, p.radio*2);
            //Planet color
            pintData.drawCircle(0, 0, p.radio*2);

Thats the code, i use it to check if the planet points (col[0], col[1], col[2] and col[3]) are of the same color, then if they are same color y draw on the planet renderTexture (p.capaPintura) colors of the conquerer ink.


this is the planet after being conquerer by the blue team, the code works, but i have to use the conquer function once every time a planet is hit by ink or it wont work.. and its so laggy, theres a method to do it just with render textures?, i have to draw the planet renderTexture on bmd just to use getPixel, so if the planet is bigger then bigger is the lag i get because of that draw... .

Link to comment
Share on other sites

I would do it this way: I would store the number of blue pixels in a variable(bluePixels), and before drawing the blue circle, I would check the pixels inside that circle and increase bluePixels accordingly. When bluePixels == totalPixels - player wins. That way you won't have to check the whole planet after every drawing.

Make sure you use Canvas renderer, getPixel with WebGL renderTexture is gonna be very slow.


Link to comment
Share on other sites

ty, but my trouble is that i only know of BitmapData getPixel, and because of that i have to draw the renderTexture i want to check in a bitmapData just to use BitmapData.getPixel(). I cant find any RenderTexture.getPixel function. So because of that draw of the entire planet on the bitmapdata to call getPixel funtion i get tons of lag.

Link to comment
Share on other sites

Why do you need a RenderTexture? In CanvasRenderer, BitmapData and RenderTexture are basically the same thing(they are both canvas elements), so you are just copying one canvas to another. RenderTexture is useful for WebGL, but in this case you should not use WebGL anyway.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...