Navigation

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

    Making a gun that shoots

    Beginners
    5
    13
    542
    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.
    • A
      AtomAlexander F last edited by

      Side scrolling and 2 d I'm a sprite based guy not good enough at coding to make 3d stuff lol 😂

      1 Reply Last reply Reply Quote 1
      • M
        Maxwello F last edited by

        So you just want to add a gun into the animation right?

        1 Reply Last reply Reply Quote 1
        • A
          AtomAlexander F last edited by pianofire

          Yes but I only want the gun to appear when sprite is aiming. (like only when holding be and then only fire when shoulder button is pressed for example)

          1 Reply Last reply Reply Quote 0
          • M
            Maxwello F last edited by Maxwello

            Part 2 of the video tutorial on sprites gets to this near the end.
            State variable within an array of animation data? Or something

            1 Reply Last reply Reply Quote 2
            • A
              AtomAlexander F last edited by

              OK I'll re-watch that video

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

                @AtomAlexander youl have different states for your sprite(character)
                like ;
                idle = 0
                walk= 1

                ect
                and then your have your animation for those states

                so add a state
                draw gun = 2
                then for your animation choose the tiles with that state in
                for shooting check out a sample or users project and see how they did it

                1 Reply Last reply Reply Quote 3
                • Dave
                  Dave Fuze Team last edited by

                  Everyone's correct here :) You'll need a a few different states and that should manage everything you need.

                  Are you planning on drawing the sprites yourself with the image editor or using the built-in assets? I'm also wondering what you mean by "aiming"..

                  If you want to simply shoot straight across the screen, you'll need only to increase the bullet's x position.

                  If you want to "aim" and shoot in a direction, it's a little different. Still simple, but it involves using something called normalize(). I'm super happy to explain it here, but I won't overload you with info that isn't relevant to what your goal is!

                  Let me know and I'll put together a post.

                  1 Reply Last reply Reply Quote 1
                  • A
                    AtomAlexander F last edited by

                    I'm making my own sprites and yes the bullets will only be traveling along the x axis I call it among because I don't want h to have the gun out and showing unless you press the button to upholster it. Also the gun it's a different separete sprite

                    1 Reply Last reply Reply Quote 0
                    • Dave
                      Dave Fuze Team last edited by

                      Alright - well it sounds like you'd make us of setSpriteVisibility() on the gun itself, so you might have a button press which sets the visibility of the gun sprite. Let's say you had (in this example code I'm assuming your gun sprite is create and stored in "gunSprite":

                      In your game loop:

                      if c.zl then
                          playerSprite.aim = true // set a flag in the sprite properties so the game knows the sprite is aiming
                          setSpriteVisibility(gunSprite, true)
                      else
                          playerSprite.aim = false
                          setSpriteVisibility(gunSprite, false)
                      endif
                      

                      This would be alright, but the problem would be that for every frame the ZL button is held, you are setting visibility and the aiming flag. An improvement could make use of the "rising and falling edge" concept in the sprite tutorial part 2 video:

                      You'll need a global controls and "old" controls variable:

                      c = controls(0)
                      old_c = c
                      

                      You will also want to make sure your gunSprite visibility and player aiming property are set to false before you enter the main loop:

                      setSpriteVisibility(gunSprite, false)
                      playerSprite.aim = false
                      

                      Then, in your main loop

                      // before you do anything with controls, read them:
                      c = controls(0)
                      
                      // check if ZL is pressed and wasn't pressed on the previous frame (when you initially press the button):
                      if c.zl and !old_c.zl then
                          playerSprite.aim = true
                          setSpriteVisibility(gunSprite, true)
                      endif
                      
                      // check to see if ZL is not held and was held on the previous frame (when you let go of the button)
                      if !c.zl and old_c.zl
                          playerSprite.aim = false
                          setSpriteVisibility(gunSprite, false)
                      endif
                      
                      // after you've done everything you want, before you draw things, store the old state of the controls:
                      old_c = c
                      

                      This way, you only set the visibility and aim state to the correct values once, when the button is pressed or let go of.

                      There will be much more in terms of the shooting and processing bullets, but this is a core concept which will help!

                      1 Reply Last reply Reply Quote 3
                      • A
                        AtomAlexander F last edited by

                        You guys are the best thanks for all the help

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