1

So Im creating my first 2d java game and im wondering how to have it seem as if the player is standing on a platform if it lands on it. The problem lies in the fact that in my game the "NINJA" is always at the center of the screen and never moves but just the background and platforms do. Any ideas on how to solve the problem?

  r=background

  rectx=backgroundx

  recty=backgroundy

  block=platform

  blockx=platformx

  blocky=platformy

my code

    if ((jumping == true)) {

                    recty = recty + 3;
                    r.setY(recty);
                    blocky = blocky + 3;
                    block.setY(blocky);
                    rectx = rectx - 5;
                    r.setX(rectx);
                    blockx = blockx - 5;
                    block.setX(blockx);
                    ninjarun1.setImage(imgjumpingninja);

                    if (jumpforce == 0) {
                        ninjarun1.setImage(imgninjafalling);

                        recty = recty - 3;
                        r.setY(recty);
                        rectx = rectx - 5;
                        r.setX(rectx);
                        blockx = blockx - 5;
                        block.setX(blockx);
                        blocky = blocky - 3;
                        block.setY(blocky);

                    }

                }

                //rightrunning 
                if ((jumping == false)) {

                    blocky = 300;
                    block.setY(blocky);

                    recty = 0;
                    r.setY(recty);




                }
rashadbb
  • 31
  • 1
  • 6
  • So, you've just described back "collision detection". As the character is moving, you need to determine if they collide with anything, you then need to determine "where" collision took place (ie at their head or feet) and change the state accordingly – MadProgrammer Jan 26 '18 at 21:35
  • See related: [Checking Collision of Shapes with JavaFX](https://stackoverflow.com/questions/15013913/checking-collision-of-shapes-with-javafx). – jewelsea Jan 26 '18 at 22:37

0 Answers0