I have roundPath and BoxPath and I would like to do:
id modifyPath = [CCActionTween actionWithDuration:2 key:#"path" from:roundPath to:boxpath];
but I have the error "incompatible type of argument 3 of 'actionWithDuration:key:from:to:' Ho w can I solve this please ? sorry for my english I'm french :/
I presume that "path" is a CGPoint type. In that case you can't use CCActionTween because it only works on built-in data types like BOOL, char, int, float, double but not C structs. CGPoint is a C struct defined as {float x; float y;}.
You can't use CCActionTween with path.x and path.y either. That's because you can't do this in Objective-C:
node.position.x = 10; // ERROR
You could however subclass and add two float properties myX and myY. You can tween both individually and assign them to the position in an update method every frame:
self.position = CGPointMake(myX, myY);
Related
I have this code and its giving me and error Cannot convert value of type 'CLLocationDirection' (aka 'Double') to expected argument type 'Float' on arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(direction))). Please help me fix. Thank you.
func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
var direction: CLLocationDirection = newHeading.magneticHeading
if direction > 180 {
direction = 360 - direction
}
else {
direction = 0 - direction
}
// Rotate the arrow image
if let arrowImageView = self.arrowImageView {
UIView.animateWithDuration(1.0, animations: { () -> Void in
arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(direction)))
})
And would it also be possible to make the compass point to a longitude and latitude specified by the user? Could you please teach me how. Thanks a lot.
Swift's primitive types are not interchangeable (unlike in Objective-C)
Either you make your degreesToRadians function conform also to Double
or you have to create a Float from direction
arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(CGFloat(direction))))
This is my code.
Matrix<int, 240, 240>* imagePixels;
for (signed int x = 0; x < 100; ++x)
{
for (signed int y = 0; y < 100; ++y)
{
imagePixels(x,y) = y;
}
}
I want to simply add values to my matrix but it gives me:
expression preceding parentheses of apparent call must have (pointer-to-) function type
at matrix(x,y) = y;
I'm using C++ CLI.
I've never used Eigen, but I think it's complaining about the type of imagePixels.
Matrix<int, 240, 240>* imagePixels;
(I'm assuming the fact that you didn't initialize imagePixels with anything is a copy-paste error on the web, not in your actual code.)
All the examples of using the () syntax to access Eigen matrix objects are using the class a value type, not a pointer. Try it without the *, and see if that solves it for you.
Matrix<int, 240, 240> imagePixels;
// ^-- No "*"
Edit
OK, so imagePixels is a member of your managed class. Managed classes are only allowed to contain other managed classes, managed handles (^), unmanaged pointers (*), or basic types (e.g., int). Unmanaged classes as a value type is not allowed.
There's two ways around this:
Leave imagePixels as a pointer, and dereference it each time you use the () syntax.
(*imagePixels)(x,y) = y;
Declare a unmanaged struct to hold your matrix as a value, and have a pointer to that in your class.
struct HolderOfUnmanagedThings { Matrix<int, 240, 240> imagePixels; };
// In your managed class
HolderOfUnmanagedThings* unmanaged = new HolderOfUnmanagedThings();
unmanaged->imagePixels(x,y) = y;
I'm trying to convert the String "10.20" to Int without converting it to Double before.
I want to get the value: 10
At the moment what is working is:
let valueString = "10.20"
let valueInt = Int(Double(valueString)!)
print(valueInt)
But, is there any better way to do it?
I was trying first to do it with this command but was returning nil:
let valueString = "10.20"
let valueInt = Int(valueString)
print(valueInt)
Thanks!
You could just put an extension on the Int type that makes it StringLiteralConvertable, producing the expected result via a Float cast behind the scenes.
I have a conditional that looks like:
if sqrtf(powf(startTouch.x - (touches.first as! UITouch).locationInView(self.view).y, 2) + powf(startTouch.y-(touches.first as! UITouch).locationInView(self.view).y, 2)) > dragThreshold as! Float {
self.drag = false;
}
I am getting an error that says Binary operator > cannot be applied to two Float operands. I cannot understand why I can't check if a float is greater than another float. What is this error trying to tell me?
The members of a CGPoint are of type CGFloat, and assuming you are on a 64-bit architecture the native type used to store a CGFloat is Double - try treating those calculated values as Doubles (use sqrt() and pow() instead of the Float versions)... using dragThreshold as a Double as well
Using latest Xcode 7 beta 4 and SpriteKit's function override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) I did break this big chunk to smaller ones like this:
let dragThreshold: Int = 1
let startTouch = CGPointZero
let pow1 = powf(Float(startTouch.x - touches!.first!.locationInView(self.view).y), 2.0)
let pow2 = powf(Float(startTouch.y-touches!.first!.locationInView(self.view).y), 2.0)
let sq = sqrtf(pow1 + pow2)
if sq > Float(dragThreshold) {
self.drag = false;
}
This works. Basically added more conversions for powf arguments, changed 2 to 2.0
General advice - if you get some strange errors, try to break down your expression into smaller ones to isolate issue.
I'm trying to initialize ALAssetsGroupType constant in Swift (Xcode 6.4.):
let groupTypes: ALAssetsGroupType = ALAssetsGroupType(ALAssetsGroupAll)
But It doesn't compile for 32bit devices(ex, iPhone 5) and I get error:
There's probably a better way, but the direct approach is to use the constructor for Int32 to create a signed Int32 from a UInt32:
let groupTypes: ALAssetsGroupType = ALAssetsGroupType(Int32(bitPattern: ALAssetsGroupAll))
Explanation
If you option-click on ALAssetsGroupType you will see that it is a typealias for Int:
typealias ALAssetsGroupType = Int
But, if you then click on AssetsLibrary next to Declared In you will see that in the header file it is actually a typedef for NSUInteger:
ALAssetsLibrary.h
typedef NSUInteger ALAssetsGroupType;
So, what's going on here? Why doesn't Swift treat NSUInteger as UInt? Swift is a strongly typed language, which means you can't just assign a Int to an UInt without conversion. To keep our lives simpler and to remove many of those conversions, the Swift engineers decided to treat NSUInteger as Int which saves a lot of hassle in most cases.
The next piece of the mystery is the definition of ALAssetsGroupAll:
enum {
ALAssetsGroupLibrary = (1 << 0), // The Library group that includes all assets.
ALAssetsGroupAlbum = (1 << 1), // All the albums synced from iTunes or created on the device.
ALAssetsGroupEvent = (1 << 2), // All the events synced from iTunes.
ALAssetsGroupFaces = (1 << 3), // All the faces albums synced from iTunes.
ALAssetsGroupSavedPhotos = (1 << 4), // The Saved Photos album.
#if __IPHONE_5_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
ALAssetsGroupPhotoStream = (1 << 5), // The PhotoStream album.
#endif
ALAssetsGroupAll = 0xFFFFFFFF, // The same as ORing together all the available group types,
};
Note that the comment next to ALAssetsGroupAll says "The same as ORing together all the available group types". Well, 0x3F would have sufficed, but presumably the author decided to set all of the bits just to future proof it in case other options were added in the future.
The problem is that while 0xFFFFFFFF fits in an NSUInteger, it doesn't fit into an Int32, so you get an overflow warning on 32-bit systems. The solution provided above converts the UInt32 0xFFFFFFFF into an Int32 with the same bitPattern. That then gets converted to an ALAssetsGroupType which is just an Int, so on a 32-bit system you get an Int with all bits set (which is the representation of -1). On a 64-bit system, the Int32 value of -1 gets sign extended to -1 in 64-bit which sets all 64 bits of the value.
Another way to solve it is to define your own AllGroups:
let AllGroups = -1 // all bits set
let groupTypes: ALAssetsGroupType = AllGroups
Note, this is deprecated in iOS 9:
typedef NSUInteger ALAssetsGroupType NS_DEPRECATED_IOS(4_0, 9_0, "Use PHAssetCollectionType and PHAssetCollectionSubtype in the Photos framework instead");