//next 이미지 터치시 현재 scene 다시 불러주고 , end 이미지터치시 종료하는 간단한 소스입니다
//asset 폴더에 next.png , end.png 이미지를 만드셔서 넣어주어야 합니다
//cocos2d 라이브러리를 첨부했습니다. 외부 라이브러리 import하는 방법은 생략하겠습니다.
CoCosActivity.java
-------------------------------------------------------------------------------------------------
//asset 폴더에 next.png , end.png 이미지를 만드셔서 넣어주어야 합니다
//cocos2d 라이브러리를 첨부했습니다. 외부 라이브러리 import하는 방법은 생략하겠습니다.
CoCosActivity.java
-------------------------------------------------------------------------------------------------
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
public class CoCosActivity extends Activity {
import org.cocos2d.opengl.CCGLSurfaceView;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
private CCGLSurfaceView mGLSurfaceView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mGLSurfaceView = new CCGLSurfaceView(this);
CCDirector director = CCDirector.sharedDirector();
director.attachInView(mGLSurfaceView);
setContentView(mGLSurfaceView);
CCDirector.sharedDirector().setDisplayFPS(false);
CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
CCScene scene = StartLayer.scene();
CCDirector.sharedDirector().runWithScene(scene);
}
}
-------------------------------------------------------------------------------------------------
StartLayer.java
------------------------------------------------------------------------------------------------
}
-------------------------------------------------------------------------------------------------
StartLayer.java
------------------------------------------------------------------------------------------------
import org.cocos2d.layers.CCLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.particlesystem.CCParticleSystem;
import org.cocos2d.types.CGPoint;
import android.view.MotionEvent;
public class
StartLayer extends CCLayer {
CCSprite nextSceneSprite;
CCSprite endSceneSprite;
public
StartLayer (){
this.setIsTouchEnabled(true);
setBackGround();
}
private void setBackGround() {
nextSceneSprite = CCSprite.sprite("next.png");
nextSceneSprite.setPosition(240f,500f);
endSceneSprite = CCSprite.sprite("end.png");
endSceneSprite.setPosition(240f,350f);
this.addChild(nextSceneSprite);
this.addChild(endSceneSprite);
}
public static CCScene scene() {
CCScene scene = CCScene.node();
CCLayer layer = new StartLayer();
scene.addChild(layer);
return scene;
}
@Override
public boolean ccTouchesBegan(MotionEvent event) {
CGPoint startLocation =
CGPoint startLocation =
CCDirector.sharedDirector().convertToGL(CGPoint.make(event.getX(), event.getY()));
if ( nextSceneSprite.getBoundingBox().contains(startLocation.x, startLocation.y)){
CCScene scene = StartLayer.scene();
CCDirector.sharedDirector().replaceScene(scene);
}
if ( endSceneSprite.getBoundingBox().contains(startLocation.x, startLocation.y)){
CCDirector.sharedDirector().getActivity().finish();
}
return super.ccTouchesBegan(event);
}
}
------------------------------------------------------------------------------------------------
'Cocos2d' 카테고리의 다른 글
Cocos2d Android : 6장 . plist를 이용한 애니매이션 (0) | 2012.01.10 |
---|---|
Cocos2d Android : 5장 . Cocos2d Scene 전환 효과 (1) | 2012.01.06 |
Cocos2d Android : 4장 . Cocos2d 액션 정리 (0) | 2012.01.06 |
Cocos2d Android : 3장 . CCParticleSystem 사용법 (0) | 2012.01.06 |
Cocos2d Android : 2장 . CCProgressTimer 사용법 (0) | 2012.01.05 |