Navigation

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

    Loading Sprites into a Project

    Help
    3
    4
    243
    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.
    • K
      kendog400 F last edited by MikeDX

      I would like to load a sprite sheet from the kenney / board games into a project. A deck of cards. I'm still trying to figure out how..
      Is there any tutorial or help I could find ? This photo upload is from Untied Games.....!

      alt text

      This would help very much, and would help me get the ball rolling.......In Codea / lua they would have Hearts, Spades, Diamonds and Clubs in a section with other icons, and you would make an Array for your deck of cards, here in Fuze you would have to use a sprite sheet.....Which is fine if I only knew how..

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

        @kendog400 Hi have a look at this example of how to chop an image up into separate sprites https://fuzearena.com/forum/topic/437/fun-with-sprites/7

        If the image is tiled like this one you can use gettilesize to find the size of a tile

        ts = gettilesize(image, n) // ts is tilesize n is the tile number
        

        A sprite can also have associated variables so you could have:

        sprite.suit = "Hearts"
        sprite.value=9

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

          I find that using the sprite commands works well when there are lots of animation frames, but given that each card is only a single frame - you might find it simpler to use the drawSheet function. https://fuzearena.com/help/view/drawSheet

          You might want your program to start something like:

          // load the image file
          sheet = loadImage("Untied Games/Playing cards")
          
          // create a structure type for a card, used for the deck, hands, revealed cards, etc
          struct card_type
              str suit
              int val
              vec pos
              int img
          endstruct
          
          // now when we declare an array using the card_type, each element has all those properties above.
          card_type deck[52]
          
          // We could manually setup the data or use a loop that went over each suit and set the properties for each card:
          
          i = 9 // this is the number of the first card image tile in the sprite sheet
          c = 0 // deck array index
          for suit = 0 to 4 loop // loop over each suit
              for value = 1 to 14 loop // loop over each card in the suit
                      if suit == 0 then deck[c].suit = "Clubs" endif
                      if suit == 1 then deck[c].suit = "Diamonds" endif
                      if suit == 2 then deck[c].suit = "Hearts" endif
                      if suit == 3 then deck[c].suit = "Spades" endif
                      deck[c].val = value // set the value of the card to the value counter 
                      if deck[c].val > 10 then deck[c].val = 10 endif // cap the value off at 10, if this was blackjack for instance
                      deck[c].img = i // set the image tile number from the spritesheet
                      i += 1 // increase the img counter
                      c += 1 // increase the card counter
              repeat
          repeat
          

          We can then use the .img property of any card in the deck array to index the drawSheet function to draw cards

          // draw a random card in the middle of the screen at a scale of 4:
          scale = 4
          width = tileSize( sheet, 0 ).x * scale
          height = tileSize( sheet, 0 ).y * scale
          c = random(52)
          drawSheet( sheet, deck[c].img, { gwidth()/2, gheight()/2, width, height}  )
          update()
          sleep(100) // I have to go to bed
          

          I'm sure there are simpler ways to get started but this is the sort of setup I would use. I think it gives you everything you need in a handy place. Let me know if you want any of it elaborated on I tried to be thorough in the comments.

          1 Reply Last reply Reply Quote 1
          • K
            kendog400 F last edited by

            Very helpful, I will be at the drawing board soaking this up..If I have to much trouble, I'LL be back to ask for a demo of the random card. But I'LL try to figure this out 1st...

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