Navigation

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

    Fun with Sprites

    General Discussion
    6
    9
    436
    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.
    • pianofire
      pianofire Fuze Team last edited by

      1 Reply Last reply Reply Quote 4
      • Wanderer1412
        Wanderer1412 Donator last edited by

        Ohhhh - that is amazing
        Tutorial please! ... or code share?

        pianofire 2 Replies Last reply Reply Quote 0
        • pianofire
          pianofire Fuze Team @Wanderer1412 last edited by

          @Wanderer1412 Let me tidy it up a bit first then I will share it

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

            @pianofire That's cool! I also saw your sliding block puzzle last night and although its really neat.. I just wanted to slide those blocks back into place so much. haha

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

              @Wanderer1412 OK I have shared that. My friend code is SW-5218-2817-5887

              1 Reply Last reply Reply Quote 2
              • M
                MikeDX last edited by

                For those that want to look at the code before Colin accepts 100 friend requests:

                // Fun with Sprites Demo
                // by @pianofire 
                // Picture taken by me is Mallard, Green Arrow and Blue Peter @ Barrow Hill
                //
                // Number of tiles across 
                // Worked with 40 but was slow to create (1600 sprites)
                // 50 seemed to hang (2500 sprites!)
                tilesAcross = 20
                // Fit to height
                screenWidth = gHeight()
                // Padding to centre image
                xOffset = (gWidth() - screenWidth) / 2
                yOffset = (gHeight() - screenWidth) / 2
                // Initialize variables
                pictureSize = { 0, 0 }
                tileWidth = 0
                screenTileWidth = screenWidth / tilesAcross
                // Array of tiles
                array tiles[tilesAcross * tilesAcross]
                // Load image and create tiles
                picture = loadPicture("FUZE/Trains")
                printAt(0,0, "Creating Sprites...")
                update()
                tilePicture(picture)
                
                drawPicture()
                explodePicture()
                // Reverse 10X faster
                reverseExplosion(10)
                
                // Draw the picture
                function drawPicture()
                  for s = 0 to 1 step 0.02 loop // Rotate and scale the tiles to the screen
                    clear()
                    for i = 0 to len(tiles) loop
                      setSpriteScale(tiles[i], s, s)
                      setSpriteRotation(tiles[i], s * 360)
                    repeat
                    drawSprites()
                    update()
                  repeat  
                return void
                
                // load the picture from a file
                function loadPicture(imageName)
                  picture = loadImage(imageName, true)
                  pictureSize = imageSize( picture )
                  screenWidth = gHeight()
                  xOffset = (gWidth() - screenWidth) / 2
                  yOffset = (gHeight() - screenWidth) / 2
                  tileWidth = pictureSize.x / tilesAcross
                  screenTileWidth = screenWidth / tilesAcross
                return picture
                
                // Split the picture into tiles
                function tilePicture(picture)
                  for x = 0 to tilesAcross loop
                    for y = 0 to tilesAcross loop
                      sprite = createSprite()
                      tile = createImage(screenTileWidth, screenTileWidth, false, image_rgb)
                      setDrawTarget(tile)    
                      drawImage(picture, { x * tileWidth, y * tileWidth, tileWidth, tileWidth }, { 0, 0, screenTileWidth, screenTileWidth})  
                      update()
                      setSpriteImage(sprite, tile)
                      setSpriteLocation(sprite, x * screenTileWidth + xOffset, y * screenTileWidth + yOffset)
                      setSpriteOrigin(sprite, { -screenTileWidth / 2, -screenTileWidth / 2 } )
                      setSpriteScale(sprite, 1, 1)
                      sprite.saveX = sprite.x
                      sprite.saveY = sprite.y
                      sprite.id = y * tilesAcross + x
                      tiles[sprite.id] = sprite
                    repeat
                  repeat 
                return void
                
                // Explode picture
                function explodePicture()
                  sleep(1)
                  for i = 0 to len(tiles) loop
                    value = rnd(100) + 10 // random speed
                    dirX = 1
                    if (rnd(2) == 1) then // random x direction
                      dirX = -1
                    endif
                    dirY = 1    
                    if (rnd(2) == 1) then // random y direction
                      dirY = -1
                    endif
                    setSpriteRotationSpeed(tiles[i], value * dirX)
                    setSpriteSpeed(tiles[i], { value * dirX, value * dirY } ) 
                  repeat
                  for i = 0 to 500 loop
                    clear()
                    updateSprites()
                    drawSprites()
                    update()    
                  repeat
                return void
                
                // Unexplode picture
                function reverseExplosion(scaleFactor)
                  for i = 0 to len(tiles) loop // Reverse speed 
                    tile = tiles[i]
                    setSpriteRotationSpeed(tile, -tile.rotation_speed * scaleFactor)
                    setSpriteSpeed(tile, { -tile.x_speed * scaleFactor, -tile.y_speed * scaleFactor } ) 
                  repeat
                  for i = 0 to 50 loop
                    clear()
                    updateSprites()
                    drawSprites()
                    update()    
                  repeat
                  clear()
                  for i = 0 to len(tiles) loop // Cheat to get original image!
                    tile = tiles[i]
                    setSpriteRotation(tile, 0)
                    setSpriteLocation(tile, tile.saveX, tile.saveY )
                  repeat
                  drawSprites()
                  update()
                  sleep(1)
                return void
                
                1 Reply Last reply Reply Quote 4
                • pianofire
                  pianofire Fuze Team last edited by

                  Typically I have spotted a couple of issues with this code since I published it. Bonus points if you can spot them

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

                    How did you get that picture on the switch?

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

                      I think it’s one of the built in assets? There are some with trains if I remember

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