Stop updating Rokon-use Rokon to develop a game from scratch

Source: Internet
Author: User

Lazy bones (http://blog.csdn.com/iamlazybone)

Stop updating Rokon-use Rokon to develop a game from scratch

I haven't started to study the Rokon framework seriously yet, so I stopped the update. I really want to take it and continue it. Unfortunately, the bones are too self-known.

Use Rokon to write a small game to commemorate it:

 

0. Create a project

First create an android project, then create the libs folder, put the rokon-2-0-3.jar file and libgdx. drag the so file in, and right-click the project properties to find the Java build path and add the rokon-2-0-3.jar as a reference library to the project.

1. Entry Activity Class

The following is the code for lazygamebyrokon. java.

Package lazy. game. rokon. main; <br/> Import COM. stickycoding. rokon. drawpriority; <br/> Import COM. stickycoding. rokon. rokonactivity; <br/> public class lazygamebyrokon extends rokonactivity {<br/> Public static final float game_width = 480f; <br/> Public static final float game_height = 320f; <br/> @ override <br/> Public void oncreate () {<br/> // debug mode, print, FPS <br/> // debugmode (); <br/> normalmode (); <br/> // set full screen <br/> forcefullscreen (); <br/> // force landscape screen, you can also set 'android: screenorientation = "Landscape" 'in manifest <br/> forcelandscape (); <br/> // set the screen size <br/> setgamesize (game_width, game_height); <br/> // set the rendering mode. The priority_vbo mode is faster than the normal mode. <br/> setdrawpriority (drawpriority. priority_vbo); <br/> // sets the resource path '. assets/textures/'<br/> setgraphicspath ("Textures/"); <br/> // create an engine <br/> createengine (); <br/>}< br/> @ override <br/> Public void onloadcomplete () {<br/> gotogamescene (); <br/>}< br/> Public void gotogamescene () {<br/>}< br/>}

First, our activity class inherits the rokonactivity and carries out some engine initialization settings in the oncreate () method.

After the engine is loaded, the onloadcomplete () method is automatically called. For example, we can go to the main game menu from here.

2. Create a scenario

Like most game engines, Rokon is managed by scenario scene. For example, the main menu is a scenario and the game is a scenario. Here we only need one scenario in the game.

Create a new scene class that inherits from Rokon as follows:

Package lazy. game. rokon. main; <br/> Import android. util. log; <br/> Import android. view. keyevent; <br/> Import android. view. motionevent; <br/> Import COM. stickycoding. rokon. scene; <br/> public class gamescene extends scene {<br/> Public lazygamebyrokon game; <br/> Public gamescene (lazygamebyrokon game) {<br/> super (3 ); // set the number of layers in the current scenario <br/> This. game = game; // main class handle <br/> useinvoke (); // The callback method is available, sprite must have a name to use the callback method <br/>}< br/> @ override <br/> Public void ongameloop () {<br/>}< br/> Public void ontouchdown (float X, float y, motionevent event, <br/> int pointercount, int pointerid) {<br/> log. I ("gamescene", "ontouchdown ()"); <br/>}< br/> Public void ontouchmove (float X, float y, motionevent event, <br/> int pointercount, int pointerid) {<br/> log. I ("gamescene", "ontouchmove ()"); <br/>}< br/> Public void ontouchup (float X, float y, motionevent event, <br/> int pointercount, int pointerid) {<br/> log. I ("gamescene", "ontouchup ()"); <br/>}< br/> Public Boolean onkeydown (INT keycode, keyevent event) {<br/> switch (keycode) {<br/> case keyevent. keycode_call: <br/> log. I ("gamescene", "onkeydown () keycode_call"); <br/> break; <br/> case keyevent. keycode_back: <br/> log. I ("gamescene", "onkeydown () keycode_back"); <br/> break; <br/> case keyevent. keycode_search: <br/> log. I ("gamescene", "onkeydown () keycode_search"); <br/> break; <br/> case keyevent. keycode_menu: <br/> log. I ("gamescene", "onkeydown () keycode_menu"); <br/> break; <br/> case keyevent. keycode_endcall: <br/> log. I ("gamescene", "onkeydown () keycode_endcall"); <br/> break; <br/> case keyevent. keycode_home: <br/> log. I ("gamescene", "onkeydown () keycode_home"); <br/> break; <br/>}< br/> return false; <br/>}< br/> @ override <br/> Public void onpause () {<br/>}< br/> @ override <br/> Public void onresume () {<br/> // release resources <br/>}< br/> @ override <br/> Public void onready () {<br/>}< br/> 

We only implement and cover some basic methods, such

Ongameloop (); // as the name suggests, it is a method called during game loop and can be updated in it.

Ontouchdown (); // and so on.

Onresume (); // This will be used later. You can release image resources here.

Useinvoke (); // callback method.

After the scenario class is added, return to the main activity to create it:

Private gamescene; <br/> Public void gotogamescene () {<br/> gametextures. load (); <br/> gamescene = new gamescene (this); <br/> setscene (gamescene); <br/>} 

3. Load image resources

Gametextures. Load (); an error is returned. Next we will add the resource class gametextures.

The gametextures class code is as follows:

Package lazy. game. rokon. main; <br/> Import COM. stickycoding. rokon. texture; <br/> Import COM. stickycoding. rokon. textureatlas; <br/> public class gametextures {<br/> // Resource Manager <br/> Public static textureatlas Atlas; <br/> // background resource <br/> Public static texture gameback; <br/> Public static void load () {<br/> try {<br/> Atlas = new textureatlas (128); <br/> // create a resource and add it to the Resource Manager <br/> atlas. insert (gameback = new texture ("background.png"); <br/> // The end of resource loading <br/> atlas. complete (); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}< br/>} 

Whenever you need a resource, you can create a new texture, instantiate it, and add it to resource manager altlas. Remember to call Atlas. Complete () to notify the engine that resource loading is complete.

4. Load the background and sprite genie class

Add a background in gamescene. Java: (the simulator may not be able to see the background, but the real machine may be able to, for unknown reasons)

Private fixedbackground background;

Add in Constructor

 

Background = new fixedbackground (gametextures. gameback );

Setbackground (background );

Add the genie class:

Private sprite boy;

 

// Instantiate the boy and add it to scene

Boy = new sprite (100,100, gametextures. Boy. getwidth (),

Gametextures. Boy. getheight ());

Boy. settexture (gametextures. Boy );

Add (1, boy );

 

 

----------------- To be continued ----------------

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.