2011년 1월 16일 일요일

[Android Course][English][Theme] - Android free game engine used - Rokon




1. 'Rokon library' Download.
: http://code.google.com/p/rokon/downloads/list
The above site "Rokon library" and "Rokon library Source Code" and so on.

2. 'Rokon library' Eclipse Porject Add
















 3. 'Rokon library' Framework and description
1) Structure














2) 'Rokon library' Framework for a replacement document
: http://coscup.org/2010/slides/15_3_1300_android_game_engine.pdf


4. Sample Code.
1) 'Image Load' method











- "Image_Load_Activity.java"
public class Image_Load_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures.load();
        setScene(scene = new GameScence());
    } // End of onLoadComplete
}

- "GameScence.java"
public class GameScence extends Scene {
    private FixedBackground background;
    public GameScence() {
        super();
        setBackground(background = new FixedBackground(Textures.background));
    } // End of GameScence
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {
    } // End of onReady
   
}

- "Textures.java"
public class Textures {
    public static TextureAtlas atlas;
    public static Texture background;
    public static void load() {
        atlas = new TextureAtlas();
        atlas.insert(background = new Texture("background.png"));
        atlas.complete();
    } // End of load
   
}

2) 'Image' on the screen, showing how












- "Add_Image_Activity.java"
public class Add_Image_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence1 scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures1.load();
        setScene(scene = new GameScence1());
    } // End of onLoadComplete
}

- "GameScence1.java"
public class GameScence1 extends Scene {
    private FixedBackground background;
    private Sprite bob, bob2, bob3;
   
    public GameScence1() {
        super(1,3);
        setBackground(background = new FixedBackground(Textures1.background));
       
        // Create the Bob sprites.
        bob = new Sprite(100, 220, Textures1.bob.getWidth(), Textures1.bob.getHeight());
        bob.setTexture(Textures1.bob);
        bob2 = new Sprite(100, 180, Textures1.bob.getWidth(), Textures1.bob.getHeight());
        bob2.setTexture(Textures1.bob);
        bob3 = new Sprite(100, 260, Textures1.bob.getWidth(), Textures1.bob.getHeight());
        bob3.setTexture(Textures1.bob);
        // Add the Bob sprites to the first layer.

        add(0, bob);
        add(0, bob2);
        add(0, bob3);
    } // End of GameScence
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {

     bob3.moveTo(450, 100, 5000);
     bob.moveTo(450, 100, 4000);
     bob2.moveTo(450, 100, 3000);
    } // End of onReady
   
}

- "Textures1.java"
public class Textures1 {
    public static TextureAtlas atlas1;
    public static Texture background, bob;
    public static void load() {
        atlas1 = new TextureAtlas();
        atlas1.insert(background = new Texture("background1.png"));
        atlas1.insert(bob = new Texture("android.png"));
        atlas1.complete();
    } // End of load
   
}

3) 'Image' and "Touch Move" to













- "Touch_Image_Activity.java"
public class Touch_Image_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence2 scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures2.load();
        setScene(scene = new GameScence2());
    } // End of onLoadComplete
}

- "GameScence2.java"
public class GameScence2 extends Scene {
    private FixedBackground background;
    private Sprite bob;
   
    public GameScence2() {

        super(1,1);
        setBackground(background = new FixedBackground(Textures2.background));
       
        // Create the Bob sprites.
        bob = new Sprite(100, 220, Textures2.bob.getWidth(), Textures2.bob.getHeight());
        bob.setTexture(Textures2.bob);
        // Add the Bob sprites to the first layer.

        add(0, bob);

    } // End of GameScence2
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {
    } // End of onReady
   
    public void onTouchDown(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // This is called when you press down on the screen.
    }

    public void onTouchMove(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // This is called when you move your finger over the screen.
     //(ie pretty much every frame if your holding your finger down)
        // Here we'll just make Bob follow your finger.
        bob.x = x - (Textures2.bob.getWidth() / 2);
        bob.y = y - (Textures2.bob.getHeight() / 2);
    }

    public void onTouchUp(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // And this is called when you stop pressing.
    }
   
}

- "Textures2.java"
public class Textures2 {
    public static TextureAtlas atlas1;
    public static Texture background, bob;
    public static void load() {
        atlas1 = new TextureAtlas();
        atlas1.insert(background = new Texture("background1.png"));
        atlas1.insert(bob = new Texture("android.png"));
        atlas1.complete();
    } // End of load
   
}


4) 'Image' and "Touch" changes depending on how













- "Modifiers_Use_Activity.java"
public class Modifiers_Use_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence3 scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures3.load();
        setScene(scene = new GameScence3());
    } // End of onLoadComplete
}

- "GameScence3.java"
public class GameScence3 extends Scene {
    private FixedBackground background;
    private Sprite bob;
    private ColorModifier modifier;
   
    public GameScence3() {

        super(1,3);
        setBackground(background = new FixedBackground(Textures3.background));
       
        // Create the Bob sprites.
        bob = new Sprite(100, 220, Textures3.bob.getWidth(), Textures3.bob.getHeight());
        bob.setTexture(Textures3.bob);
        // Add the Bob sprites to the first layer.

        add(0, bob);
        // And create the modifier.
        modifier = new ColorModifier();
    } // End of GameScence
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {
    } // End of onReady
   
    public void onTouchUp(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // Add your modifier to the sprite.
        bob.addModifier(modifier);
    }
   
}

- "Textures3.java"
public class Textures3 {
    public static TextureAtlas atlas1;
    public static Texture background, bob;
    public static void load() {
        atlas1 = new TextureAtlas();
        atlas1.insert(background = new Texture("background1.png"));
        atlas1.insert(bob = new Texture("android.png"));
        atlas1.complete();
    } // End of load
   
}

In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)

댓글 없음:

댓글 쓰기