小编tal*_*lis的帖子

Swift Couple - Publishers.CombineLatest 在多个线程上

Publishers.CombineLatest当将 Publishers.CombineLatest 与运行 Main 以外的线程的 Publishers 一起使用时,并不总是调用.sink 。

这个问题并不是每次都会出现,这就是为什么我创建了连续尝试测试 100 次的单元测试。通常他们会在 4-5 次迭代后失败。

import XCTest
import Combine

class CombineLatestTests: XCTestCase {

    override func setUp() {
        continueAfterFailure = false
    }

    func testCombineLatest_receiveOn() {
        for x in 0...1000 {
            print("---------- RUN \(x)")
            let queue1 = DispatchQueue.global(qos: .userInitiated)
            let queue2 = DispatchQueue.global(qos: .background)

            let subj1 = PassthroughSubject<Int, Never>()
            let subj2 = PassthroughSubject<Int, Never>()

            let publ1 = subj1.receive(on: queue1).map { value -> Int in
                print("-- Observer 1: \(value), Thread: \(Thread.current)")
                return value
            } …
Run Code Online (Sandbox Code Playgroud)

ios swift combine

5
推荐指数
1
解决办法
1473
查看次数

如何防止两种类型的SpriteKit节点相互冲突?

我正在使用Apple Sprite Kit编写一款小游戏.

我遇到了碰撞问题.有时我不想让两个带有physicsBodys的skSpriteNodes进行交互.

作为一个例子,我有HERO,ENEMYS和SHOTS,我希望SHOTS只与ENEMYS交互.

但是当两个镜头碰撞在一起时,它们会改变它们的位置.

镜头的代码是

   shot.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:shot.size];
   shot.physicsBody.dynamic = YES;
   shot.physicsBody.allowsRotation = FALSE;
   shot.physicsBody.categoryBitMask = playerShotCategory;
   shot.physicsBody.contactTestBitMask = enemyCategory;
Run Code Online (Sandbox Code Playgroud)

并且敌人的代码是

   activeGameObject.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:activeGameObject.size];
    activeGameObject.physicsBody.dynamic = YES;
    activeGameObject.physicsBody.categoryBitMask = enemyCategory;
    activeGameObject.physicsBody.contactTestBitMask = playerCategory | playerShotCategory;
    activeGameObject.physicsBody.allowsRotation = FALSE;
Run Code Online (Sandbox Code Playgroud)

collision ios ios7 sprite-kit

4
推荐指数
1
解决办法
6756
查看次数

标签 统计

ios ×2

collision ×1

combine ×1

ios7 ×1

sprite-kit ×1

swift ×1