Spritekit,Swift中的等轴测视图问题

时间:2014-10-07 00:56:47

标签: swift sprite-kit tile isometric

我正在尝试学习如何使用Swift在Spritekit中创建等轴测视图。我正在学习如何实现等轴测视图的几个教程(或文章),但代码似乎并不适合我 - 我想知道这是否因为在Spritekit中坐标系的范围从在480x320工作空间中-240到240和-160到160。如果是这样,我根本不确定如何纠正它。

这是我的代码:

var textures:[SKTexture] = [SKTexture(imageNamed: "Tile 3"), SKTexture(imageNamed: "Cliff test"), SKTexture(imageNamed: "Cliff test"), SKTexture(imageNamed: "Tile 3_test")]
var points:[CGPoint] = [CGPointMake(0, 0), CGPointMake(1, 0), CGPointMake(0, 1), CGPointMake(1, 1)]
var sprites:[SKSpriteNode] = [SKSpriteNode]()
let degrees:CGFloat = 45
var spriteSize:CGFloat = 50
var spriteSizeHalf:CGFloat = 25

for var i = 0; i < points.count; i++ {
    let sprite = SKSpriteNode(texture: textures[i], color: nil, size: CGSizeMake(spriteSize, spriteSize))
    let label = SKLabelNode(text: "\(i)")
    sprite.addChild(label)

    let x = points[i].x
    let y = points[i].y

    //sprite.position = CGPointMake(x*spriteSize, y*spriteSize)

    sprites.append(sprite)
    main.addChild(sprite)

    //convert to Iso

    var isoPoint = CGPointMake(x-y, (x+y)/2)
    sprite.position = CGPointMake(isoPoint.x*spriteSize, isoPoint.y*spriteSize)
    sprite.zRotation = degrees*CGFloat((M_PI / 180.00))
}

这就是结果:

photo http://imageshack.com/a/img673/3776/FbBycM.png

对此有何想法?

0 个答案:

没有答案