Guys, you need the object to move and leave a trail
To do this, draw the next element (trace) with the previous tracks, which the main character has already left
Tell me, how can this be implemented in libGDX?
Very desirable sample code.
If necessary, my implementation of the movement of the hero and the class where this should all happen: level (Here the implementation of the movement with the swipe)
package com.bellkross.ggame.gameLevels; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.math.Rectangle; import static com.bellkross.ggame.states.MenuState.HEIGHT; import static com.bellkross.ggame.states.MenuState.WIDTH; public class Level { public static OrthographicCamera camera; public static final int VELOCITY = 100; public static final int SWIPE_LIMIT = 20; public static int first_x,first_y,dx,dy; public static float ggHeight, ggWidth; public static Texture gg,lineGG;//glavniy geroy public static Texture standart_background; public static Texture[] levelBackgrounds; public static Rectangle mh;//main hero public static InputProcessor LEVEL_INPUT_PROCESSOR; public Level(){ levelBackgrounds = new Texture[10]; levelBackgrounds[0]= new Texture("lvl1B.png"); camera = new OrthographicCamera(); camera.setToOrtho(false, WIDTH, HEIGHT); standart_background = new Texture("gameBackground.png"); gg = new Texture("gg30.png"); lineGG = new Texture("line.png"); ggHeight = gg.getHeight(); ggWidth = gg.getWidth(); mh = new Rectangle(0, HEIGHT - ggHeight, ggWidth, ggHeight); LEVEL_INPUT_PROCESSOR = new InputProcessor() { /*touchDown():ΠΌΠ΅ΡΠΎΠ΄ Π²ΡΠ·ΡΠ²Π°Π΅ΡΡΡ, ΠΊΠΎΠ³Π΄Π° ΠΏΠ°Π»Π΅Ρ ΠΊΠΎΡΠ½ΡΠ»ΡΡ ΡΠΊΡΠ°Π½Π° ΠΈΠ»ΠΈ Π±ΡΠ»Π° Π½Π°ΠΆΠ°ΡΠ° ΠΊΠ½ΠΎΠΏΠΊΠ° ΠΌΡΡΠΈ. * Π‘ΠΎΠΎΠ±ΡΠ°Π΅Ρ ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΈΠ΅ ΠΈΠ·Π²Π΅ΡΡΠ½ΡΠ΅ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ.*/ @Override public boolean touchDown(int x, int y, int pointer, int button) { first_x = x; first_y = y; return true; } /*touchDragged(): ΠΌΠ΅ΡΠΎΠ΄ Π²ΡΠ·ΡΠ²Π°Π΅ΡΡΡ, ΠΊΠΎΠ³Π΄Π° ΠΏΠ°Π»Π΅Ρ ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ°Π΅ΡΡΡ ΠΏΠΎ ΡΠΊΡΠ°Π½Ρ * ΠΈΠ»ΠΈ ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ°Π΅ΡΡΡ ΠΌΡΡΡ Ρ Π½Π°ΠΆΠ°ΡΠΎΠΉ ΠΊΠ½ΠΎΠΏΠΊΠΎΠΉ.*/ @Override public boolean touchDragged(int second_x, int second_y, int pointer) { dx = second_x - first_x; dy = second_y - first_y; return true; } @Override public boolean scrolled(int amount) { return false; } @Override public boolean keyDown(int keycode) { return false; } @Override public boolean keyUp(int keycode) { return false; } @Override public boolean keyTyped(char character) { return false; } @Override public boolean mouseMoved(int x, int y) { return false; } @Override public boolean touchUp(int x, int y, int pointer, int button) { return false; } }; } /**Π Π΅Π°Π»ΠΈΠ·Π°ΡΠΈΡ Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΡ Π³Π³ * @param mh ΠΊΠ²Π°Π΄ΡΠ°Ρ Π³Π³ * @param dx * @param dy*/ public static void handleInput(Rectangle mh,int dx, int dy){ if(dx>0){ if(dx>Math.abs(dy)) Level.moveRight(mh,dx);//move right if(dy>=0) { if (Math.abs(dx) < dy) Level.moveUp(mh,dy);//move up }else if(Math.abs(dx)<Math.abs(dy)) Level.moveDown(mh,dy);//move down }else{ if(dx==0) if(dy>0) Level.moveUp(mh,dy);//move up else Level.moveDown(mh,dy);//move down if(dx<0){ if(Math.abs(dx)>Math.abs(dy)) Level.moveLeft(mh,dx);//move left if(dy>=0){ if(Math.abs(dx)<Math.abs(dy)) Level.moveUp(mh,dy);//move up }else if(Math.abs(dx)<Math.abs(dy)) Level.moveDown(mh,dy);//move down } } } public static void moveUp(Rectangle mh, int dy){ if(Math.abs(dy)>=SWIPE_LIMIT&&mh.y>0) mh.y -= VELOCITY * Gdx.graphics.getDeltaTime(); } public static void moveDown(Rectangle mh, int dy){ if(Math.abs(dy)>=SWIPE_LIMIT&&mh.y<HEIGHT-mh.getHeight()) mh.y += VELOCITY * Gdx.graphics.getDeltaTime(); } public static void moveRight(Rectangle mh, int dx){ if(Math.abs(dx)>=SWIPE_LIMIT&&mh.x<WIDTH-mh.getWidth()) mh.x += VELOCITY * Gdx.graphics.getDeltaTime(); } public static void moveLeft(Rectangle mh, int dx){ if(Math.abs(dx)>=SWIPE_LIMIT&&mh.x>0) mh.x -= VELOCITY * Gdx.graphics.getDeltaTime(); } } Level_1 (Here the object moves and must leave the line behind itself)
package com.bellkross.ggame.gameLevels; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Rectangle; import com.bellkross.ggame.states.GameStateManager; import com.bellkross.ggame.states.State; import static com.bellkross.ggame.gameLevels.Level.lineGG; import static com.bellkross.ggame.gameLevels.Level.standart_background; import static com.bellkross.ggame.gameLevels.Level.dx; import static com.bellkross.ggame.gameLevels.Level.dy; import static com.bellkross.ggame.gameLevels.Level.gg; import static com.bellkross.ggame.gameLevels.Level.LEVEL_INPUT_PROCESSOR; import static com.bellkross.ggame.gameLevels.Level.mh; import static com.bellkross.ggame.gameLevels.Level.levelBackgrounds; import static com.bellkross.ggame.states.MenuState.HEIGHT; import static com.bellkross.ggame.states.MenuState.WIDTH; public class Level_1 extends State{ private Texture e1; private Rectangle e1_r; private float e1Height, e1Width; private Level level; public Level_1(GameStateManager gsm) { super(gsm); level = new Level(); e1 = new Texture("gg30.png"); e1Height = e1.getHeight(); e1Width = e1.getWidth(); e1_r = new Rectangle(WIDTH/2 - e1Width/2, HEIGHT/2-e1Height/2,e1Width,e1Height); Gdx.input.setInputProcessor(LEVEL_INPUT_PROCESSOR); } @Override public void update(float dt) { Level.handleInput(mh,dx,dy); } @Override public void render(SpriteBatch sb) { sb.setProjectionMatrix(Level.camera.combined); sb.begin(); sb.draw(levelBackgrounds[0], 0, 0, WIDTH, HEIGHT); sb.draw(standart_background, 0, 0, WIDTH, HEIGHT); sb.draw(gg, mh.x, mh.y); sb.draw(e1,e1_r.x,e1_r.y); sb.end(); } @Override public void dispose() { levelBackgrounds[0].dispose(); standart_background.dispose(); gg.dispose(); e1.dispose(); lineGG.dispose(); } @Override protected void handleInput() {} }