Navigation

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

    Finding it hard to get enemies

    Help
    5
    27
    1675
    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.
    • lawyerlounge
      lawyerlounge last edited by lawyerlounge

      Thanks again for a great example. I noticed there was no use of drawSprites() in your loop. Is that possibly the reason I had issues with the animation not running?

      image = loadImage("filename")
      sprite = createSprite()
      setSpriteImage( sprite, image)
      
      startFrame = 0
      endFrame  = 10
      fps = 10
      
      Loop
            clear()
          
            setSpriteAnimation( sprite, startFrame, endFrame, fps)
      
            updateSprites()
            drawSprites()
      
            update()
      repeat
      

      I remember just trying to get the animation to work anywhere inside the loop (without any states or conditions) resulted in no movement at all. Is it because I was misusing some sort of update() command or drawSprites() command, and it kept redrawing the initial start frame and not allowing the animation to count up to 10 at 10 fps? I'm at work and away from my switch, but I believe I tried almost all combinations of including/excluding any update() draweSprites() and updateSprites() to no avail.

      Does that make sense though?

      pianofire 1 Reply Last reply Reply Quote 0
      • pianofire
        pianofire Fuze Team @lawyerlounge last edited by pianofire

        @lawyerlounge setSpriteAnimation() initializes the animation. If you call it in your game loop it will keep resetting it back to the beginning. The updateSprites() call is the one that will move the animation forward. drawSprites() will actually draw them into video memory and update() will render that to the screen.

        So this should work (let me know if it doesn't). You also need to set the sprite location using setSpriteLocation

        sprite = createSprite()
        setSpriteImage( sprite, image)
        setSpriteLocation(sprite, gwidth()/2, gheight()/2)
        startFrame = 0
        endFrame  = 10
        fps = 10
        setSpriteAnimation( sprite, startFrame, endFrame, fps)
        
        Loop
              clear()
            
        
              updateSprites()
              drawSprites()
        
              update()
        repeat
        
        1 Reply Last reply Reply Quote 0
        • Jonboy
          Jonboy Fuze Team last edited by

          Ha Waldron... "Finding it hard to get enemies".. I make new ones every day!

          Sorry.. can't be much more help than that at the moment. See what I mean.

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

            What is the main difference from Dave's example (2 posts up) and my example (which both at some point have the setSpriteAnimation() function inside of the main loop) that would cause his to work and mine not to.

            Other than having "if statements" (which basically change a variable called "state" which in turn changes the startFrame and endFrame vars for the arguments within setSpriteAnimation), and providing a check to see if the current state is not what it used to be, what causes the program in Dave's post to let the animation run from start to finish without constantly executing the beginning of the animation? (the problem you dissected within my example)

            Or is the method of checking if state != oldState required, because if you intend an animation to change throughout the main loop you need to find a way to only run it once at particular moments? And for any asset that doesn't need to change animations you would just use the setSpriteAnimation function before the main loop and set the visibility to false until needing to display?

            I think I've figured out the bare requirements for using sSA() in the loop... would this work?

            sprite = createSprite()
            setSpriteImage( sprite, image)
            setSpriteLocation(sprite, gwidth()/2, gheight()/2)
            startFrame = 0
            endFrame  = 10
            fps = 10
            
            animSwitch = true
            
            Loop
                  clear()
                 
                  currentFrame = getSpriteAnimFrame( sprite )
            
                  if animSwitch then
                        setSpriteAnimation( sprite, startFrame, endFrame, fps)
                        animSwitch = false
                  endif
            
                  if currentFrame >= endFrame then
                        animSwitch = true
                  endif
            
                  updateSprites()
                  drawSprites()
            
                  update()
            repeat
            

            P.S. thank you for all of the help teaching me something that must be simple for you guys!
            -MikeV

            pianofire 1 Reply Last reply Reply Quote 0
            • pianofire
              pianofire Fuze Team @lawyerlounge last edited by

              @lawyerlounge Not at all. That's what we are here for. Yes you only want to call setSpriteAnimation to change the current animation. The set animation will be repeated until a new one is set. If you want more control over the animation you can use setSpriteAnimFrame but you will have to control the speed yourself:

              https://fuzearena.com/help/view/setSpriteAnimFrame

              1 Reply Last reply Reply Quote 2
              • lawyerlounge
                lawyerlounge last edited by

                Nice! so my example should display the animation on loop? (not at home yet to test it)

                pianofire 1 Reply Last reply Reply Quote 0
                • pianofire
                  pianofire Fuze Team @lawyerlounge last edited by

                  @lawyerlounge Well I haven't tried it but yes it looks like it should

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

                    @Jonboy haha i must be to nice

                    1 Reply Last reply Reply Quote 1
                    • Jonboy
                      Jonboy Fuze Team last edited by

                      ha, but not TOO nice. See, i did it again. Seriously, you should not invite me to comment :-)

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

                        @lawyerlounge My bad! Completely forgot about perhaps the most important command, drawSprites(), in the example I gave.

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