Post

Replies

Boosts

Views

Activity

Static objects regardless of camera in SceneKit
I am working on a game that involves piloting a ship through a long tunnel. I want to be able to have the tunnel the same size as the screen always so that the four edges represent the "tunnel". I'm using a SCNShapeNode to create each of the four "walls", but I can can't seem to figure out how to always have them pinned to the edges of the screen. I've tried converting the screen size to the location on the scene, but it most often doesn't really work at all or at the very best only gets close. Any ideas on how to make this work regardless of device would be greatly appreciated. Thanks.
0
0
442
Mar ’24
SCNNode slows down even with constant velocity set
I have created an App with SceneKit where I have a series of walls (lines made with a SCNShapeNode) and a ball (SCNNode using an SCNSphere). The ball is supposed to continue with a constant speed regardless of where it goes, just changing directions whenever it hits a wall. However, the ball slows down and comes to a stop after a short while. If I start it close to a wall, it bounces off the wall in the correct direction, but then still ends up slowing down to a stop after a short while. Here is how the balls are created: let sphere = SCNSphere(radius: 1.0) var sphereNode1: SCNNode? let sphereNode1 = SCNNode(geometry: sphere) let theBody1 = SCNPhysicsBody(type: .dynamic, shape: SCNPhysicsShape(geometry: sphere)) sphereNode1.worldPosition = SCNVector3(0,20,0) sphereNode1.physicsBody = theBody1 //sphereNode1.physicsBody!.velocity = SCNVector3(0.0, 2.0, 0.0) sphereNode1.physicsBody!.applyForce(SCNVector3(0.0, 2.0, 0.0), asImpulse: true) sphereNode1.physicsBody!.physicsShape = SCNPhysicsShape(geometry: sphere) sphereNode1.physicsBody!.isAffectedByGravity = false sphereNode1.physicsBody!.restitution = 1.0 sphereNode1.geometry?.materials = [sphereMaterial] I tried both giving the ball a velocity and applying a force to it. Both resulted in the above mentioned actions. I can't seem to find anywhere in the documentation that suggests a way to resolve this. I actually did this same thing in the SpriteKit environment and everything worked fine. Hopefully someone can tell me what I'm missing. Thanks, Michael
2
0
506
Mar ’24
Overlaying a UIControl over a SKSpriteNode
I'm currently using Metal to create a game board with floating balloons; each balloon is a SKSpriteNode with an image of a balloon attached. The user touches and drags the balloon to a second balloon, merging the two. Exactly how they get merged is based on input from the user. I have a UISegmentedControl that pops up where the user selects one of four responses and the merge occurs. Currently, the UISegmentedControl pops up in the middle of the game board; however, I would like it to overlay on top of the first balloon instead. I have tried this once the two balloons touch each other: bubble1.physicsBody!.velocity = CGVector(dx: 0, dy: 0) // Stopping the balloon requestView.frame.origin.x = bubble1.position.x requestView.frame.origin.y = bubble1.position.y Where requestView is a UIView (with the same dimensions of the balloon) with various subviews (including the UISegmentedControl) and bubble1 is the SKSpriteNode (balloon). However, when I add the requestView as a subview of the game board, it does not overlay on top of the SKSpriteNode (bubble1). In fact, each time I try it, it doesn't even seem to appear in the same space relative to the location of the bubble1. Any thoughts on what I might be doing wrong? Thanks!
1
0
698
Feb ’24
Timing of CollectionView layouts
I have three CollectionView's. One main collection (Board) view is the game board, which is on auto-layout to be the biggest square possible in the available View space regardless of orientation or device. The second CollectionView (Left) is set up along the left hand edge of the Board and is set to be 30 pixels wide and the same height as the Board. The third CollectionView (Bottom) is set up along the bottom of the Board and is set to be 30 pixels tall and the same width as the Board. I use Layouts to get the content size and cell size within each and cell is always a square. The Left and Bottom CollectionViews sync with the scrolling of the Board CollectionView. This all worked perfectly when I first created it maybe ten years ago. However, I am currently updating all my apps in Swift (as well as other things). And now, the Left and Bottom CollectionView's are no longer in Sync with the Board. However, it isn't because they don't move correctly (they do). It's because the cell size in the Left and Bottom are not the same size as the Board. I think it has to do with the timing of the Layouts. It configures the size of the cells (in the Left and Bottom) before it resizes the height/width to match the size of the Board. I've tested this on various devices and it works perfectly fine on the iPad mini, but none of the others. Probably not coincidentally, in the Storyboard setup, I use the iPad mini as the device (to ensure that what I'm doing fits on the smallest screen available). So, the cells are sized as if it were running on an iPad mini even when it's not. The Left and Bottom views themselves are updated to the same height/width of the Board, but the cell sizes are not subsequently updated. Thus, no more syncing. I tried to reload the data in the ViewWillAppear (first Board, then Left and Bottom), but that does resolve this issue. I had thought that the layout should be handled after any size shifts to the view, but I guess not. Any thoughts on how to resolve this? Thanks.
5
0
710
Feb ’24
UIScrollView Simulators vs Devices
I have a UIScrollView that works perfectly on simulators for all the devices and orientations. However, whenever I try to do testing of the App on an actual device, the UIScrollView is all black. In addition, it looks like it scrolls since there's a scroll bar along the edge that moves when I try to "scroll" the black box. However, when I change orientations of the device, it no longer even does that. I have stopped the App at various points to test out the heights and widths of the various views and they all look good. Yet, nothing but a black box shows up on the device. Any thoughts? Thanks.
1
0
814
Feb ’24
Game Center Achievements with 1,000 Units
I'm putting together a group of achievements on Game Center for my new game. From what I read, you must just adjust the "Percent Complete" when reporting updates on an achievement. However, you can only use whole numbers when doing that. So, how would one update a single "unit" to an achievement that needs 1,000 units to achieve? Any suggestions would be very helpful. Thanks!
1
0
511
Feb ’24
UICollectionView Drag and Drop outside view
I currently have a UICollectionView where I'm successfully using drag and drop, except in one case. I am tracking the drag and updating a variable for the cell over which the drag location is. Once it leaves the UICollectionView view element, it simply ignores the location and leaves the variable as the last cell over which the drag passed. However, if the user drops the cell outside the UICollectionView view, it cancels the action and never fires the performDropWith (even though it continues to track the drag up until the drop). According to what I've read so far, I don't see any mention of the fact the drag/drop should be cancelled in that case. Am I possibly missing a setting or an additional method that needs to be implemented for that? I'm using Swift and the most up to date Xcode and simulators. Thanks for any ideas.
0
0
495
Nov ’21
UIButton setBackgroundImage for different states not working
I'm trying to set different background images on a UIButton based on the state. I'm currently using: firstButton.setBackgroundImage(UIImage(named: "cardButtonUnSelected"), for: .normal)         firstButton.setBackgroundImage(UIImage(named: "cardButtonSelected"), for: .selected) However, neither image shows up. If I change it to be just "setImage", the image shows up and switches on the change in state. So, I know the button exists and the images are loading correctly. It's simply not working when trying to do this with a background image. Anyone have any ideas on what I might be missing?
2
2
5.8k
Nov ’21
Center item in custom UICollectionView that scrolls both directions
I have a UICollectionView that scrolls both horizontally and vertically. I'm trying to center an item in the middle of the collection view. When I did this in Objective-C, I simply used the following code: [theCollection scrollToItemAtIndexPath:thePath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally|UICollectionViewScrollPositionCenteredVertically animated:TRUE]; However, in switching everything to Swift, this doesn't seem to work. When I do this: theCollection.scrollToItem(at: thePath, at: .centeredVertically|.centeredHorizontally , animated: true) An error occurs ('|' is not a postfix unary operator). If I try to do the scrollToItem twice, once with each direction, it only does the second one. Any ideas on how to make this happen with Swift? Thanks!
1
0
706
Nov ’21
Button Style Before iOS 15.0 warning
I'm building a project with a target of iOS 13. I know it's just a warning, but I'm trying to figure out why I'm getting this warning "Button Style Before iOS 15.0". I'm not doing anything special with the buttons in the project. However, when I first started building it the target was iOS 15. Any ideas on who I figure out what "settings" might be triggering this warning?
3
1
7.9k
Nov ’21
CoreData not updating when saved (Swift)
I am trying to get the data I update in an entity within CoreData to save; however, I change the values and yet it doesn't save. Here's the basics of how I am doing this: var container: NSPersistentContainer! var theSettings: Settings! var collectionSize: Int let appDelegate = UIApplication.shared.delegate as! AppDelegate let context = container.viewContext theSettings = Settings.init(context: context) collectionSize = Int(theSettings.defaultSize) // This works sets the value correctly // Later when the user changes a setting I do this theSettings.defaultSize = 6 do { try appDelegate.persistentContainer.viewContext.save() } catch let error as NSError { print("Error: \(error), \(error.userInfo)") } I've checked and the persistentContainer is correctly setup in the appDelegate. However, the value goes back to the default once I leave the view. It never saves. I've checked all over and I can't see anything that I'm doing wrong. I've done a lot of iOS programming, but this is the first time I'm using CoreData. Thanks for any help you can offer.
8
1
4.9k
Sep ’21
Creating square views regardless of orientation
I am trying to create a UIView within a UIStackView that I want to always be square regardless of device and orientation. I have seen posting that explain how others have done it (setting constraints between UIView and superview for both height and width - a required set and an optional set - along with a 1:1 aspect constraint for the UIView) , but it no longer seems to work under all instances - in particular iPad and iPhone 11s. Does anyone have any advice on how to make this happen. It seems to me to be a pretty routine thing to do. I've done it before programmatically, but I would really like to get it done within Interface Builder. Any suggestions would be greatly appreciated.
1
0
1.7k
Aug ’20
Trying to use AutoLayout for a square UICollectionView
I am trying to use AutoLayout across all types of devices to have a square UICollectionView that maximizes the size of the UICollectionView based on the width/height of the screen (i.e. for Portrait the view is the width of the whole screen and the height is equal to that width; for Landscape the view is the height of the screen and the width is equal to that height).1. I am using Interface Builder in Xcode 9.22. Standard UICollectionView3. The UICollectionsView's settings for AutoLayout Constraints: Aspect Ratio with a Priority of 1000; Horizontal (Center) in Container with a Priority of 1000, Vertical (Center) in Container with a Prioerity of 1000; Top Space = 0 with a Priority of 250; Leading Space = 0 with a Priority of 250; Bottom Space = 0 with a Priority of 250; Trailing Space with a Priority of 250.When I do this, it just ignores the Aspect Ratio and does everything else.Anyone tell me what I'm doing wrong?
14
0
5.4k
Mar ’18