ios – Replicating Background Conduct From Brawl Stars

[ad_1]

So an fascinating downside/query, however I have been attempting to duplicate this background impact right here (brawl stars), with the icons filling the background and shifting in chosen route with a selected velocity off the display screen.

I have been in a position to initialize the background tiles/icons to right away present up when the view is loaded, nevertheless I’m having bother timing new tiles/icons to come back in on the proper time, and on the proper velocity to look the identical. I additionally do not know if that is the very best strategy and this simply represents my feeble try at messing round and attempting to duplicate this conduct.

Any recommendation or solutions welcome.

func initializeBackgroundTiles()
{
    let itemsPerRow = 4

    let itemHeight = self.body.width / 7
    let widthBetween = (itemHeight * 2) / 5
    let columnHeight = widthBetween * 4
    
    for column in 0...10 {
        
        for row in 0...5 {
            
            let columnPosition = (columnHeight * CGFloat(column))
            
            let xCalc = CGFloat(
                -(itemHeight + widthBetween) // one row to the left as properly
                + (itemHeight * Double(row) + (widthBetween * Double(row))))
            
            let yCalc = (((self.body.top - itemHeight) - columnPosition * 2) +
                         ((row % 2 == 1 ? columnHeight : 0)))
                    
            let tileSubview = CustomImageView(body: CGRect(
                x: xCalc,
                y: yCalc,
                width: itemHeight,
                top: itemHeight))
            
            tileSubview.picture = UIImage(named: "lightBand")!.withTintColor(.white)
            tileSubview.alpha = 0.04
            ContentView.addSubview(tileSubview)
            
            UIView.animate(withDuration: 30, delay: 0, choices: [.curveLinear]) {
                
                let newX = ((itemHeight * Double(row)) + (widthBetween * Double(row))) + widthBetween * 3
                let newY = 0 - ((itemHeight + (row % 2 == 0 ? columnHeight : 0)) + columnPosition * 2)
                
                tileSubview.body = CGRect(
                    x: newX,
                    y: newY,
                    width: itemHeight,
                    top: itemHeight
                )
            } completion: { accomplished in
                tileSubview.removeFromSuperview()
            }
        }
    }
}

func addBackgroundTilesTimer()
{
    Timer.scheduledTimer(timeInterval: 6, goal: self, selector: #selector(continueBackgroundTiles), userInfo: nil, repeats: true)
}

@objc func continueBackgroundTiles()
{
    // spawn a vertical and horizontal row each x seconds
    let itemHeight = self.body.width / 7
    let widthBetween = (itemHeight * 2) / 5
    let columnHeight = widthBetween * 4

        
        for row in 0...7 {
            
            let columnPosition = (columnHeight * CGFloat(1))
            
            let xCalc = CGFloat(
                -((itemHeight + widthBetween) * 2) // two buffer rows to the left as properly
                + (itemHeight * Double(row) + (widthBetween * Double(row))))
            
            let yCalc = (((self.body.top - itemHeight) - columnPosition * 2) +
                         ((row % 2 == 1 ? columnHeight : 0)))
                    
            let tileSubview = CustomImageView(body: CGRect(
                x: xCalc,
                y: yCalc,
                width: itemHeight,
                top: itemHeight))
            
            tileSubview.picture = UIImage(named: "lightBand")!.withTintColor(.white)
            tileSubview.alpha = 0.04
            self.ContentView.addSubview(tileSubview)
             
            UIView.animate(withDuration: 30, delay: 0, choices: [.curveLinear]) {
                
                let newX = ((itemHeight * Double(row)) + (widthBetween * Double(row))) + widthBetween * 3
                let newY = 0 - ((itemHeight + (row % 2 == 0 ? columnHeight : 0)) + columnPosition * 2)
                
                tileSubview.body = CGRect(
                    x: newX,
                    y: newY,
                    width: itemHeight,
                    top: itemHeight
                )
            } completion: { accomplished in
                tileSubview.removeFromSuperview()
            }
        }
    }

[ad_2]

Leave a Reply