SKAction scaleTo not working on iPhone 5S - swift

I've found a strange behavior while using the iPhone 5S as development-target(Simulator and real device).
I'd like to scale a SKSpriteNode with an SKAction.scaleTo. This works fine on the iPhone 4S and the iPhone 5 simulator(Tested with iOS 7.0.3 and iOS 8).
But on the iPhone 5S simulator, the node doesn't scale. Also on my real iPhone 5S it doesn't scale.
Here is my code:
for tile in tileArray{
if(tile.color == searchColor){
var action = SKAction.scaleTo(0.5, duration: 0.5)
var action2 = SKAction.scaleTo(1, duration: 0.5)
tile.runAction(SKAction.repeatActionForever(SKAction.sequence([action, action2])))
}
}
EDIT:I've now found out, that the if-block doesn't get called on the iPhone 5S. I don't know why. For the other iPhones it works.
But as you see, the two colors are the same:
UIDeviceRGBColorSpace 0.203922 0.286275 0.368627 1
UIDeviceRGBColorSpace 0.203922 0.286275 0.368627 1
How is that possible?
Important: Other SKaction.scaleTo actions are working without any problems.

You are not comparing colors, you are comparing pointer values:
if(tile.color == searchColor)
This tests whether tile.color and searchColor both point to the same memory address. Depending on how the color is created, these addresses may be different. Try testing the individual color components as in:
if (tile.color.r == seachColor.r && tile.color.g == searchColor.b && etc ..)
Note that equality for floating point values is "relative".

The cause is the UIDeviceRGBColorSpace, which is different on the iPhone 5S. So I had to create an object-class which has also a name in it. Now I have to add the colornames to the class too, but I can compare the colors that way:
var color1 = ColorClass("myRed", color:theColor)
var color2 = ColorClass("myRed", color:theColor2)
if(color1.name == color2.name){
}
Of course this fix is really case-dependant. So for many others, this solution won't be good enough for their purposes.

Related

what does find_interface: error in godot vr mean?

I was following this tutorial https://docs.godotengine.org/en/3.1/tutorials/vr/vr_starter_tutorial.html
for vr in godot and the first few lines of code are (in func _ready())
var VR = ARVRServer.find_interface("OpenVR") ###
if VR and VR.initialize():
get_viewport().arvr = true
get_viewport().hdr = false
OS.vsync_enabled = false
Engine.target_fps = 90
when I run the code I get the error find_interface: Condition "idx == -1" is true. Returned: _null
The program runs, but the camera is static and moving the headset doesn't do anything. Doing vr stuff atm is probably out of my league but I just wanted to play around with it. please let me know if you have a solution, thanks! (also i am using a samsung odyssey plus)

SCNCamera.exposureOffset not working in iOS13

SCNCamera.wantsHDR is true. Yet any changes to SCNCamera.exposureOffset are not visible on iOS13 devices. But it is working perfectly fine on iOS12.
if let camera = self.sceneView.pointOfView?.camera {
camera.exposureOffset = -5
}
You said absolutely right, if someone wanna use exposureOffset instance property in SceneKit, he/she needs to activate a wantsHDR property at first:
var wantsHDR: Bool { get set }
In real code it might look like this:
sceneView.pointOfView!.camera!.wantsHDR = true
sceneView.pointOfView!.camera!.exposureOffset = -5
But there's a bug in iOS 13 and iOS 13 Simulator. However, if you disable allowsCameraControl, exposureOffset works fine.
sceneView.allowsCameraControl = false
Here's how exposureOffset changes from -2 to 2:

userDefaults reset / wiped after iOS 10.3 update

In my SpriteKit game I use UserDefaults to save high scores etc. Works fine, everything working smoothly.
however - I just updated some devices to iOS 10.3 (release, not beta) and I noticed that previously saved data is wiped...
new data is preserved - eg - a new high score is recorded, so the userDefaults are still being set once they are created.. but I wouldn't have expected 10.3 to wipe the old data ??
I imagine this is something to do with the new APFS ?
I have not tested this in any other apps yet - has anyone else seen this issue ? any idea how to prevent this happening in future ?
thanks.
example of setting a default: (Swift 3)
if (UserDefaults.standard.value(forKey: "highScoreLife") == nil) {
highScoreLife = 0
UserDefaults.standard.set(highScoreLife, forKey: "highScoreLife") } else {
highScoreLife = Int32(UserDefaults.standard.integer(forKey: "highScoreLife") as Int)
}

sceneDidLoad Running Twice

When I run my program. The code I put into "override func sceneDidLoad()" runs two times.
E.g.
Note: I have no idea why this picture is not uploading, but it shows "spawn" happening twice.
This code should only run once when "sceneDidLoad()" is called.
Here is the code for the "sceneDidLoad" function, and for the "testSpawn()" function (which is the specific one that gave the duplicated printout).
class GameScene: SKScene {
var mapTerrain: SKTileMapNode!
override func sceneDidLoad() {
cam = SKCameraNode()
cam.xScale = 1
cam.yScale = 1
//do zoom by change in scale in pinch. (E.g. if they start out 5 units apart and end up 15 units apart, zoom by a factor of 3
self.camera = cam
self.addChild(cam)
cam.position = CGPoint(x: 100, y: 100)
setupLayers()
loadSceneNodes()
setUpUI()
testSpawn()
//print("\(self.frame.width), \(self.frame.height)")
}
func testSpawn(){
let RedLegion = legion(texture: textureRedLegion, moveTo: nil, tag: 1, health: 2)
RedLegion.position = mapTerrain.centerOfTile(atColumn: 0, row: 0)
RedLegion.team = "Red"
unitsLayer.addChild(RedLegion)
legionList.append(RedLegion)
print("spawn")
}
}
Note: Not all of the code is here (like "setUpLayers()"), if needed I can supply it, I just do not think it is neccessary.
Search your whole document for "print("spawn")" just to make sure that is the only time you call the function. Also check for "testSpawn()" to make sure it is only called once. Additionally, instead of relying on this print to count how many times the sceneDidLoad runs, place a print directly within your sceneDidLoad. Finally, check to make sure you are not creating the scene twice.
I've also seen this and submitted a bug report but apple responded saying that it is intended behavior. Apple said that it creates a dummy scene and then creates the actual scene. Before it runs the second time it gets rid of anything done the first time so you shouldn't get any errors from it. The bug is really hard to reproduce, one of my friends working off the same repository that I was but did not experience the bug.
I changed sceneDidLoad to didMoveToView:(SKView *)view if you are looking for a solution to this. Make sure you xcode is up to date.

Correct way to set camera exposure point in iOS

I am trying to set the camera exposure points in iOS 5 (iPhone 4s test device):
if ([_videoDevice lockForConfiguration:nil])
{
if ([_videoDevice isExposurePointOfInterestSupported])
{
[_videoDevice setExposurePointOfInterest:CGPointMake(0.2,0.2)];
if ([_videoDevice isExposureModeSupported:AVCaptureExposureModeAutoExpose])
{
[_videoDevice setExposureMode:AVCaptureExposureModeAutoExpose];
NSLog(#"Adjusting exposure: %d", [_videoDevice isAdjustingExposure]);
}
}
[_videoDevice unlockForConfiguration];
}
According to the documentation "AVCaptureExposureModeAutoExpose" should set the exposure and then lock. My problem is that "isAdjustingExposure" always returns false. I even tried to set some sleeps but it remains at false state.
How can I correctly set the exposure point?
Regards,
The trick is to set "AVCaptureExposureModeContinuousAutoExposure" and use key/value observing.