저는 Swift and Sprite Kit를 처음 사용합니다.스프라이트 키트 버튼의 이미지를 업데이트하는 방법은 무엇입니까?
MyScene.swift에서 특정 이미지가있는 단추를 만들려고합니다. 버튼을 클릭 할 때마다 새 이미지로 버튼 이미지를 변경하고 싶습니다. 어떻게하면됩니까?
GameScene.swift
class GameScene: SKScene {
var rollButton:SKSpriteNode = SKSpriteNode(imageNamed: "dice1.png")
override func didMoveToView(view: SKView) {
rollButton.position = CGPoint(x: 79, y: 290) //this position is based to what? Is there an easier way to put a button using storyborard
rollButton.setScale(0.5) //what does setScale mean?
self.addChild(rollButton)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
if CGRectContainsPoint(rollButton.frame, touch.locationInNode(self)) {
changeButtonImage()
}
}
}
func changeButtonImage() {
//radom get value beteween 1 - 6
change the rollButton image with a new value??? //how to do that
}
- 내가 연결이 스토리 보드에 신속 GameScene을 스토리 보드에있는 UIButton을 추가하고보다 방법이 있나요? (자식 노드를 추가하면 프로그래밍 방식으로 매우 어려울 수 있습니다.)
- 노드의 CGPoint는 무엇을 기반으로합니까? 현재 UIView? 예를 들어, I는 화상이있는 경우, 프로그램의 다른 이미지 ( SpriteKit 노드를 사용하여 신속한에서) 버튼의 형상을 변경하는 방법
- : dice1, dice2, dice3을 ...
이 대물 인 C 코드 :
NSString *fileName = [NSString stringWithFormat:@"dice%d.png", num];
// Setting the uiimageview to the appropriate image
self.rollButton.image = [UIImage imageNamed:fileName];
내가 storyborard에서 버튼을 설정하는 방법에와 생성 된 각각의 새로운 GameScene에 uiviewcontrollers를 사용하는 것보다 어떤 좋은 예를 찾을 수 없습니다,