小编Jer*_*911的帖子

精灵套件 - 弹簧接头(减震器)

关闭,谢谢@Smick在这里发布的初始车辆代码: Sprite Kit销接头似乎有一个不正确的锚

我正在尝试在车轮(左轮)和底盘之间添加滑动接头以及弹簧接头,以产生减震效果.

使用下面的代码,我没有压缩.我意识到文档显示了一个弹簧接头将两个节点拉在一起 - 与我想要的相反.这可能在SK吗?

我认为针接头可能是罪魁祸首?当我注释掉销钉接头时,汽车零件会变得混乱 - 一切都在屏幕上飞舞.最初,销接头将车轮固定在底盘上,但显然我想将车轮固定在"减震器"上.

此外,SKPhysicsJointSliding的"轴"参数让我有点困惑.它想要一个矢量.一个向量相对于?

先感谢您.

- (SKShapeNode*) makeWheel
{
SKShapeNode *wheel = [[SKShapeNode alloc] init];
CGMutablePathRef myPath = CGPathCreateMutable();
CGPathAddArc(myPath, NULL, 0,0, 16, 0, M_PI*2, YES);
wheel.path = myPath;
wheel.physicsBody.mass = 0.5;
return wheel;
}

- (void) createCar{

// 1. car body
SKSpriteNode *carBody = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(120, 8)];
carBody.position = CGPointMake(200, 700);
carBody.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:carBody.size];
carBody.physicsBody.mass = 1.0;
[self addChild:carBody];

// 2. wheels
SKShapeNode *leftWheel = [self makeWheel];
leftWheel.position = …
Run Code Online (Sandbox Code Playgroud)

spring ios sprite-kit

7
推荐指数
1
解决办法
3715
查看次数

Sprite Kit:如何子类化SKNode以创建Vehicle类(带关节的复杂对象)

有没有人想出(本地)如何将SKNode子类化为包含多个通过关节连接的物体 - 例如,汽车?

似乎没有办法将子类的关节添加到父场景的physicsWorld属性中.

此外,当尝试编译并运行下面的对象时,即使没有关节,我也会收到BAD_EXC_ACCESS错误.

感谢@Smick在此处发布的初始车辆代码:Sprite Kit引脚接头似乎有一个不正确的锚点

卡车类:

#import "Truck.h"

@implementation Truck


-(id)initWithPosition:(CGPoint)pos {


SKSpriteNode *carBody = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(120, 8)];
carBody.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:carBody.size];
carBody.position = pos;
carBody.physicsBody.mass = 1.0;


SKSpriteNode *carTop = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(50, 8)];
carTop.position = CGPointMake(230, 708);
carTop.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:carTop.size];
carTop.physicsBody.mass = 0;

SKPhysicsJointFixed *carBodyJoint = [SKPhysicsJointFixed jointWithBodyA:carBody.physicsBody
                                                                  bodyB:carTop.physicsBody
                                                                 anchor:CGPointMake(0, 0)];



return self;
}

+(Truck*)initWithPosition:(CGPoint)pos {
return [[self alloc] initWithPosition:pos];
}


@end
Run Code Online (Sandbox Code Playgroud)

MyScene: 在此输入图像描述

subclass sprite-kit sknode

3
推荐指数
1
解决办法
5148
查看次数

Angular 5+ RxJS订阅主题不起作用

我有一个已订阅的可观察的服务。有效负载被传递到服务中的主题上。但是,当我在组件中订阅该主题时,没有任何反应。我应该在组件console.log中的.subscribe方法中 看到ngOnInit

我在以前的版本中使用了相同的设置,该版本订阅了http.get操作产生的可观察结果。我想知道为什么它不适用于该版本。

服务:

@Injectable()
export class TileService {

  availableTiles$ = new Subject<any>();

  // The view is expecing an array, else: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
  source: {}[] = [
    {title: 'Title A'},
    {title: 'Title B'}
  ];

  simpleObservable = new Observable((observer) => {
    observer.next(this.source);
    observer.complete();
});

  constructor() { }

  getTiles(): void {
    this.simpleObservable.subscribe(x => this.availableTilesStream(x));
  }

  availableTilesStream(data) {
    console.log(data);                // Logs an array of the two objects …
Run Code Online (Sandbox Code Playgroud)

rxjs angular

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

标签 统计

sprite-kit ×2

angular ×1

ios ×1

rxjs ×1

sknode ×1

spring ×1

subclass ×1