logo
down
shadow

Subclassing in Swift SpriteKit


Subclassing in Swift SpriteKit

By : Arijit Mitra
Date : November 22 2020, 10:38 AM
hope this fix your issue It looks like class Projectile calls super.init() before setting its own properties, and never calls setUpValues() at all, meaning your variable properties never have values.
In the Fireball subclass the setUpValues function still isn't being called, and you don't have a separate init() function, so it's the same problem: the values aren't ever being set.
code :


Share : facebook icon twitter icon
Subclassing SpriteKit classes in Swift

Subclassing SpriteKit classes in Swift


By : Nguyen Tung
Date : March 29 2020, 07:55 AM
it helps some times I'm not certain exactly why, but the hidden functionality inside SKLabelNode was trying to call an init function with no parameters. This seems to work:
code :
class HelloLabel: SKLabelNode {
    init() {
        super.init()
    }

    init(fontNamed fontName: String!) {
        super.init(fontNamed: fontName)
        self.text = "Hello, World!"
        self.fontSize = 65;
        self.position = CGPoint(x: 400, y: 500);
    }
}
Subclassing SKNodes created with SpriteKit .sks scene file

Subclassing SKNodes created with SpriteKit .sks scene file


By : edepalma
Date : March 29 2020, 07:55 AM
will help you I wrote a little helper delegate to deal with this: https://github.com/ice3-software/node-archive-delegate. It uses the NSKeyedUnarchiverDelegate to subclass your sprites by name.
how can i change my spritekit on collision in spritekit swift

how can i change my spritekit on collision in spritekit swift


By : Eky Ahamed Emon
Date : March 29 2020, 07:55 AM
wish help you to fix your issue If you want to change the Image of the Sprite, then you should use SKPhysicsContactDelegate Method.
In General that means that you have to implement the SKPhysicsContactDelegate, Make a new Struct:
code :
struct PhysicCategories {
        static let NoneC : UInt32 = 0x1 << 0
        static let Bird : UInt32 = 0x1 << 1
        static let PlatformC : UInt32 = 0x1 << 2
        static let FinishC : UInt32 = 0x1 << 3
        static let ObstacleC : UInt32 = 0x1 << 4
    } 
PhysicsWorld.contactdelegate = self
func didBeginContact(contact: SKPhysicsContact) {

        var contactbody1 = contact.bodyA
        var contactbody2 = contact.bodyB


        if contactbody1.categoryBitMask < contactbody2.categoryBitMask{

            contactbody1 = contact.bodyA
            contactbody2 = contact.bodyB


        } else {

            contactbody1 = contact.bodyB
            contactbody2 = contact.bodyA

        }

        if ((contactbody1.categoryBitMask == PhysicCategories.BirdC) && (contactbody2.categoryBitMask == PhysicCategories.ObstacleC)){
            // Make a GameOver Function for that!
            // GameOver()


        }
        if ((contactbody1.categoryBitMask == PhysicCategories.BirdC) && (contactbody2.categoryBitMask == PhysicCategories.PlatformC)){

            contactbody1.node.texture = SKTexture(imageNamed: "")



        }
ios - Swift 2.2 - SpriteKit - Looping a video with SpriteKit

ios - Swift 2.2 - SpriteKit - Looping a video with SpriteKit


By : Ivan Alejandro Lugo
Date : March 29 2020, 07:55 AM
like below fixes the issue I found the solution by compiling different precedent responses from stackoverflow. Here is the working code (swift 2.2). This code loops seamlessly the video playback with a SKSVideoNode object on the scene (with an AVPlayer initializer):
code :
override func didMoveToView(view: SKView) {

    let urlStr = NSBundle.mainBundle().pathForResource("Video_Socle", ofType: "mov")
    let url = NSURL(fileURLWithPath: urlStr!)

    player = AVPlayer(URL: url)

 NSNotificationCenter.defaultCenter().addObserverForName(AVPlayerItemDidPlayTo     EndTimeNotification
   , object: player!.currentItem, queue: nil)
    { notification in
        let t1 = CMTimeMake(5, 100);
        self.player!.seekToTime(t1)
        self.player!.play()
    }


    videoNode = SKVideoNode(AVPlayer: player!)
    videoNode!.position = CGPointMake(frame.size.width/2, frame.size.height/2)
    videoNode!.size = CGSize(width: 2048, height: 1536)
    videoNode!.zPosition = 0


    background.addChild(videoNode!)
    videoNode!.play()
Swift thinks I'm subclassing NSSet wrongly but I'm not subclassing it at all

Swift thinks I'm subclassing NSSet wrongly but I'm not subclassing it at all


By : ztluck
Date : March 29 2020, 07:55 AM
seems to work fine So figured it out, thanks to that other question (which is quite different though):
code :
guard let myClass = info.myClass as? (NSObject & MyClass).Type else { return }
let myInstance = myClass.init()
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org