Navigation

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

    collideMap() only in the main loop scope?

    Beginners
    collision sprites collidemap
    2
    5
    361
    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.
    • spikey
      spikey F last edited by spikey

      I couldn't find the problem, why my collision boxes had no effect. Then I realized, that calling collideMap(sprite) outside of my function, namely in the main loop, make them work. Did you make the same experience? If not I maybe have to change the order of function calls, or dig where the real problem lies in my code.

      Its a long time ago, I tried something with map collision, and the last time, I postponed the project, so I am a newbie to map collisions and this could be very obvious to you.

      This pseudo code worked: the collision boxes worked

      loadMap("level1") // a map with collision boxes I draw in the map editor
      // sprites[] is a global array of sprites
      // players is a global int with the number of sprites/players
      loop
         updateSprites()
         drawMap()
         for i = 0 to players loop
            collideMap(sprites[i])
         repeat
         drawSprites()
      repeat
      

      The following code caused the collision borders to be ignored.

      loadMap("level1") // a map with collision boxes I draw in the map editor
      // sprites[] is a global array of sprites
      // players is a global int with the number of sprites/players
      loop
         updateSprites()
         drawMap()
         for i = 0 to players loop
           updatePlayers(i)
         repeat
         drawSprites()
      repeat
      
      function updatePlayers(player)
         collideMap(sprites[i])
      return void
      
      1 Reply Last reply Reply Quote 0
      • spikey
        spikey F last edited by

        Gosh! it works now! After putting the function back in. So, sorry. But no clue, yet why.
        I get some coffee.

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

          Oh, I just found out how to make it fail again.
          If I do a getSpriteLocation() before the collideMap() call, the collision box have no effect and the sprite can walk through the boxes.

          This inhibits the collision boxes:

          pos = getSpriteLocation(sprite)
          collideMap(sprite)
          // do some clamping of the coordinates
          setSpriteLocation(sprite)
          

          This works:

          collideMap(sprite)
          pos = getSpriteLocation(sprite)
          // do some clamping of the coordinates
          setSpriteLocation(sprite)
          

          I think I just have to study these commands a bit more and read more example code.

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

            @spikey i usually drawmap() then updatesprites() the sprite location i put at the top of the loop so that shouldn't effect the collision not in my experience anyway maybe because the sprites are getting updated before the map

            1 Reply Last reply Reply Quote 1
            • spikey
              spikey F last edited by

              @waldron i appreciate that guidance. I will do it like this.

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