Hi!
I noticed with the Word Magnet App that sometimes the words disappear off the screen a bit, making them hard to “get a hold of”. Is there any way to put some padding around the edge to keep the words from spilling over?
Thank you!
Teri
Hi!
I noticed with the Word Magnet App that sometimes the words disappear off the screen a bit, making them hard to “get a hold of”. Is there any way to put some padding around the edge to keep the words from spilling over?
Thank you!
Teri
You could limit where objects can move by adding some if statements in the touch code for the pan gesture. Don’t move a label outside if it’s x position is less than 20. Something along these lines. Let me know if that helps.
// limit the x coordinate
if panGesture.view.frame.origin.x < 20 {
panGesture.view.frame.origin.x = 20
}
Thanks Paul,
I think I have the problem solved. However, I did not state my problem accurately, my problem was the position of the labels upon loading the view. Your information put me on the right track (I think) in that I had to “monkey” with the x and y coordinates. So I did this;
var x = Int ( arc4random_uniform ( 280 ) + 20 ) //random x from 20 - 300
var y = Int( arc4random_uniform( 380) + 20) //random y from 20 - 425
Now I notice that when I rotate from portrait to landscape mode I lose some of the labels off screen. The reason according to what I’ve read so far is that the x/y coordinates shift when the device is rotated. I have found some documentation about using a SpriteKit that might speak to this problem.
However, what I’ve found is for objective C. Is this something that is used in Swift, could it be a solution to keeping all the labels on the screen, and if so how is it done in Swift? Or is there an easier way to do this…
Thank you again for all the suggestions and help!
Teri
@teripenski Three solutions you could try.
Example Screen Size 480x320 (points)
// Portrait starting orientation
// label1 (X, Y) = (200, 140)
let relativeX = X / oldScreenWidth // 200.0 / 320
let relativeY = Y / oldScreenHeight // 140.0 / 480
let newX = relativeX * newScreenWidth // (200.0 / 320) * 480
let newY = relativeY * newScreenHeight // (140.0 / 480) * 320