Post

Replies

Boosts

Views

Activity

Lag in my game
Hello! I have a maze game that I have just made, and the code works, the only thing I don't understand is that whenever I play and make a big maze, like 27x27 or bigger, it runs super slow and has a big lag every time i try to move. Does anyone know what I can do to lessen the lag? I know that it has a ton of views to compute when the maze is big, but most of the views are in Lazy Stacks so they shouldn't be causing as much of a problem as they are. Here's my code, I'd really appreciate it if someone had a good solution to my problem import SwiftUI struct ContentView: View {       @StateObject var data: DataBase       @StateObject var trafficControl: TrafficControl       var body: some View {     ZStack{       Group{         LazyVStack{           ForEach(1...data.size, id: \.self) { index in             LazyHStack {               ForEach(1...data.size, id: \.self) { box in                 Rectangle().fill(Color.gray).frame(width: 90, height: 90, alignment: .center).scaledToFill().padding(-4)               }           }                         }         }         LazyVStack{           ForEach(1...(data.size), id: \.self) { index in             LazyHStack {               ForEach(1...(data.size + 1), id: \.self) { box in                 if data.vert[((index.self - 1) * (data.size + 1)) + box.self] == 1 {                 Rectangle().fill(Color.black).frame(width: 6, height: 92, alignment: .center).scaledToFill().padding(.trailing, 38).padding(.leading, 38).padding(.top, -5).padding(.bottom, -5)                 }                 else {                   Rectangle().fill(Color.gray).frame(width: 6, height: 92, alignment: .center).scaledToFill().padding(.trailing, 38).padding(.leading, 38).padding(.top, -5).padding(.bottom, -5).opacity(0)                 }               }             }           }         }         LazyHStack{           ForEach(1...data.size, id: \.self) { index2 in             LazyVStack {               ForEach(1...(data.size + 1), id: \.self) { box2 in                 if data.horz[((index2.self - 1) * (data.size + 1)) + box2.self] == 1 {                   Rectangle().fill(Color.black).frame(width: 96, height: 6, alignment: .center).scaledToFill().padding(.trailing, -7).padding(.leading, -7).padding(.top, 38).padding(.bottom, 38)                 }                 else {                   Rectangle().fill(Color.gray).frame(width: 96, height: 6, alignment: .center).scaledToFill().padding(.trailing, -7).padding(.leading, -7).padding(.top, 38).padding(.bottom, 38).opacity(0)               }             }           }         }       }         Rectangle().fill(Color.white).frame(width: 60, height: 60, alignment: .center).scaledToFill()       }.offset(x: CGFloat(data.ex), y: CGFloat(data.why)).animation(.linear(duration: 0.3), value: data.ex).animation(.linear(duration: 0.3), value: data.why).frame(width: 300, height: 300, alignment: .center)               Circle().fill(Color.black).frame(width: 20, height: 20, alignment: .center).scaledToFill()       Rectangle().fill(Color.green).frame(width: 1000, height: 1000, alignment: .center).offset(x: 590, y: 0)       Rectangle().fill(Color.green).frame(width: 1000, height: 1000, alignment: .center).offset(x: 0, y: 590)       Rectangle().fill(Color.green).frame(width: 1000, height: 1000, alignment: .center).offset(x: -590, y: 0)       Rectangle().fill(Color.green).frame(width: 1000, height: 1000, alignment: .center).offset(x: 0, y: -590)               HStack{         Text("corx: \(data.corx)")         Text("cory: \(data.cory)")       }.offset(x: 0, y: -200)       Text("Size: \(data.size)").offset(x: 0, y: -250)               Text("Back to menu").padding().background(Color.black).offset(x: 0, y: -300).onTapGesture {         trafficControl.currentPage = .page1       }             }.gesture(DragGesture(minimumDistance: 40)       .onEnded { endedGesture in       if (endedGesture.location.x - endedGesture.startLocation.x) > 0 {         if (endedGesture.location.y - endedGesture.startLocation.y) > (endedGesture.location.x - endedGesture.startLocation.x) {           data.MoveDown()         }         else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.location.x - endedGesture.startLocation.x) {           data.MoveUp()         }         else {           data.MoveRight()         }       }         else if (endedGesture.startLocation.x - endedGesture.location.x) > 0 {           if (endedGesture.location.y - endedGesture.startLocation.y) > (endedGesture.startLocation.x - endedGesture.location.x) {             data.MoveDown()           }           else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.startLocation.x - endedGesture.location.x) {             data.MoveUp()           }           else {             data.MoveLeft()           }         }         else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.location.y - endedGesture.startLocation.y) {           data.MoveUp()         }         else {           data.MoveRight()         }         data.corx = -data.ex/90         data.cory = data.why/90       }         )}         } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView(data: DataBase(), trafficControl: TrafficControl())   } }
1
0
409
Jul ’22
Randomizing a ForEach view loop
Hello! I am trying to make a list of numbers where when I press a button, random numbers show up, and each time you press it the button, it changes. I have code that I think should accomplish this but I am very confused about how it works. When I use $Array.index(Int, offSetBy: 0), does this return the value at that place in the array, or does that just return the Int I put into it? Anyway, here's my code, hopefully someone can help me. Thanks! import SwiftUI struct ContentView: View {       @State var numm = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]       @State var fill = 0       var body: some View {     VStack{       Button {         fill = 0         numm.removeAll()                   while fill < 20 {           numm.append(Int.random(in: 0...1))           fill += 1         }       } label: {         Text("Make List")       }       ForEach(1...(20), id: \.self) { box in         if $numm.index(box.self, offsetBy: 0) == 1 {           Text("\(box.self)")         }         else {           Text("----")         }       }     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
1
0
1k
Jul ’22
ForEach loop or initializer broken
Hey! I am trying to make a game and came across a problem. I simplified the problem by making a new program to test it out, and whenever I try to run it, it says that updating took more than 5 seconds, or nothing shows up at all. If anyone could help me make this work, or suggest a better way to do it, that would be awesome! Thanks! Here's my code import SwiftUI struct ContentView: View {       @State var numm = [0, 0]       @State var fill = 1       var body: some View {     VStack{       ForEach(1...(20), id: \.self) { box in         if numm.index(box.self, offsetBy: 0) == 1 {           Text("\(box.self)")         }         else {           Text("---")         }       }     }   }   init() {     fill = 0     numm.removeAll()           while fill < 20 {       numm.append(Int.random(in: 0...1))       fill += 1     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
2
0
389
Jul ’22
What to use to update multiple views at once?
Hi! I am trying to make a maze game, and right now I am simply working on generating the maze. I have code that randomizes the contents of an array called "right". This array has enough members to fill what the maze size is, but when I run my code, the views don't update, the ForEach function seems to make it so it cannot read data from my DataBase. Please help me? import SwiftUI struct ContentView: View {       @StateObject var data: DataBase       @StateObject var trafficControl: TrafficControl       var body: some View {     ZStack{       Group{         LazyVStack{                       ForEach(1...data.size, id: \.self) { index in             LazyHStack {               ForEach(1...data.size, id: \.self) { box in                 Rectangle().fill(Color.gray).frame(width: 90, height: 90, alignment: .center).scaledToFill().padding(-4)               }           }                         }         }         LazyVStack{           ForEach(1...(data.size), id: \.self) { index in             LazyHStack {               ForEach(1...(data.size + 1), id: \.self) { box in                 if data.**** == 1 {                 Rectangle().fill(Color.gray).frame(width: 6, height: 90, alignment: .center).scaledToFill().padding(.trailing, 38).padding(.leading, 38).padding(.top, -4).padding(.bottom, -4)                 }                 else {                   Rectangle().fill(Color.black).frame(width: 6, height: 90, alignment: .center).scaledToFill().padding(.trailing, 38).padding(.leading, 38).padding(.top, -4).padding(.bottom, -4)                 }               }             }           }         }       LazyHStack{         ForEach(1...data.size, id: \.self) { index in           LazyVStack {             ForEach(1...(data.size + 1), id: \.self) { box in               Rectangle().fill(                 Color.black).frame(width: 90, height: 6, alignment: .center).scaledToFill().padding(.top, 38).padding(.bottom, 38).padding(.trailing, -4).padding(.leading, -4)             }           }         }       }         Rectangle().fill(Color.white).frame(width: 60, height: 60, alignment: .center).scaledToFill()       }.offset(x: CGFloat(data.ex), y: CGFloat(data.why)).onAppear(){         print("\(data.size/2 + 1)")       }               Circle().fill(Color.black).frame(width: 20, height: 20, alignment: .center).scaledToFill()                     }.gesture(DragGesture(minimumDistance: 40)       .onEnded { endedGesture in       if (endedGesture.location.x - endedGesture.startLocation.x) > 0 {         if (endedGesture.location.y - endedGesture.startLocation.y) > (endedGesture.location.x - endedGesture.startLocation.x) {           data.why -= 90         }         else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.location.x - endedGesture.startLocation.x) {           data.why += 90         }         else {           data.ex -= 90         }       }         else if (endedGesture.startLocation.x - endedGesture.location.x) > 0 {           if (endedGesture.location.y - endedGesture.startLocation.y) > (endedGesture.startLocation.x - endedGesture.location.x) {             data.why -= 90           }           else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.startLocation.x - endedGesture.location.x) {             data.why += 90           }           else {             data.ex += 90           }         }         else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.location.y - endedGesture.startLocation.y) {           data.why += 90         }         else {           data.why -= 90         }         data.corx = data.ex/90         data.cory = data.why/90       }         )}         } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView(data: DataBase(), trafficControl: TrafficControl())   } }
1
0
522
Jul ’22
Submit my app with my new Apple ID
Hi! So, I made a game a while ago on my old apple ID, and I submitted it to Testflight and everything, and I was updating it for a while, and then I stopped. I still have the Xcode project for the app on my mac, but the thing is, I now have a new Apple Id, and I want to submit the same app again, and continue updating it, but on my new Apple ID and not my old one. When I try to submit the app to Testflight, it tells me that there is already an app with that name and that I cannot submit it. I still have access to my other developer account on my old Apple ID, but it will expire in about a month. Is there a way I can transfer ownership of the app to my new Apple ID? Or maybe just delete it from testflight on my old account so I can resubmit it on my new account? If anyone knows how that would be awesome, thanks!
0
0
385
Jul ’22
Safe Area Insets
I am working on an app that needs to fit in the safe area. I am currently using UIScreen.main.bounds.size.height and width to size everything in my view, but these seem to ignore the safe area insets, which results in my view being obstructed by other things in the safe area of the device running my app. How can I set a variable to equal the top safe area inset and another variable to equal the bottom safe area inset in order to fix my problem? Please help me, I’ve been looking forever to find an answer, and I can’t find one
4
1
2.5k
Jul ’22