Visual Studio 2015 설치하기


1) Download

https://www.visualstudio.com/ko/downloads/

Visual Studio Community 2015 업데이트 3 – 무료 를 다운받는다.



2) 사용자 지정 설치 선택


3) 프로그래밍 언어 > Visual C++ 선택


4) 설치



결과



Cocos2d-x 기본 자료형 (Point , Size , Rect) 예제



c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
 
USING_NS_CC;
 
Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();
    
    auto layer = HelloWorld::create();
    scene->addChild(layer);
 
    return scene;
}
 
 
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    /**
        코코스2d 기본자료형
     */
    //Point
    Point point = Point(240,160);
    CCLOG("x : %f , y : %f", point.x , point.y);
    
    //Size
    Size size = Size(100100);
    CCLOG("width : %f , height : %f", size.width , size.height);
 
    //Rect
    Rect rect = Rect(240160100100);
    CCLOG("(x,y) : (%f,%f) , width : %f , height : %f" , rect.origin.x , rect.origin.y , rect.size.width , rect.size.height);
    
    return true;
}
cs



결과

1
2
3
4
x : 240.000000 , y : 160.000000
width : 100.000000 , height : 100.000000
(x,y) : (240.000000,160.000000) , width : 100.000000 , height : 100.000000
 
cs


Error:UNEXPECTED TOP-LEVEL ERROR:

Error:java.lang.OutOfMemoryError: GC overhead limit exceeded

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java'' finished with non-zero exit value 3



gradle)

1
2
3
4
5
6
android {
    ...
    dexOptions {
        javaMaxHeapSize "2g"
    }
}



결과



전체 이미지중 일부 이미지만 보여주기 및 레이어 이동하기



c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
 
USING_NS_CC;
 
Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();
    
    auto layer = HelloWorld::create();
    scene->addChild(layer);
 
    return scene;
}
 
 
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
 
 
    /**
        Hello World 출력하기
     */
    //Hello World 라벨객체
    auto label = Label::createWithTTF("Hello World""fonts/Marker Felt.ttf"24);
    //위치지정
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - label->getContentSize().height));
 
    //레이어에 추가
    this->addChild(label, 1);
 
    
    /**
        Image 추가하기
     */
    //create("추가할 이미지 파일명")
    //Rect(x,y,width,height) : 왼쪽 상단이 0,0 이된다 , 전체 이미지중 (x,y)에서 (x+width,y+height) 의 사각형
    auto spr = Sprite::create("testimage.png" , Rect(0,0,30,30));   //메모리 관리 Cocos에서 직접관리
    //Anchor Point 지정
    spr -> setAnchorPoint(Point(0.5,0.5));  //기본값 : 0.5 0.5
    //이미지 위치 지정 (Anchor Point의 위치)
    spr -> setPosition(Point(100,100));     //기본값 : 0 0
    //레이어에 추가
    this -> addChild(spr);
    //이미지의 가운데 위치가 100,100으로 지정
    
    
    //레이어의 위치 이동
    this->setPosition(Point(100,100));
    
    return true;
}
cs



결과

레이어가 이동하여 자식 객체인 이미지와 글자의 위치가 바뀌었다 (글자는 영역을 넘어가서 안보임)

Hello World 및 이미지 추가하기



c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
 
USING_NS_CC;
 
Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();
    
    auto layer = HelloWorld::create();
    scene->addChild(layer);
 
    return scene;
}
 
 
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
 
 
    /**
        Hello World 출력하기
     */
    //Hello World 라벨객체
    auto label = Label::createWithTTF("Hello World""fonts/Marker Felt.ttf"24);
    //위치지정
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - label->getContentSize().height));
 
    //레이어에 추가
    this->addChild(label, 1);
 
    
    /**
        Image 추가하기
     */
    //create("추가할 이미지 파일명")
    auto spr = Sprite::create("testimage.png");   //메모리 관리 Cocos에서 직접관리
    //Anchor Point 지정
    spr -> setAnchorPoint(Point(0.5,0.5));
    //이미지 위치 지정 (Anchor Point의 위치)
    spr -> setPosition(Point(100,100));
    //레이어에 추가
    this -> addChild(spr);
    //이미지의 가운데 위치가 100,100으로 지정
    
    
    return true;
}
cs



결과




Cocos 설치하기


1. 다운로드

http://www.cocos2d-x.org/download 에서 Cocos2d-x를 다운로드 한다.


2. 개발환경 설치

2-1) JAVA 설치 및 패스 설정

2-2) Android SDK 설치 및 패스 설정

2-3) Android NDK 설치 및 패스 설정

2-4) Ant 설치 및 패스 설정


1

2

3

4

5

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home         

export ANDROID_HOME=/Users/ghj/Library/Android/sdk

export NDK_ROOT=/Users/ghj/Library/Android/sdk/ndk-bundle

export ANT_HOME=/Users/ghj/Desktop/ant/apache_ant_1_9_7=

export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${NDK_ROOT}:${ANT_HOME}/bin

cs


3. Xcode 설치

(4. 윈도우 인 경우 파이썬을 설치한다)


5. 터미널을 열고 코코스 설치폴더로 가서 설치한다

1
2
Gwonui-MacBook-Pro:~ ghj$ cd Desktop/cocos/cocos2d-x-3_13_1/
Gwonui-MacBook-Pro:cocos2d-x-3_13_1 ghj$ ./setup.py
cs


6. bash 파일을 업데이트한다

1
Gwonui-MacBook-Pro:cocos2d-x-3_13_1 ghj$ source ~/.bash_profile
cs


7. 프로젝트를 생성한다

1
Gwonui-MacBook-Pro:cocos2d-x-3_13_1 ghj$ cocos new test -p com.ghj.test -l cpp -/Users/ghj/Desktop/workspace/cocos/
cs


8. 프로젝트를 실행한다


결과




두 날짜사이의 차이 계산

두날짜 사이의 시간 차이(ms)를 하루 동안의 ms(24시*60분*60초*1000밀리초) 로 나눈다.



java)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.blog;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class BlogEx002 {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        String strStartDate = "20161225";
        String strEndDate = "20161201";
        String strFormat = "yyyyMMdd";    //strStartDate 와 strEndDate 의 format
        
        //SimpleDateFormat 을 이용하여 startDate와 endDate의 Date 객체를 생성한다.
        SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
        try{
            Date startDate = sdf.parse(strStartDate);
            Date endDate = sdf.parse(strEndDate);
 
            //두날짜 사이의 시간 차이(ms)를 하루 동안의 ms(24시*60분*60초*1000밀리초) 로 나눈다.
            long diffDay = (startDate.getTime() - endDate.getTime()) / (24*60*60*1000);
            System.out.println(diffDay+"일");
        }catch(ParseException e){
            e.printStackTrace();
        }
    }
}
 
cs



결과




split() 함수를 사용하여 .(마침표) /(슬래시) \\(역슬래시) 로 구분하기

\\(역슬래시 2개)를 붙여서 구분한다



java)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.blog;
 
public class BlogEx001 {
 
    public static void main(String[] args) {
        String strTest1 = "ABCD.가나다라.1234";        //.(마침표)로 구분
        String strTest2 = "사과/바나나/딸기";    // /(슬래시)로 구분
        String strTest3 = "노트북\\휴대폰\\티비";    //\(역슬래시)로 구분
        
        /** \\ (역슬래시2개) 로 구분 */
        String[] arrTest1 = strTest1.split("\\.");
        String[] arrTest2 = strTest2.split("\\/");
        String[] arrTest3 = strTest3.split("\\\\");
        
        
        /** 출력 */
        for(int i=0; i<arrTest1.length; i++){
            System.out.println(arrTest1[i]);
        }
        System.out.println();
        
        for(int i=0; i<arrTest2.length; i++){
            System.out.println(arrTest2[i]);
        }
        System.out.println();
        
        for(int i=0; i<arrTest3.length; i++){
            System.out.println(arrTest3[i]);
        }
        System.out.println();
        
    }
}
 
cs



결과





'IT > - 프로그래밍' 카테고리의 다른 글

코코스 Cocos 설치하기  (0) 2017.01.04
자바 두 날짜사이의 차이 계산  (0) 2017.01.03
MAC 잠자기 기능  (0) 2016.12.03
안드로이드 PCI값 가져오기  (0) 2016.12.03
안드로이드 eNB값 가져오기  (0) 2016.12.03

잠자기 기능



잠자기 방법

1. 애플메뉴 -> 잠자기

2. 전원버튼을 길게 누르기



깨우기 방법

임의의 키를 누르거나 마우스를 클릭

PCI값 가져오기



java)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.ghj.pciex;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ToggleButton;
 
import java.util.List;
 
public class MainActivity extends AppCompatActivity {
 
    TextView txtPci;
 
    //manager
    TelephonyManager telephonyManager;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        txtPci = (TextView)findViewById(R.id.txtPci);
 
        //manager
        telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        if(telephonyManager.getNetworkType()==TelephonyManager.NETWORK_TYPE_LTE){
            //리스너 등록
            telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }
    }
 
    //리스너
    PhoneStateListener mPhoneStateListener = new PhoneStateListener(){
        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);
 
            //PCI
            List<CellInfo> cellinfos = telephonyManager.getAllCellInfo();
            for(CellInfo info : cellinfos){
                if(info instanceof CellInfoLte){
                    int cellci = ((CellInfoLte)info).getCellIdentity().getCi();
                    Log.d("pci", cellci+"");
                    if(cellci!=0 && cellci!=Integer.MAX_VALUE){
                        int pci = ((CellInfoLte)info).getCellIdentity().getPci(); //Physical Cell Id 0..503, Integer.MAX_VALUE if unknown
                        txtPci.setText("PCI : "+pci);
                        break;
                    }
                }
            }
        }
    };
 
 
    @Override
    protected void onDestroy() {
        telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        super.onDestroy();
    }
}
 
cs



xml)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <TextView
        android:id="@+id/txtPci"
        android:textSize="24dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
 
</LinearLayout>
 
cs



AndroidManifest.xml)

1
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
cs



결과


+ Recent posts