How to prevent distorted images?











up vote
2
down vote

favorite












I have the problem that the images I add are distorted. I have created a pixel accurate background for the iPhone X at (1125 x 2436), so I don't have to use .aspectFill and .aspectFit because I want a screen without black borders.



I use the following code to create the images:



func animateDeck() {
let chip = SKSpriteNode(imageNamed: "Chip")
chip.position = CGPoint(x: 300, y: 400)
chip.zPosition = 2
chip.setScale(1)
gameScene2.addChild(chip)
print("test")
}


Is there a way to display the images in their correct size without using .aspectFit or .aspectFill?



now (left) and how it should be (right)



Thank you in advance!










share|improve this question




















  • 1




    If you have an image which is exactly the same size as the iPhone X, and set the position to view.center, you should be fine. However, even if it should fit perfect, set it to aspectFill or aspectFit just so you don't get distortion on other screen sizes.
    – George_E
    Nov 4 at 10:22






  • 1




    Try also checking to see that chip is at your expected size - and if not, you can set it using chip.size = CGSize(width: 1125, height: 2436).
    – George_E
    Nov 4 at 10:25










  • I have created a new image with the size 1125 x 2436. In the middle is the 128x128 chip. The rest of the image is transparent. Unfortunately this does not work. With the other variant gameScene2.scaleMode = .aspectFit black bars are displayed again, which I want to prevent.
    – TimKrs
    Nov 4 at 11:00










  • Why don’t you consider adding a UIImage to the view controller instead of the scene if you are not moving the background?
    – George_E
    Nov 4 at 11:03










  • When I use let image = UIImage(named: "Chip"), I cannot use it as a node. So I can no longer use SKPhysicsBody, SKAction, etc. avail
    – TimKrs
    Nov 4 at 11:24















up vote
2
down vote

favorite












I have the problem that the images I add are distorted. I have created a pixel accurate background for the iPhone X at (1125 x 2436), so I don't have to use .aspectFill and .aspectFit because I want a screen without black borders.



I use the following code to create the images:



func animateDeck() {
let chip = SKSpriteNode(imageNamed: "Chip")
chip.position = CGPoint(x: 300, y: 400)
chip.zPosition = 2
chip.setScale(1)
gameScene2.addChild(chip)
print("test")
}


Is there a way to display the images in their correct size without using .aspectFit or .aspectFill?



now (left) and how it should be (right)



Thank you in advance!










share|improve this question




















  • 1




    If you have an image which is exactly the same size as the iPhone X, and set the position to view.center, you should be fine. However, even if it should fit perfect, set it to aspectFill or aspectFit just so you don't get distortion on other screen sizes.
    – George_E
    Nov 4 at 10:22






  • 1




    Try also checking to see that chip is at your expected size - and if not, you can set it using chip.size = CGSize(width: 1125, height: 2436).
    – George_E
    Nov 4 at 10:25










  • I have created a new image with the size 1125 x 2436. In the middle is the 128x128 chip. The rest of the image is transparent. Unfortunately this does not work. With the other variant gameScene2.scaleMode = .aspectFit black bars are displayed again, which I want to prevent.
    – TimKrs
    Nov 4 at 11:00










  • Why don’t you consider adding a UIImage to the view controller instead of the scene if you are not moving the background?
    – George_E
    Nov 4 at 11:03










  • When I use let image = UIImage(named: "Chip"), I cannot use it as a node. So I can no longer use SKPhysicsBody, SKAction, etc. avail
    – TimKrs
    Nov 4 at 11:24













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have the problem that the images I add are distorted. I have created a pixel accurate background for the iPhone X at (1125 x 2436), so I don't have to use .aspectFill and .aspectFit because I want a screen without black borders.



I use the following code to create the images:



func animateDeck() {
let chip = SKSpriteNode(imageNamed: "Chip")
chip.position = CGPoint(x: 300, y: 400)
chip.zPosition = 2
chip.setScale(1)
gameScene2.addChild(chip)
print("test")
}


Is there a way to display the images in their correct size without using .aspectFit or .aspectFill?



now (left) and how it should be (right)



Thank you in advance!










share|improve this question















I have the problem that the images I add are distorted. I have created a pixel accurate background for the iPhone X at (1125 x 2436), so I don't have to use .aspectFill and .aspectFit because I want a screen without black borders.



I use the following code to create the images:



func animateDeck() {
let chip = SKSpriteNode(imageNamed: "Chip")
chip.position = CGPoint(x: 300, y: 400)
chip.zPosition = 2
chip.setScale(1)
gameScene2.addChild(chip)
print("test")
}


Is there a way to display the images in their correct size without using .aspectFit or .aspectFill?



now (left) and how it should be (right)



Thank you in advance!







swift sprite-kit skspritenode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 4 at 12:52

























asked Nov 4 at 9:48









TimKrs

158




158








  • 1




    If you have an image which is exactly the same size as the iPhone X, and set the position to view.center, you should be fine. However, even if it should fit perfect, set it to aspectFill or aspectFit just so you don't get distortion on other screen sizes.
    – George_E
    Nov 4 at 10:22






  • 1




    Try also checking to see that chip is at your expected size - and if not, you can set it using chip.size = CGSize(width: 1125, height: 2436).
    – George_E
    Nov 4 at 10:25










  • I have created a new image with the size 1125 x 2436. In the middle is the 128x128 chip. The rest of the image is transparent. Unfortunately this does not work. With the other variant gameScene2.scaleMode = .aspectFit black bars are displayed again, which I want to prevent.
    – TimKrs
    Nov 4 at 11:00










  • Why don’t you consider adding a UIImage to the view controller instead of the scene if you are not moving the background?
    – George_E
    Nov 4 at 11:03










  • When I use let image = UIImage(named: "Chip"), I cannot use it as a node. So I can no longer use SKPhysicsBody, SKAction, etc. avail
    – TimKrs
    Nov 4 at 11:24














  • 1




    If you have an image which is exactly the same size as the iPhone X, and set the position to view.center, you should be fine. However, even if it should fit perfect, set it to aspectFill or aspectFit just so you don't get distortion on other screen sizes.
    – George_E
    Nov 4 at 10:22






  • 1




    Try also checking to see that chip is at your expected size - and if not, you can set it using chip.size = CGSize(width: 1125, height: 2436).
    – George_E
    Nov 4 at 10:25










  • I have created a new image with the size 1125 x 2436. In the middle is the 128x128 chip. The rest of the image is transparent. Unfortunately this does not work. With the other variant gameScene2.scaleMode = .aspectFit black bars are displayed again, which I want to prevent.
    – TimKrs
    Nov 4 at 11:00










  • Why don’t you consider adding a UIImage to the view controller instead of the scene if you are not moving the background?
    – George_E
    Nov 4 at 11:03










  • When I use let image = UIImage(named: "Chip"), I cannot use it as a node. So I can no longer use SKPhysicsBody, SKAction, etc. avail
    – TimKrs
    Nov 4 at 11:24








1




1




If you have an image which is exactly the same size as the iPhone X, and set the position to view.center, you should be fine. However, even if it should fit perfect, set it to aspectFill or aspectFit just so you don't get distortion on other screen sizes.
– George_E
Nov 4 at 10:22




If you have an image which is exactly the same size as the iPhone X, and set the position to view.center, you should be fine. However, even if it should fit perfect, set it to aspectFill or aspectFit just so you don't get distortion on other screen sizes.
– George_E
Nov 4 at 10:22




1




1




Try also checking to see that chip is at your expected size - and if not, you can set it using chip.size = CGSize(width: 1125, height: 2436).
– George_E
Nov 4 at 10:25




Try also checking to see that chip is at your expected size - and if not, you can set it using chip.size = CGSize(width: 1125, height: 2436).
– George_E
Nov 4 at 10:25












I have created a new image with the size 1125 x 2436. In the middle is the 128x128 chip. The rest of the image is transparent. Unfortunately this does not work. With the other variant gameScene2.scaleMode = .aspectFit black bars are displayed again, which I want to prevent.
– TimKrs
Nov 4 at 11:00




I have created a new image with the size 1125 x 2436. In the middle is the 128x128 chip. The rest of the image is transparent. Unfortunately this does not work. With the other variant gameScene2.scaleMode = .aspectFit black bars are displayed again, which I want to prevent.
– TimKrs
Nov 4 at 11:00












Why don’t you consider adding a UIImage to the view controller instead of the scene if you are not moving the background?
– George_E
Nov 4 at 11:03




Why don’t you consider adding a UIImage to the view controller instead of the scene if you are not moving the background?
– George_E
Nov 4 at 11:03












When I use let image = UIImage(named: "Chip"), I cannot use it as a node. So I can no longer use SKPhysicsBody, SKAction, etc. avail
– TimKrs
Nov 4 at 11:24




When I use let image = UIImage(named: "Chip"), I cannot use it as a node. So I can no longer use SKPhysicsBody, SKAction, etc. avail
– TimKrs
Nov 4 at 11:24












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Check out this project I just made to show you how to create a texture and apply it to a node. All you need should be in GameScene.swift.



Also, in your ViewController, make sure that your GameScene is initialised properly as shown in my project, or how you did it with this:



gameScene2 = GameScene(size: view, bounds: size)





share|improve this answer























  • I never recommend doing this, set the sks to the size of iphone x instead. You should be designing your scene with 1 size in mind, programming like this is only going to hurt you in the long run.
    – Knight0fDragon
    2 days ago











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',
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%2f53139513%2fhow-to-prevent-distorted-images%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Check out this project I just made to show you how to create a texture and apply it to a node. All you need should be in GameScene.swift.



Also, in your ViewController, make sure that your GameScene is initialised properly as shown in my project, or how you did it with this:



gameScene2 = GameScene(size: view, bounds: size)





share|improve this answer























  • I never recommend doing this, set the sks to the size of iphone x instead. You should be designing your scene with 1 size in mind, programming like this is only going to hurt you in the long run.
    – Knight0fDragon
    2 days ago















up vote
1
down vote



accepted










Check out this project I just made to show you how to create a texture and apply it to a node. All you need should be in GameScene.swift.



Also, in your ViewController, make sure that your GameScene is initialised properly as shown in my project, or how you did it with this:



gameScene2 = GameScene(size: view, bounds: size)





share|improve this answer























  • I never recommend doing this, set the sks to the size of iphone x instead. You should be designing your scene with 1 size in mind, programming like this is only going to hurt you in the long run.
    – Knight0fDragon
    2 days ago













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Check out this project I just made to show you how to create a texture and apply it to a node. All you need should be in GameScene.swift.



Also, in your ViewController, make sure that your GameScene is initialised properly as shown in my project, or how you did it with this:



gameScene2 = GameScene(size: view, bounds: size)





share|improve this answer














Check out this project I just made to show you how to create a texture and apply it to a node. All you need should be in GameScene.swift.



Also, in your ViewController, make sure that your GameScene is initialised properly as shown in my project, or how you did it with this:



gameScene2 = GameScene(size: view, bounds: size)






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered Nov 4 at 14:54









George_E

838425




838425












  • I never recommend doing this, set the sks to the size of iphone x instead. You should be designing your scene with 1 size in mind, programming like this is only going to hurt you in the long run.
    – Knight0fDragon
    2 days ago


















  • I never recommend doing this, set the sks to the size of iphone x instead. You should be designing your scene with 1 size in mind, programming like this is only going to hurt you in the long run.
    – Knight0fDragon
    2 days ago
















I never recommend doing this, set the sks to the size of iphone x instead. You should be designing your scene with 1 size in mind, programming like this is only going to hurt you in the long run.
– Knight0fDragon
2 days ago




I never recommend doing this, set the sks to the size of iphone x instead. You should be designing your scene with 1 size in mind, programming like this is only going to hurt you in the long run.
– Knight0fDragon
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139513%2fhow-to-prevent-distorted-images%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()