Nil is not compatible with expected argument type 'UnsafePointer' Creating custom Physics Body












0















So I needed to create a custom physics body for my sprite in my project. I was looking for an easy way to do this as I had no Idea how too. I was pointed to this site that generates a physics body based on the points you plot. When I copied it into my project and changed some of the details to fit my sprite, I was met with the following error, "Nil is not compatible with expected argument type 'UnsafePointer'".



Here is the code for the physics body shape:



var offsetX = CGFloat(player.frame.size.width * player.anchorPoint.x)
var offsetY = CGFloat(player.frame.size.height * player.anchorPoint.y)

var path = CGMutablePath()

CGPathMoveToPoint(path, nil, 77 - offsetX, 175 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 173 - offsetY)
CGPathAddLineToPoint(path, nil, 177 - offsetX, 116 - offsetY)
CGPathAddLineToPoint(path, nil, 200 - offsetX, 100 - offsetY)
CGPathAddLineToPoint(path, nil, 187 - offsetX, 92 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 28 - offsetY)
CGPathAddLineToPoint(path, nil, 77 - offsetX, 26 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 29 - offsetY)
CGPathAddLineToPoint(path, nil, 25 - offsetX, 39 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 45 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 156 - offsetY)
CGPathAddLineToPoint(path, nil, 26 - offsetX, 161 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 172 - offsetY)
CGPathAddLineToPoint(path, nil, 70 - offsetX, 174 - offsetY)


path.closeSubpath()

player.physicsBody = SKPhysicsBody(polygonFrom: path)


This error pops up for each of the CGPathAddLineToPoint() lines. I know that this is wrong, I just don't know how to write it correctly, can someone help me out on this one?










share|improve this question

























  • Don't use those Objective-C functions. Use the instance methods of CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:03











  • can you give me an example of using this for one of the points

    – Tony Martini
    Nov 13 '18 at 22:05











  • Please read the documentation

    – vadian
    Nov 13 '18 at 22:05











  • Look at the Swift documentation for CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:05











  • Check this thread. And you can find some other threads on SO searching with the error message "Nil is not compatible with expected argument type 'UnsafePointer'".

    – OOPer
    Nov 13 '18 at 22:15
















0















So I needed to create a custom physics body for my sprite in my project. I was looking for an easy way to do this as I had no Idea how too. I was pointed to this site that generates a physics body based on the points you plot. When I copied it into my project and changed some of the details to fit my sprite, I was met with the following error, "Nil is not compatible with expected argument type 'UnsafePointer'".



Here is the code for the physics body shape:



var offsetX = CGFloat(player.frame.size.width * player.anchorPoint.x)
var offsetY = CGFloat(player.frame.size.height * player.anchorPoint.y)

var path = CGMutablePath()

CGPathMoveToPoint(path, nil, 77 - offsetX, 175 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 173 - offsetY)
CGPathAddLineToPoint(path, nil, 177 - offsetX, 116 - offsetY)
CGPathAddLineToPoint(path, nil, 200 - offsetX, 100 - offsetY)
CGPathAddLineToPoint(path, nil, 187 - offsetX, 92 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 28 - offsetY)
CGPathAddLineToPoint(path, nil, 77 - offsetX, 26 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 29 - offsetY)
CGPathAddLineToPoint(path, nil, 25 - offsetX, 39 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 45 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 156 - offsetY)
CGPathAddLineToPoint(path, nil, 26 - offsetX, 161 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 172 - offsetY)
CGPathAddLineToPoint(path, nil, 70 - offsetX, 174 - offsetY)


path.closeSubpath()

player.physicsBody = SKPhysicsBody(polygonFrom: path)


This error pops up for each of the CGPathAddLineToPoint() lines. I know that this is wrong, I just don't know how to write it correctly, can someone help me out on this one?










share|improve this question

























  • Don't use those Objective-C functions. Use the instance methods of CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:03











  • can you give me an example of using this for one of the points

    – Tony Martini
    Nov 13 '18 at 22:05











  • Please read the documentation

    – vadian
    Nov 13 '18 at 22:05











  • Look at the Swift documentation for CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:05











  • Check this thread. And you can find some other threads on SO searching with the error message "Nil is not compatible with expected argument type 'UnsafePointer'".

    – OOPer
    Nov 13 '18 at 22:15














0












0








0








So I needed to create a custom physics body for my sprite in my project. I was looking for an easy way to do this as I had no Idea how too. I was pointed to this site that generates a physics body based on the points you plot. When I copied it into my project and changed some of the details to fit my sprite, I was met with the following error, "Nil is not compatible with expected argument type 'UnsafePointer'".



Here is the code for the physics body shape:



var offsetX = CGFloat(player.frame.size.width * player.anchorPoint.x)
var offsetY = CGFloat(player.frame.size.height * player.anchorPoint.y)

var path = CGMutablePath()

CGPathMoveToPoint(path, nil, 77 - offsetX, 175 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 173 - offsetY)
CGPathAddLineToPoint(path, nil, 177 - offsetX, 116 - offsetY)
CGPathAddLineToPoint(path, nil, 200 - offsetX, 100 - offsetY)
CGPathAddLineToPoint(path, nil, 187 - offsetX, 92 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 28 - offsetY)
CGPathAddLineToPoint(path, nil, 77 - offsetX, 26 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 29 - offsetY)
CGPathAddLineToPoint(path, nil, 25 - offsetX, 39 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 45 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 156 - offsetY)
CGPathAddLineToPoint(path, nil, 26 - offsetX, 161 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 172 - offsetY)
CGPathAddLineToPoint(path, nil, 70 - offsetX, 174 - offsetY)


path.closeSubpath()

player.physicsBody = SKPhysicsBody(polygonFrom: path)


This error pops up for each of the CGPathAddLineToPoint() lines. I know that this is wrong, I just don't know how to write it correctly, can someone help me out on this one?










share|improve this question
















So I needed to create a custom physics body for my sprite in my project. I was looking for an easy way to do this as I had no Idea how too. I was pointed to this site that generates a physics body based on the points you plot. When I copied it into my project and changed some of the details to fit my sprite, I was met with the following error, "Nil is not compatible with expected argument type 'UnsafePointer'".



Here is the code for the physics body shape:



var offsetX = CGFloat(player.frame.size.width * player.anchorPoint.x)
var offsetY = CGFloat(player.frame.size.height * player.anchorPoint.y)

var path = CGMutablePath()

CGPathMoveToPoint(path, nil, 77 - offsetX, 175 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 173 - offsetY)
CGPathAddLineToPoint(path, nil, 177 - offsetX, 116 - offsetY)
CGPathAddLineToPoint(path, nil, 200 - offsetX, 100 - offsetY)
CGPathAddLineToPoint(path, nil, 187 - offsetX, 92 - offsetY)
CGPathAddLineToPoint(path, nil, 86 - offsetX, 28 - offsetY)
CGPathAddLineToPoint(path, nil, 77 - offsetX, 26 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 29 - offsetY)
CGPathAddLineToPoint(path, nil, 25 - offsetX, 39 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 45 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 156 - offsetY)
CGPathAddLineToPoint(path, nil, 26 - offsetX, 161 - offsetY)
CGPathAddLineToPoint(path, nil, 62 - offsetX, 172 - offsetY)
CGPathAddLineToPoint(path, nil, 70 - offsetX, 174 - offsetY)


path.closeSubpath()

player.physicsBody = SKPhysicsBody(polygonFrom: path)


This error pops up for each of the CGPathAddLineToPoint() lines. I know that this is wrong, I just don't know how to write it correctly, can someone help me out on this one?







swift sprite-kit core-graphics skphysicsbody






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 22:03









rmaddy

242k27316380




242k27316380










asked Nov 13 '18 at 21:59









Tony MartiniTony Martini

176




176













  • Don't use those Objective-C functions. Use the instance methods of CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:03











  • can you give me an example of using this for one of the points

    – Tony Martini
    Nov 13 '18 at 22:05











  • Please read the documentation

    – vadian
    Nov 13 '18 at 22:05











  • Look at the Swift documentation for CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:05











  • Check this thread. And you can find some other threads on SO searching with the error message "Nil is not compatible with expected argument type 'UnsafePointer'".

    – OOPer
    Nov 13 '18 at 22:15



















  • Don't use those Objective-C functions. Use the instance methods of CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:03











  • can you give me an example of using this for one of the points

    – Tony Martini
    Nov 13 '18 at 22:05











  • Please read the documentation

    – vadian
    Nov 13 '18 at 22:05











  • Look at the Swift documentation for CGMutablePath.

    – rmaddy
    Nov 13 '18 at 22:05











  • Check this thread. And you can find some other threads on SO searching with the error message "Nil is not compatible with expected argument type 'UnsafePointer'".

    – OOPer
    Nov 13 '18 at 22:15

















Don't use those Objective-C functions. Use the instance methods of CGMutablePath.

– rmaddy
Nov 13 '18 at 22:03





Don't use those Objective-C functions. Use the instance methods of CGMutablePath.

– rmaddy
Nov 13 '18 at 22:03













can you give me an example of using this for one of the points

– Tony Martini
Nov 13 '18 at 22:05





can you give me an example of using this for one of the points

– Tony Martini
Nov 13 '18 at 22:05













Please read the documentation

– vadian
Nov 13 '18 at 22:05





Please read the documentation

– vadian
Nov 13 '18 at 22:05













Look at the Swift documentation for CGMutablePath.

– rmaddy
Nov 13 '18 at 22:05





Look at the Swift documentation for CGMutablePath.

– rmaddy
Nov 13 '18 at 22:05













Check this thread. And you can find some other threads on SO searching with the error message "Nil is not compatible with expected argument type 'UnsafePointer'".

– OOPer
Nov 13 '18 at 22:15





Check this thread. And you can find some other threads on SO searching with the error message "Nil is not compatible with expected argument type 'UnsafePointer'".

– OOPer
Nov 13 '18 at 22:15












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290145%2fnil-is-not-compatible-with-expected-argument-type-unsafepointercgaffinetransfo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290145%2fnil-is-not-compatible-with-expected-argument-type-unsafepointercgaffinetransfo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values