Type 'UIImage' has no member 'radialGradientImage'












0















I'm trying to use a color gradient for the background of a scene in my sprite kit game. So it looks similar to this:



enter image description here



I need help solving the following error:




Type 'UIImage' has no member 'radialGradientImage'




The code:



import UIKit
import SpriteKit
import StoreKit
import GameKit
import AVFoundation
import SpriteKit.SKTexture

class Start: SKScene {
let color1 = UIColor(red: 255/255, green: 153/255, blue: 102/255, alpha: 1)
let color2 = UIColor(red: 255/255, green: 204/255, blue: 153/255, alpha: 1)

//Error ->
let backgroundImg = UIImage.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)

//

let backgroundTexture = SKTexture(image: backgroundImg)
let background = SKSpriteNode(texture: backgroundTexture)

override func didMove(to view: SKView) {
//Background
background.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
addChild(background)
}

static func radialGradientImage(size: CGSize, outerColor: UIColor, innerColor: UIColor) -> UIImage
{
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorsSpace: colorSpace, colors: [outerColor.cgColor, innerColor.cgColor] as CFArray, locations: [1.0, 0.0])
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0)

UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
let imageContext = UIGraphicsGetCurrentContext()

imageContext!.drawRadialGradient(gradient!, startCenter: center, startRadius: 0.0, endCenter: center, endRadius: size.width / 2.0, options: CGGradientDrawingOptions.drawsAfterEndLocation)

let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return image!
}
}









share|improve this question

























  • stackoverflow.com/questions/24380535/…

    – Leo Dabus
    Nov 25 '18 at 16:08











  • But I have a SKScene @LeoDabus

    – Joy Lucas
    Nov 25 '18 at 16:15
















0















I'm trying to use a color gradient for the background of a scene in my sprite kit game. So it looks similar to this:



enter image description here



I need help solving the following error:




Type 'UIImage' has no member 'radialGradientImage'




The code:



import UIKit
import SpriteKit
import StoreKit
import GameKit
import AVFoundation
import SpriteKit.SKTexture

class Start: SKScene {
let color1 = UIColor(red: 255/255, green: 153/255, blue: 102/255, alpha: 1)
let color2 = UIColor(red: 255/255, green: 204/255, blue: 153/255, alpha: 1)

//Error ->
let backgroundImg = UIImage.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)

//

let backgroundTexture = SKTexture(image: backgroundImg)
let background = SKSpriteNode(texture: backgroundTexture)

override func didMove(to view: SKView) {
//Background
background.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
addChild(background)
}

static func radialGradientImage(size: CGSize, outerColor: UIColor, innerColor: UIColor) -> UIImage
{
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorsSpace: colorSpace, colors: [outerColor.cgColor, innerColor.cgColor] as CFArray, locations: [1.0, 0.0])
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0)

UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
let imageContext = UIGraphicsGetCurrentContext()

imageContext!.drawRadialGradient(gradient!, startCenter: center, startRadius: 0.0, endCenter: center, endRadius: size.width / 2.0, options: CGGradientDrawingOptions.drawsAfterEndLocation)

let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return image!
}
}









share|improve this question

























  • stackoverflow.com/questions/24380535/…

    – Leo Dabus
    Nov 25 '18 at 16:08











  • But I have a SKScene @LeoDabus

    – Joy Lucas
    Nov 25 '18 at 16:15














0












0








0








I'm trying to use a color gradient for the background of a scene in my sprite kit game. So it looks similar to this:



enter image description here



I need help solving the following error:




Type 'UIImage' has no member 'radialGradientImage'




The code:



import UIKit
import SpriteKit
import StoreKit
import GameKit
import AVFoundation
import SpriteKit.SKTexture

class Start: SKScene {
let color1 = UIColor(red: 255/255, green: 153/255, blue: 102/255, alpha: 1)
let color2 = UIColor(red: 255/255, green: 204/255, blue: 153/255, alpha: 1)

//Error ->
let backgroundImg = UIImage.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)

//

let backgroundTexture = SKTexture(image: backgroundImg)
let background = SKSpriteNode(texture: backgroundTexture)

override func didMove(to view: SKView) {
//Background
background.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
addChild(background)
}

static func radialGradientImage(size: CGSize, outerColor: UIColor, innerColor: UIColor) -> UIImage
{
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorsSpace: colorSpace, colors: [outerColor.cgColor, innerColor.cgColor] as CFArray, locations: [1.0, 0.0])
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0)

UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
let imageContext = UIGraphicsGetCurrentContext()

imageContext!.drawRadialGradient(gradient!, startCenter: center, startRadius: 0.0, endCenter: center, endRadius: size.width / 2.0, options: CGGradientDrawingOptions.drawsAfterEndLocation)

let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return image!
}
}









share|improve this question
















I'm trying to use a color gradient for the background of a scene in my sprite kit game. So it looks similar to this:



enter image description here



I need help solving the following error:




Type 'UIImage' has no member 'radialGradientImage'




The code:



import UIKit
import SpriteKit
import StoreKit
import GameKit
import AVFoundation
import SpriteKit.SKTexture

class Start: SKScene {
let color1 = UIColor(red: 255/255, green: 153/255, blue: 102/255, alpha: 1)
let color2 = UIColor(red: 255/255, green: 204/255, blue: 153/255, alpha: 1)

//Error ->
let backgroundImg = UIImage.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)

//

let backgroundTexture = SKTexture(image: backgroundImg)
let background = SKSpriteNode(texture: backgroundTexture)

override func didMove(to view: SKView) {
//Background
background.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
addChild(background)
}

static func radialGradientImage(size: CGSize, outerColor: UIColor, innerColor: UIColor) -> UIImage
{
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorsSpace: colorSpace, colors: [outerColor.cgColor, innerColor.cgColor] as CFArray, locations: [1.0, 0.0])
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0)

UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
let imageContext = UIGraphicsGetCurrentContext()

imageContext!.drawRadialGradient(gradient!, startCenter: center, startRadius: 0.0, endCenter: center, endRadius: size.width / 2.0, options: CGGradientDrawingOptions.drawsAfterEndLocation)

let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return image!
}
}






ios swift sprite-kit gradient radial-gradients






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 15:48









rmaddy

244k27324386




244k27324386










asked Nov 25 '18 at 15:17









Joy LucasJoy Lucas

115




115













  • stackoverflow.com/questions/24380535/…

    – Leo Dabus
    Nov 25 '18 at 16:08











  • But I have a SKScene @LeoDabus

    – Joy Lucas
    Nov 25 '18 at 16:15



















  • stackoverflow.com/questions/24380535/…

    – Leo Dabus
    Nov 25 '18 at 16:08











  • But I have a SKScene @LeoDabus

    – Joy Lucas
    Nov 25 '18 at 16:15

















stackoverflow.com/questions/24380535/…

– Leo Dabus
Nov 25 '18 at 16:08





stackoverflow.com/questions/24380535/…

– Leo Dabus
Nov 25 '18 at 16:08













But I have a SKScene @LeoDabus

– Joy Lucas
Nov 25 '18 at 16:15





But I have a SKScene @LeoDabus

– Joy Lucas
Nov 25 '18 at 16:15












1 Answer
1






active

oldest

votes


















0














radialGradientImage is a static method of your Start class, not the UIImage class.



You want:



let backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)


But that is going to fail with more errors because you can't access frame, color1, or color2 there.



You need to change let to lazy var:



lazy var backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)





share|improve this answer
























  • Thanks that worked well. Is there also a possibility to use a vertical gradient instead of a radial gradient (like the gradient from the screenshot in my question)?

    – Joy Lucas
    Nov 25 '18 at 15:44











  • That's a completely separate question. Mark this one as solved by clicking the checkmark to the left of the answer. If you have a new question about gradients, post an new question if needed after doing some research first.

    – rmaddy
    Nov 25 '18 at 15:46











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%2f53468907%2ftype-uiimage-has-no-member-radialgradientimage%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














radialGradientImage is a static method of your Start class, not the UIImage class.



You want:



let backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)


But that is going to fail with more errors because you can't access frame, color1, or color2 there.



You need to change let to lazy var:



lazy var backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)





share|improve this answer
























  • Thanks that worked well. Is there also a possibility to use a vertical gradient instead of a radial gradient (like the gradient from the screenshot in my question)?

    – Joy Lucas
    Nov 25 '18 at 15:44











  • That's a completely separate question. Mark this one as solved by clicking the checkmark to the left of the answer. If you have a new question about gradients, post an new question if needed after doing some research first.

    – rmaddy
    Nov 25 '18 at 15:46
















0














radialGradientImage is a static method of your Start class, not the UIImage class.



You want:



let backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)


But that is going to fail with more errors because you can't access frame, color1, or color2 there.



You need to change let to lazy var:



lazy var backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)





share|improve this answer
























  • Thanks that worked well. Is there also a possibility to use a vertical gradient instead of a radial gradient (like the gradient from the screenshot in my question)?

    – Joy Lucas
    Nov 25 '18 at 15:44











  • That's a completely separate question. Mark this one as solved by clicking the checkmark to the left of the answer. If you have a new question about gradients, post an new question if needed after doing some research first.

    – rmaddy
    Nov 25 '18 at 15:46














0












0








0







radialGradientImage is a static method of your Start class, not the UIImage class.



You want:



let backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)


But that is going to fail with more errors because you can't access frame, color1, or color2 there.



You need to change let to lazy var:



lazy var backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)





share|improve this answer













radialGradientImage is a static method of your Start class, not the UIImage class.



You want:



let backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)


But that is going to fail with more errors because you can't access frame, color1, or color2 there.



You need to change let to lazy var:



lazy var backgroundImg = Start.radialGradientImage(size: frame.size, outerColor: color1, innerColor: color2)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 15:30









rmaddyrmaddy

244k27324386




244k27324386













  • Thanks that worked well. Is there also a possibility to use a vertical gradient instead of a radial gradient (like the gradient from the screenshot in my question)?

    – Joy Lucas
    Nov 25 '18 at 15:44











  • That's a completely separate question. Mark this one as solved by clicking the checkmark to the left of the answer. If you have a new question about gradients, post an new question if needed after doing some research first.

    – rmaddy
    Nov 25 '18 at 15:46



















  • Thanks that worked well. Is there also a possibility to use a vertical gradient instead of a radial gradient (like the gradient from the screenshot in my question)?

    – Joy Lucas
    Nov 25 '18 at 15:44











  • That's a completely separate question. Mark this one as solved by clicking the checkmark to the left of the answer. If you have a new question about gradients, post an new question if needed after doing some research first.

    – rmaddy
    Nov 25 '18 at 15:46

















Thanks that worked well. Is there also a possibility to use a vertical gradient instead of a radial gradient (like the gradient from the screenshot in my question)?

– Joy Lucas
Nov 25 '18 at 15:44





Thanks that worked well. Is there also a possibility to use a vertical gradient instead of a radial gradient (like the gradient from the screenshot in my question)?

– Joy Lucas
Nov 25 '18 at 15:44













That's a completely separate question. Mark this one as solved by clicking the checkmark to the left of the answer. If you have a new question about gradients, post an new question if needed after doing some research first.

– rmaddy
Nov 25 '18 at 15:46





That's a completely separate question. Mark this one as solved by clicking the checkmark to the left of the answer. If you have a new question about gradients, post an new question if needed after doing some research first.

– rmaddy
Nov 25 '18 at 15:46




















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%2f53468907%2ftype-uiimage-has-no-member-radialgradientimage%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

Costa Masnaga

Fotorealismo

Sidney Franklin