Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Player in the middle of the screen when he walks

    Help
    4
    21
    888
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • waldron
      waldron F @Skullo last edited by

      @skullo drawsheet() is used for images so would behave differently any particular reason you want to use drawsheet over drawsprite's()?

      Skullo 1 Reply Last reply Reply Quote 0
      • Skullo
        Skullo @waldron last edited by Skullo

        @waldron Yeah, my sprite have 28 tiles for walking, attacking, etc... I have always worked with a state machine and drawSheet function to recreate animation and move the sprite over the map. In this new project I want the current player to be in the centre of the screen due to the map goes beyond the screen size so I need the camera to follow the current player when walking on the map. There would be more players on the map so I need to play with getSpriteLocation functions in order to calculate distances between them.

        1 Reply Last reply Reply Quote 0
        • R
          Richard F last edited by Richard

          @Skullo Is it the order that you're doing it? Currently you're changing the camera position based on the player position then updating the player position based on your state machine then drawing it. I think you need to update your player position then your camera position then do the drawing each time you go through the loop.

          Skullo 1 Reply Last reply Reply Quote 0
          • Skullo
            Skullo @Richard last edited by

            @richard It doesn't work either. I have the feeling that setSpriteCamera moves your sprites instead of moving itself. It is a bit weird. I don't know if someone else think the same.

            1 Reply Last reply Reply Quote 0
            • Skullo
              Skullo last edited by Skullo

              This video confirm my suspects about setSpriteCamera, the functions moves all your sprites. I just need the camera to follow the sprite that the player controls in order to have this sprite always in the centre of the screen, someone can help me?

              1 Reply Last reply Reply Quote 0
              • waldron
                waldron F last edited by

                If you want different targets for the camera I'd set up a variable and key which one you want it to follow. Wouldn't that work?

                1 Reply Last reply Reply Quote 0
                • waldron
                  waldron F last edited by

                  If followP == 0 then
                  Setspritecamera(p1.x,p1.y,1)
                  endif
                  So on

                  1 Reply Last reply Reply Quote 0
                  • Skullo
                    Skullo last edited by

                    The problem is that the camera doesn't follow the target but it moves the map so every sprite drawn moves along the camera :(

                    1 Reply Last reply Reply Quote 0
                    • Ben 2.0
                      Ben 2.0 last edited by

                      If setspritecamera() moves the map, then why not always draw the player at the same coordinates but still update player.x and player.y to update the camera. This may be the totally wrong way of looking at it but it could be a step in the right direction.

                      1 Reply Last reply Reply Quote 0
                      • Skullo
                        Skullo last edited by Skullo

                        Yeah, I'm drawing the current player at the centre of the screen and using player.x and player.y to update the camera. The problem comes when I try to draw the rest of sprites, if the camera moves, they all do. I need some kind of camera function that only moves the camera.

                        Edit: CentreSpriteCamera works fine when using DrawSprites, but in my project I have tiled images that need DrawSheet function to be drawn. Using CentreSpriteCamera along with DrawSheet produce the following wrong behaviour:

                        1 Reply Last reply Reply Quote 0
                        • R
                          Richard F last edited by

                          @Skullo you can use set sprite image in a very similar way to draw sheet.

                          setSpriteImage(handle, imageHandle, tileNumber)
                          

                          If you used sprites in this way, you could still use your state machine for the specific tile you wanted to show and they would work with the sprite camera along with your map.

                          Skullo 1 Reply Last reply Reply Quote 3
                          • Skullo
                            Skullo @Richard last edited by

                            @richard It works! Thank you very much everyone for your help!!!

                            1 Reply Last reply Reply Quote 1
                            • Skullo
                              Skullo last edited by Skullo

                              Below is the result. I'm planning on creating a Capture the Flag Game but I'm open to other ideas. Thanks again to everyone for your help.

                              1 Reply Last reply Reply Quote 5
                              • First post
                                Last post