0 / 0 / 0
Регистрация: 28.04.2015
Сообщений: 32
|
|
1 | |
Масштабирование04.12.2015, 17:06. Показов 1267. Ответов 1
Метки нет (Все метки)
Здравствуйте, делаю игру по уроку в ютубе, там есть возможность перехода на другой уровень, но когда я на него перехожу, все изображение пропадает, мне кажется дело в размерах, как это можно исправить? https://www.cyberforum.ru/atta... 1449237991
https://www.cyberforum.ru/atta... 1449237991
0
|
04.12.2015, 17:06 | |
Ответы с готовыми решениями:
1
Scaling или масштабирование Масштабирование картинки Swift xCode масштабирование масштабирование |
0 / 0 / 0
Регистрация: 28.04.2015
Сообщений: 32
|
|
07.12.2015, 16:52 [ТС] | 2 |
Вот первый документ GameScene.swift:
Код
struct PhysicsCategory { static let En: UInt32 = 1 static let Bullet: UInt32 = 2 static let Player: UInt32 = 3 } class GameScene: SKScene, SKPhysicsContactDelegate { var Player = SKSpriteNode(imageNamed: "Image") var score = Int() var Scorelbl = UILabel() override func didMoveToView(view: SKView) { physicsWorld.contactDelegate = self self.scene?.size = CGSize(width: self.frame.size.width, height: self.frame.size.height) Player.position = CGPointMake(self.size.width / 2, self.size.height / 5) Player.physicsBody = SKPhysicsBody(rectangleOfSize: Player.size) Player.physicsBody?.affectedByGravity = false Player.physicsBody?.categoryBitMask = PhysicsCategory.Player Player.physicsBody?.contactTestBitMask = PhysicsCategory.En Player.physicsBody?.dynamic = false var Timer = NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: Selector("Spaw"), userInfo: nil, repeats: true) var EnTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("SpawEn"), userInfo: nil, repeats: true) self.addChild(Player) Scorelbl.text = "\(score)" Scorelbl = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20)) Scorelbl.backgroundColor = UIColor.whiteColor() Scorelbl.textColor = UIColor.blackColor() self.view?.addSubview(Scorelbl) } func didBeginContact(contact: SKPhysicsContact) { var firstBody : SKPhysicsBody = contact.bodyA var secondBody: SKPhysicsBody = contact.bodyB if ((firstBody.categoryBitMask == PhysicsCategory.En) && (secondBody.categoryBitMask == PhysicsCategory.Bullet) || (firstBody.categoryBitMask == PhysicsCategory.Bullet) && (secondBody.categoryBitMask == PhysicsCategory.En)){ collisionBullet(firstBody.node as! SKSpriteNode, Bullet: secondBody.node as! SKSpriteNode) } else if ((firstBody.categoryBitMask == PhysicsCategory.En) && (secondBody.categoryBitMask == PhysicsCategory.Player) || (firstBody.categoryBitMask == PhysicsCategory.Player) && (secondBody.categoryBitMask == PhysicsCategory.En)){ collisionWithPerson(firstBody.node as! SKSpriteNode, Person: secondBody.node as! SKSpriteNode) } } func collisionBullet(En: SKSpriteNode, Bullet: SKSpriteNode){ En.removeFromParent() Bullet.removeFromParent() score++ Scorelbl.text = "\(score)" } func collisionWithPerson(En: SKSpriteNode, Person: SKSpriteNode){ En.removeFromParent() Person.removeFromParent() view?.presentScene(Next()) Scorelbl.removeFromSuperview() } func Spaw(){ var Bullet = SKSpriteNode(imageNamed: "Image-1") Bullet.zPosition = -5 Bullet.position = CGPointMake(Player.position.x, Player.position.y) let action = SKAction.moveToY(self.size.height + 30, duration: 1.0) let actionDone = SKAction.removeFromParent() Bullet.runAction(SKAction.sequence([action, actionDone])) Bullet.runAction(SKAction.repeatActionForever(action)) Bullet.physicsBody = SKPhysicsBody(rectangleOfSize: Bullet.size) Bullet.physicsBody?.categoryBitMask = PhysicsCategory.Bullet Bullet.physicsBody?.contactTestBitMask = PhysicsCategory.En Bullet.physicsBody?.affectedByGravity = false Bullet.physicsBody?.dynamic = false self.addChild(Bullet) } func SpawEn(){ var En = SKSpriteNode(imageNamed: "Image-2") var minVal = self.size.width / 8 var maxVal = self.size.width - 20 var Point = UInt32(maxVal - minVal) En.position = CGPoint(x: CGFloat(arc4random_uniform(Point)), y: self.size.height) En.physicsBody = SKPhysicsBody(rectangleOfSize: En.size) En.physicsBody?.categoryBitMask = PhysicsCategory.En En.physicsBody?.contactTestBitMask = PhysicsCategory.Bullet En.physicsBody?.affectedByGravity = false En.physicsBody?.dynamic = true let action = SKAction.moveToY(-60, duration: 3.0) En.runAction(SKAction.repeatActionForever(action)) let actionDone = SKAction.removeFromParent() En.runAction(SKAction.sequence([action, actionDone])) self.addChild(En) } override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { /* Called when a touch begins */ for touch in touches { let location = touch.locationInNode(self) Player.position.x = location.x } } override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch in touches { let location = touch.locationInNode(self) Player.position.x = location.x } } override func update(currentTime: CFTimeInterval) { /* Called before each frame is rendered */ } } Код
class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene(fileNamed:"GameScene") { // Configure the view. let skView = self.view as! SKView skView.showsFPS = true skView.showsNodeCount = true /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ scene.scaleMode = .AspectFill skView.presentScene(scene) } } override func shouldAutorotate() -> Bool { return true } override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { if UIDevice.currentDevice().userInterfaceIdiom == .Phone { return .AllButUpsideDown } else { return .All } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Release any cached data, images, etc that aren't in use. } override func prefersStatusBarHidden() -> Bool { return true } } Код
class Next: SKScene{ var RestartB : UIButton! override func didMoveToView(view: SKView) { scene?.backgroundColor = UIColor.redColor() RestartB = UIButton(frame: CGRect(x: 0, y: 0, width: view.frame.size.width / 3, height: 30)) RestartB.center = CGPointMake(view.frame.size.width / 2, view.frame.size.width / 7) RestartB.setTitle("Restart", forState: UIControlState.Normal) RestartB.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal) RestartB.addTarget(self, action: Selector("Restart"), forControlEvents: UIControlEvents.TouchUpInside) self.view?.addSubview(RestartB) } func Restart(){ self.view?.presentScene(Start(), transition: SKTransition.flipHorizontalWithDuration(0.3)) RestartB.removeFromSuperview() } } struct PhysicssCategory { static let En: UInt32 = 1 static let Bullet: UInt32 = 2 static let Player: UInt32 = 3 }
0
|
07.12.2015, 16:52 | |
07.12.2015, 16:52 | |
Помогаю со студенческими работами здесь
2
Масштабирование Масштабирование Масштабирование Масштабирование Искать еще темы с ответами Или воспользуйтесь поиском по форуму: |