I want to implement glide in my game but I don't know how. I know that the Glide format is:
Glide.with(context).load(R.drawable.image).into(imageView);
But I don't understand how to implement it in my game.class
Game.class:
public class Game extends SurfaceView { Player player; Paint paint; Bitmap image_player; public Game(Context context, AttributeSet attrs) { super(context, attrs); paint = new Paint(); image_player = BitmapFactory.decodeResource(getResources(), R.drawable.player); player = new Player(this, image_player); } public void onDraw(Canvas canvas) { paint.setColor(Color.BLACK); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); player.onDraw(canvas); invalidate(); } } Player.Class:
public class Player { private Game game; private Bitmap player; Paint paint; int x, y, start = 0, width, height, currentFrame = 0,Horizontal = 1, Vertical = 8, frameLengthInMilliseconds = 150, cantFrames = 8; long fps, timeThisFrame, lastFrameChangeTime = 0; public Player(Game juego, Bitmap player){ this.game = game; this.player = player; this.width = player.getWidth() / Vertical; this.height = player.getHeight() / Horizontal; paint = new Paint(); } private void update() { long startFrame = System.currentTimeMillis(); if (startFrame > lastFrameChangeTime + frameLengthInMilliseconds) { lastFrameChangeTime = startFrame; currentFrame++; if (currentFrame >= cantFrames) { currentFrame = 0; } } long startFrameTime = System.currentTimeMillis(); timeThisFrame = System.currentTimeMillis() - startFrameTime; if (timeThisFrame >= 1) { fps = 1000 / timeThisFrame; } } public void onDraw(Canvas canvas) { update(); int srcX = currentFrame * width; int srcY = height * start; x = canvas.getWidth()/2; y = canvas.getHeight()/2; Rect src = new Rect(srcX, srcY, srcX + width, srcY + height); Rect dst = new Rect(x, y, x + width, y + height); canvas.drawBitmap(player, src, dst, null); } } XML:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <com.example.agusv.MyProject.Game android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent"/> </android.support.constraint.ConstraintLayout>