2016年8月8日 星期一

iPhone 模擬器雙指動作

Ref:http://stackoverflow.com/questions/13275832/how-to-mimic-two-finger-scroll-drag-gesture-on-ios-simulator
Macbook pro (OS X EI Captian 10.11.5)
Xcode 7.3.1
1. Alt鍵 + 滑鼠 (Zoom)
2. Alt+ Shift 鍵 + 滑鼠 (Pan)


2016年8月3日 星期三

Mac OSX Game 2

Ref:https://www.raywenderlich.com/119815/sprite-kit-swift-2-tutorial-for-beginners
Macbook pro (OS X EI Captian 10.11.5)
Xcode 7.3.1
1. 準備ninja.png monster.png
2. 開啟新Game專案
3. 取消Portrait設定
4. 刪除 GameScene.sks (本例不需)
5. 開啟Assets.xcassets
    載入 ninja.png, monster.png
6. 開啟GameScene.swift
     以程式加入小圖片(Sprite)  
7. 加入ninja.png (name : player)
         // 1
        let player = SKSpriteNode(imageNamed: "Player")
        override func didMoveToView(view: SKView) {
        // 2
        backgroundColor = SKColor.whiteColor()
        // 3
        player.position = CGPoint(x: size.width * 0.1, y: size.height * 0.5)
        // 4
        addChild(player)
8. 以程式加入 monster
    //----- 2016.8.3
        runAction(SKAction.repeatActionForever(
            SKAction.sequence([
                SKAction.runBlock(addMonster),
                SKAction.waitForDuration(1.0)
                ])
            ))
    //-----
9. 加入mouseDown (iOS 用touchesEnded )
   //------
    override func mouseDown(theEvent: NSEvent) {
        
        // 1 - Choose one of the touches to work with
        //guard let touch = touches.first else {
        //    return
        //}
        let touchLocation = theEvent.locationInNode(self); //touch.locationInNode(self)
        ....
10. Result

Mac OSXGame1 (Hello world)

Macbook pro (OS X EI Captian 10.11.5)
Xcode 7.3.1
1. 與iOS步驟相同,為選擇OSX Game template
2. Result

Mac iOS Swift Game 2

Ref:https://www.raywenderlich.com/119815/sprite-kit-swift-2-tutorial-for-beginners
Macbook pro (OS X EI Captian 10.11.5)
Xcode 7.3.1
1. 準備ninja.png monster.png
2. 開啟新Game專案
3. 取消Portrait設定
4. 刪除 GameScene.sks (本例不需)
5. 開啟Assets.xcassets
    載入 ninja.png, monster.png
6. 開啟GameScene.swift
     以程式加入小圖片(Sprite)  
7. 加入ninja.png (name : player)
         // 1
        let player = SKSpriteNode(imageNamed: "Player")
        override func didMoveToView(view: SKView) {
        // 2
        backgroundColor = SKColor.whiteColor()
        // 3
        player.position = CGPoint(x: size.width * 0.1, y: size.height * 0.5)
        // 4
        addChild(player)
8. 以程式加入 monster
    //----- 2016.8.3
        runAction(SKAction.repeatActionForever(
            SKAction.sequence([
                SKAction.runBlock(addMonster),
                SKAction.waitForDuration(1.0)
                ])
            ))
    //-----
9. 加入 touchesEnded method


















10. 碰撞方法尚未加入

2016年8月2日 星期二

Mac iOS Swift Game 1 (Hello World)

Ref:https://www.raywenderlich.com/119815/sprite-kit-swift-2-tutorial-for-beginners
Macbook pro (OS X EI Captian 10.11.5)
Xcode 7.3.1
1. 參考文獻比較 Sprite Kit 與 Unity
2. 開啟 New Project (Game template)
     新專案包含Spaceship圖檔(Assets.xcassets)
3. GameScene.swift
//
//  GameScene.swift
//  SWSpriteHello
//
//  Created by Jou CS on 2016/8/3.
//  Copyright (c) 2016年 Jou CS. All rights reserved.
//

import SpriteKit

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        /* Setup your scene here */
        //-- 2016.8.3 加入 Hello World! 標籤控制項
        let myLabel = SKLabelNode(fontNamed:"Chalkduster")
        myLabel.text = "Hello, World!"
        myLabel.fontSize = 45
        myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
        
        self.addChild(myLabel)
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
       /* Called when a touch begins */
        // -- 2016.8.3 Click 加入 自轉的Spaceship
        for touch in touches {
            let location = touch.locationInNode(self)
            
            let sprite = SKSpriteNode(imageNamed:"Spaceship")
            
            sprite.xScale = 0.5
            sprite.yScale = 0.5
            sprite.position = location
            
            let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)
            
            sprite.runAction(SKAction.repeatActionForever(action))
            
            self.addChild(sprite)
        }
    }
   
    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */
    }
}
4. 執行專案

2016年8月1日 星期一

Mac Swift Animation 1

Ref:https://www.codementor.io/swift/tutorial/view-animations-ios-tutorial
1. Open a new SingleView project
2. Open Main.storyboard
    Add ImageView Control
3. Open Assets.xcassets
     Right button click : Add new image set
     Drop Image file
4. Add ImageView (image)
5. Add animation function in ViewController.swift
//
//  ViewController.swift
//  SWANPNG1
//
//  Created by Jou CS on 2016/8/1.
//  Copyright © 2016年 Jou CS. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
// 1. drag ImageView control into here : declare (MVC)
    @IBOutlet weak var vIMG1: UIImageView!
    
// 2. Override function of viewWillAppear    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
    }
// 3. Override function of viewDidAppear
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        UIView.animateWithDuration(5, animations: {
            self.vIMG1.backgroundColor = UIColor.blueColor();
        })
        
    }


}






 











4. Repeat, Autoreverse
 //UIView.animateWithDuration(5, animations: {
 //    self.vIMG1.backgroundColor = UIColor.blueColor();
 // })

 UIView.animateWithDuration(5, delay: 0.5, options: [.Repeat, .Autoreverse], animations:{ self.vIMG1.backgroundColor = UIColor.blueColor();}, completion: nil)


2016年7月30日 星期六

brew update error /usr/local must be writable

brew update error /usr/local must be writable
Solved:
1. sudo chmod -R g+w /usr/local
2. brew udate