- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
您好,我正在尝试修复这个 spritekit 的物理形状倒置的错误。
[SKPhysicsBody bodyWithTexture:monsterTexture size:monsterTexture.size]
怪物第一次出现时,物理 body 方向是正确的。但是第二次和之后的每一次怪物出现,它的物理 body 都沿着 Y 轴倒转。查看图片,其中 skView.showsPhysics = true;
显示物理形状。它第一次正常工作的事实让我觉得也许我不知道的一些属性正在被修改或什么的。
我想将 2 个物理 block 放在 Boot 的粗略形状中,但这并不理想,因为我想在其他一些更复杂的形状上使用 bodyWithTexture,它们也遇到了同样的错误。
我还尝试了 bodyWithTexture:monsterTexture
,原始 SKTexture 对象而不是 bodyWithTexture:monster.texture
,Monster 对象的纹理。
这是我添加怪物的代码。如果您需要更多,请告诉我。
- (Monster *)monster:(NSDictionary *)settings
{
NSDictionary * monsterDefaults = [self monsterDefaults];
NSDictionary * monsterConfig = [self monsterConfig:settings[TYPE]];
SKTexture * monsterTexture = monsterConfig[TEXTURE] ? monsterConfig[TEXTURE] : monsterDefaults[TEXTURE];
Monster * monster = [Monster spriteNodeWithTexture:monsterTexture];
// Animation
if (monsterConfig[ANIMATION]) {
[monster runAction:monsterConfig[ANIMATION]];
}
// Moster Stats
monster.name = MONSTER_SPRITE;
monster.type = settings[TYPE];
monster.points = monsterConfig[POINTS] ? [monsterConfig[POINTS] intValue] : [monsterDefaults[POINTS] intValue];
monster.damage = monsterConfig[DAMAGE] ? [monsterConfig[DAMAGE] intValue] : [monsterDefaults[DAMAGE] intValue];
monster.hp = monsterConfig[HP] ? [monsterConfig[HP] intValue] : [monsterDefaults[HP] intValue];
monster.lethal = monsterConfig[LETHAL] ? [monsterConfig[LETHAL] boolValue] : [monsterDefaults[LETHAL] boolValue];
// Monster Physics
float physicsResize = monsterConfig[RESIZE] ? [monsterConfig[RESIZE] floatValue] : [monsterDefaults[RESIZE] floatValue];
switch ([monsterConfig[SHAPE] intValue]) {
case COMPLEX:
NSLog(@"%@", monster.texture);
NSLog(@"rotation: %f", monster.zRotation);
NSLog(@"x scale: %f", monster.xScale);
NSLog(@"y scale: %f", monster.yScale);
monster.physicsBody = [SKPhysicsBody bodyWithTexture:monster.texture size:monster.texture.size];
break;
case RECTANGLE:
monster.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(monster.size.width * physicsResize, monster.size.height * physicsResize)];
break;
default:
monster.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:(monster.size.height * physicsResize) / 2];
break;
}
monster.physicsBody.dynamic = false;
monster.physicsBody.affectedByGravity = false;
monster.physicsBody.categoryBitMask = monsterCategory;
monster.physicsBody.contactTestBitMask = weaponCategory | heroCategory;
monster.physicsBody.collisionBitMask = defaultCategory;
// Monster Flight Pattern
SKAction * flightPattern = [self monsterFlightPattern:monster settings:settings];
// Monster Rotation
// Rotation disabled for physics text
// [self monsterRotation:monster rotationConfig:monsterConfig[ROTATION]];
// Move & Remove
SKAction * remove = [Config removeAction:monster];
[monster runAction:[SKAction sequence:@[flightPattern, remove]]];
return monster;
}
我在类加载时缓存纹理
@property (nonatomic) SKTexture * monsterBootTexture;
...
- (id)initWithFrameSize:(CGSize)frameSize
{
...
SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:monsterAtlas];
self.monsterBootTexture = [atlas textureNamed:MONSTER_BOOT];
...
}
NSLog是这样写的:
2015-01-02 12:03:20.619 Gadget Blaster[3301:665394] <SKTexture> 'boot.png' (97 x 100)
2015-01-02 12:03:20.623 Gadget Blaster[3301:665394] <SKTexture> 'boot.png' (97 x 100)
我根据 LearnCocos2D 的评论添加了以下日志:
2015-01-03 12:00:06.131 Gadget Blaster[3987:772046] rotation: 0.000000
2015-01-03 12:00:06.133 Gadget Blaster[3987:772046] x scale: 1.000000
2015-01-03 12:00:06.134 Gadget Blaster[3987:772046] y scale: 1.000000
2015-01-03 12:00:08.131 Gadget Blaster[3987:772046] rotation: 0.000000
2015-01-03 12:00:08.131 Gadget Blaster[3987:772046] x scale: 1.000000
2015-01-03 12:00:08.132 Gadget Blaster[3987:772046] y scale: 1.000000
2015-01-03 12:00:10.156 Gadget Blaster[3987:772046] rotation: 0.000000
2015-01-03 12:00:10.156 Gadget Blaster[3987:772046] x scale: 1.000000
2015-01-03 12:00:10.159 Gadget Blaster[3987:772046] y scale: 1.000000
此外,在使用复杂物理体时,我遇到了一些意想不到的碰撞问题。 SKPhysicsBody bodyWithCircleOfRadius
似乎表现得更好,我正在考虑让所有的怪物都成为圆形物理形状。
最佳答案
我认为这是 iOS8 上 Spritekit 的一个错误。我怀疑当物理体的纹理从内部缓存中检索时会出现错误。它可能会错误地翻转图像以尝试更正来自 CoreGraphics 的坐标系。
改用 bodyWithBodies。糟糕,我真的很喜欢这个功能。
关于ios - SpriteKit SKPhysicsBody bodyWithTexture 颠倒了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27748034/
我正在 Swift 中使用 SpriteKit 制作一款平台游戏,其中涉及一个跳跃的主角。然而,一旦关卡加载,玩家就会立即掉到地上。 You can see it in action here. 我使
我有一个简单的游戏玩法,功能如下: 我的目标是检测球何时击中白色部分(游戏结束场景将加载)或球何时击中灰色部分(游戏继续) 因为形状缩小并且有很多东西在进行,我认为在需要时创建 SKPhysicsBo
我正在构建一个 SpriteKit“链式 react ”游戏,其中的圆圈在“爆炸”时会变大。我正在使用 SKPhysicsBody(circleOfRadius:) 初始值设定项来为圆圈创建物理体。
我正在按照《Swift 3 游戏开发》一书的说明创建一个简单的点击拍打游戏。我有两个 SKSpriteNode,一个是玩家,另一个是静态对象,如果接触就会伤害玩家。 对玩家的伤害将通过category
我必须遵循为我的敌人制作自定义physicalBody的代码。请参阅下面的代码: let offsetX = CGFloat(Enemy.frame.size.width * Enemy.anchor
我有一个随机迷宫生成器,它开始 build 小迷宫,然后进入大型关卡。 “C”是收藏品,“T”是瓷砖。 “P”是玩家的起始位置。我在下面包含了一个示例瓦片 map 。 当我有像这里这样的 6x12 小
是否可以检测节点是否仅在一侧与另一侧发生碰撞? 例如,一只动物与另一只动物发生冲突。在这种情况下,碰撞检测方法被调用。但是当动物跳过动物并在其上“行走”时,碰撞检测不会被激活。 我将不胜感激每一个答案
我有一个播放器。他必须跳过一些街区。 但是,似乎 SKPhysicsBody(rectangleOfSize: ... ) 没有正确对齐。当角色撞到方 block 的上半部分时,它只是穿过而他不能从下
我在屏幕上有一个图像,它是一个 SKSpriteNode,上面附有一个 SKPhysicsBody。我试图通过倾斜设备在屏幕上四处移动它。我让它沿 x 轴移动,但我似乎无法让它沿 y 轴移动。 我使用
有什么简单的方法可以测试 SKPhysicsBody 是否完全包含另一个? 像 bodyA 这样的东西包含了 bodyB 的每个点,左右。 只是想在实现一些 2D 数学助手之前问你如何使用附加的“元”
我正在创建一个简单的 Sprite Kit 游戏,但是当我将 PhysicsBody 添加到我的一个 Sprite 时,它似乎处于错误的位置。我知道它在我设置的错误位置skView.showsPhys
我将使用哪种 SKPhysicsBody 主体类型来创建椭圆物理主体? 我知道我可以用直线做一条曲线,只是让它不是一个真正的椭圆,但似乎必须有某种方法来挤压一个圆或创建一个圆? 最佳答案 Create
我的目标是旋转一个圆形节点,就像一个由电机驱动的轮子,例如顺时针旋转时,由于地板的摩擦力,轮子会向右移动。 根据其他线程,旋转 SKPhysicsBody 的方法是旋转它所连接的主体。 此代码旋转 S
出于某种原因,当我在这个场景中为这个 SKSpriteNodes 创建一个 SKPhysicsBody 时,物理体看起来比它们应该的小得多。例如(请忽略蓝链): 如您所见,形状在其下方复制,但主体要高
我想知道如何创建一个像这样更复杂的 SKPhysicsyBody?我想对黑色部分进行hittest。 我用 PaintCode 将这个形状导出到 CG 矩形。 var barrierpath2Path
我在父节点 B 中有一个节点 A。 我在节点 B 上使用 setScale 来产生缩放的错觉,但是当我这样做时,节点 A 及其所有 sibling 都没有预期的物理体。 尽管 A 看起来越来越小,但它
所以我正在尝试使用两个 SKPhysicsBody 对象。我在看一些教程来帮助处理碰撞机制并处理它。 我从其中一个教程中提取了这段代码: func didBeginContact(contac
我目前正在开发一款游戏,其中我有一张圆柱形物体的图片,我用以下内容制作了一个 SKPhysicsBody: self.oval.node.physicsBody = SKPhysicsBody(tex
下面是我的“Floor.swift”类,下面基本上是一堆墙。我有来自屏幕顶部的对象,一旦 Floor 和 SKSpriteNodes 发生碰撞,我希望 SKSpriteNode 被移除。下面是我的 F
我想知道是否有一个工具可以用来在 SpriteKit 中轻松生成复杂的物理体。我想要一个具有多边形形状的基于体积的物理体。 SpriteKit 允许使用该方法创建这样的主体: + (SKPhysics
我是一名优秀的程序员,十分优秀!