I'm a beginner in AndEngine developing, but I want to share this function that I made, to build a Grid on the screen.
Using java Syntax Highlighting
- public Line buildGrid(int pWidth, int pHeight, float pRed, float pGreen, float pBlue){
- Line grid = new Line(0, 0, 0, pHeight);
- grid.setColor(0.5f, 0.5f, 0.5f);
- int cont = 0;
- while(cont < pWidth){
- cont += 10;
- grid.attachChild(new Line(cont, 0, cont, pHeight));
- grid.getLastChild().setColor(pRed, pGreen, pBlue);
- }
- cont = 0;
- while (cont < pHeight){
- cont += 10;
- grid.attachChild(new Line(0, cont, pWidth, cont));
- grid.getLastChild().setColor(pRed, pGreen, pBlue);
- }
- return grid;
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
The pWidth and pHeight params indicates the size of the Grid (the entire screen, for example), and the other params indicates the color of the lines.
You can use this just attaching the result to the scene.
Using java Syntax Highlighting
- scene.attachChild(buildGrid(CAMERA_WIDTH, CAMERA_HEIGHT, 0.9f, 0.9f, 0.9f));
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Enjoy!
