Moving a path with a repeating bitmap in android

I am currently writing a script to scroll in android, and I am having problems filling the path with a repeating bitmap. I create a path from several coordinates to make up the "earth". I have a character that is fixed in the middle of the canvas and screen, and I move the path to represent the movement of the character. I was able to fill the path with a repeating image using BitmapShader. I can also move the shape of the path from side to side on the screen. However, Bitmapshader seems to use an initial default value of 0.0, which means that the shader always draws a ground repeating image in the same place. This means that although the path moves, the re-image of the earth never moves. Somebody knows,How to change the origin of the shader or find out the best way to fill the path with a repeating image?

Alternatively, can anyone suggest a better solution for filling out a hand-drawn form with an image?

Thanks Andy

+3
source share
2 answers

Thanks, looked at them ... Replica Island seems to use quite a bit of OpenGL, which is currently slightly superior to me, and Snake didn’t quite do what he was looking for ... eventually got there ..

    //Shape pathShape = this.getPathShape();
    Bitmap groundImage = ImageHandler.getmGroundImage();
    int offset = groundImage.getWidth()-(xPosition%groundImage.getWidth());
    Path path = new Path();
    path.moveTo(coordinates.get(0).getmX(), coordinates.get(0).getmY());

    for ( ShapeCoordinate coordinate : coordinates ) {
        path.lineTo(coordinate.getmX(), coordinate.getmY());
    }

    path.lineTo(coordinates.get(coordinates.size()-1).getmX(), mYBase);
    path.lineTo(coordinates.get(0).getmX(), mYBase);
    path.lineTo(coordinates.get(0).getmX(), coordinates.get(0).getmY());
    path.close();

    PathShape shape = new PathShape(path,canvas.getWidth(),canvas.getHeight());

    BitmapShader bs = new BitmapShader(groundImage, Shader.TileMode.REPEAT,Shader.TileMode.REPEAT);

    Matrix matrix = new Matrix();
    matrix.reset();
    matrix.setScale(1,1);
    matrix.preTranslate(offset, 0);
    bs.setLocalMatrix(matrix);

    ShapeDrawable sd = new ShapeDrawable(shape);
    sd.setColorFilter(Color.argb(255, 50*(mLevel+1), 50*(mLevel+1), 50*(mLevel+1)), Mode.LIGHTEN);
    sd.getPaint().setShader(bs);
    sd.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    sd.draw(canvas);   
+2
source

Have you looked at Snake's example in Android-sdk? In addition, Replica Island is another example of how to make a tile engine in android.

0
source

Source: https://habr.com/ru/post/1764928/


All Articles