我创建了一个球节点,并应用了3d模型中的纹理图像。我总共捕获了6张图像,其中3张图像(具有120度)用于绕x轴滚动,其余3张图像用于绕y轴滚动。我想要精灵套件使用下面的代码来模拟它。当我施加脉冲时,它开始滑动而不是滚动,并且当它碰撞到侧面时,它开始旋转但又不滚动。通常,根据对球的冲动,它有时应转动并滚动在一起。我想获得结果的例子是“ 8球池游戏”球的效果。
var ball = SKSpriteNode()
var textureAtlas = SKTextureAtlas()
var textureArray = [SKTexture]()
override func didMove(to view: SKView) {
textureAtlas = SKTextureAtlas(named: "white")
for i in 0... textureAtlas.textureNames.count {
let name = "ball_\(i).png"
textureArray.append(SKTexture(imageNamed: name))
}
ball = SKSpriteNode(imageNamed: textureAtlas.textureNames[0])
ball.size = CGSize(width: ballRadius*2, height: ballRadius*2)
ball.position = CGPoint(x: -ballRadius/2-20, y: -ballRadius-20)
ball.zPosition = 0
ball.physicsBody = SKPhysicsBody(circleOfRadius: ballRadius)
ball.physicsBody?.isDynamic = true
ball.physicsBody?.restitution = 0.3
ball.physicsBody?.linearDamping = 0
ball.physicsBody?.allowsRotation = true
addChild(ball)}
答案 0 :(得分:0)
您需要施加角度冲动才能使其旋转
var getRectArea = function(width, height) {
return width * height;
};
console.log("Area of Rectangle: " + getRectArea(3,4));
// This should return the following result in the console:
// Area of Rectangle: 12