我正在使用Swift和SpriteKit开发游戏。我希望背景在某个分数上发生变化。这是代码:
class GameScene: SKScene {
var bg = SKSpriteNode()
override func didMoveToView(view: SKView) {
makeBg()
}
func makeBg() {
let bgTexture = SKTexture(imageNamed: "img/bg.png")
let moveBg = SKAction.moveByX(-bgTexture.size().width, y: 0, duration: 9)
let replaceBg = SKAction.moveByX(bgTexture.size().width, y: 0, duration:0)
let animateBg = SKAction.repeatActionForever(SKAction.sequence([moveBg, replaceBg]))
for var i: CGFloat = 0; i<3; i++ {
let bg = SKSpriteNode(texture: bgTexture)
bg.name = "background"
bg.position = CGPoint(x: bgTexture.size().width/2 + bgTexture.size().width * i, y: CGRectGetMidY(self.frame))
bg.size.height = self.frame.height
bg.runAction(animateBg)
addChild(bg)
}
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if score == 0 {
bg.texture = SKTexture(imageNamed: "img/bg.png")
} else if score == 3 {
bg.texture = SKTexture(imageNamed: "img/bgOri.png")
}
}
但是图像不会改变......错误在哪里?
答案 0 :(得分:2)
因此,您可以在for循环中创建的所有节点上更改纹理:
session_start();
require_once '../../lib/mailer/PHPMailerAutoload.php';
$errors = [];
if(isset($_POST['fname'], $_POST['lname'], $_POST['email'], $_POST['contactno'], $_POST['message'])){
$fields = [
'fname'=>$_POST['fname'],
'lname'=>$_POST['lname'],
'email'=>$_POST['email'],
'contactno'=> $_POST['contactno'],
'message'=> $_POST['message']
];
foreach($fields as $field => $data){
if (empty($data)){
$errors[]='The ' . $field . ' field is required.';
}
}
if(empty($errors)){
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->Host = 'smtp.gmail.com';
$m->Username = 'icyraud@gmail.com';
$m->Password = 'giantboq1';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->isHTML();
$m->Subject = 'Contact Form Submitted';
$m->Body = 'From: ' . $fields['fname'] .' '. $fields['lname']. ' (' . $fields['email'] . ')<p>' . $fields['message'] . '</p>';
$m->FromName = 'Contact';
$m->AddAddress('icyraud@gmail.com','JDGS Company');
if($m->send()){
header('Location: thanks.php');
die();
} else{
$errors[]= 'Sorry, could not send email. Try again later.';
}
}
} else{
$errors[] = 'Something went wrong';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('Location: contact-us.php');
请注意,您不需要在GameScene中定义bg属性来实现此目的。