Section 1 of [v2.x Oge-Example] plot an object

Source: Internet
Author: User
Tags random seed

Preface:

OGE, ogengine, is an open-source game developed by orange games based on Java to support cross-platform. It has been developing for more than two years since its establishment in April. During this period, many projects developed based on ogengine have been successfully launched on the market. Starting from the official open source, many developers began to join the ranks of ogengine. At the same time, there were many problems on the official website, forums, Q groups, and many others, most of which were new users, you are often asked repeatedly. Some of them have previously used andengine, and the use of ogengine may be somewhat different, which is not very satisfactory during development. To this end, we will start to write an Oge-example today. When you are learning ogeengine, you can refer to these examples, which should be easier to use.

 

Body:

First, explain the OGE-example idea framework. These cases will be put into a project and displayed in list. There will be two levels of menus, starting from the simplest, some examples will be added along with the development of the engine in the future, and will be placed in this project for your convenience.

I. Considerations for importing Oge-Example:

1. First learning to run the platform environment to build Android: http://dev.ogengine.com/forum.php? MoD = viewthread & tid = 629 & extra = Page % 3d1, or IOS build: http://dev.ogengine.com/forum.php? MoD = viewthread & tid = 631 & extra = Page % 3d1;

2. The OGE-example project now supports running on two platforms (Android and iOS). In this case, some pictures and words are used.

To load these resources to the corresponding starters (Android and iOS starters );

Put it in the android Launcher:

Put it in the IOS starter:

 

Oge-example project structure:

 

Chapter 1 Section 1: drawing objects 1. Position: drawing_example --> drawingsprite2. Class Name: drawingsprite

 

(1) draw lines:

Line: Line (float px1, float py1, float px2, float py2, float plinewidth, vertexbufferobjectmanager pvertexbufferobjectmanager)

Px1, py1 line start position

Px2, py1 line endpoint

Plinewidth: line width

Setcolor (float Pred, float pgreen, float pblue) line color

PRED red

Pgreen green

Pblue blue

The minimum color value is 0, and the maximum value is 1. You can enter a specific color value as follows: setcolor (204/255, 4/255, 201/255)

Vertexbufferobjectmanager vertex cache Object Management

 

/**

* Draw 100 straight lines with random positions and colors

*/

Private void drawingline (){

Final long random_seed = 1234567890; // Random Seed

Final random = new random (random_seed );

For (INT I = 0; I <100; I ++ ){

Final float X1 = random. nextfloat () * 300; // random 0-300 starting point of Line X

Final float X2 = random. nextfloat () * 300; // random 0-300 at the end of line x

Final float Y1 = random. nextfloat () * 480; // random 0-480 starting point of line y

Final float y2 = random. nextfloat () * 480; // random 0-480 at the end of line y

Final float linewidth = random. nextfloat () * 5; // random 0-5 line width

 

Final line = new line (x1, Y1, X2, Y2, linewidth,

Getvertexbufferobjectmanager (); // draw a line

 

Line. setcolor (random. nextfloat (), random. nextfloat (),

Random. nextfloat (); // sets the color value range from 0 to 1.

 

This. attachchild (line); // The entity added to this scenario is drawn and updated only after the scenario is added.

}

} (2). Draw a rectangle

Rectangle: rectangle (float PX, float py, float pwidth, float pheight, vertexbufferobjectmanager pvertexbufferobjectmanager)

Position of PX and Py rectangles

Pwidth, pheight rectangular width and height

Vertexbufferobjectmanager vertex cache Object Management

 

/**

* Draw four rectangles.

*/

Private void drawingrectangle (){

// Red rectangle

Rectangle rectangle0 = new rectangle (300,120,100,100,

Getvertexbufferobjectmanager (); // draw a rectangle, position x300, position y120, width 100, Height 100

Rectangle0.setcolor (1, 0, 0); // set it to Red: 1 or 255/255

This. attachchild (rectangle0); // The entity added to this scenario will be drawn and updated only after being added to the scenario.

// Green rectangle

Rectangle rectangle1 = new rectangle (400,120,100,100,

Getvertexbufferobjectmanager (); // draw a rectangle. The position is x400, the position is y120, the width is 100, and the height is 100.

Rectangle1.setcolor (0, 1, 0); // set to Green: 1

This. attachchild (rectangle1); // The entity added to this scenario will be drawn and updated only after being added to the scenario.

// Blue rectangle

Rectangle rectangle2 = new rectangle (300,220,100,100,

Getvertexbufferobjectmanager (); // draw a rectangle. The position is x300, the position is y220, the width is 100, and the height is 100.

Rectangle2.setcolor (0, 0, 1); // set it to blue: 1

This. attachchild (rectangle2); // The entity added to this scenario will be drawn and updated only after being added to the scenario.

// Yellow rectangle

Rectangle rectangle3 = new rectangle (400,220,100,100,

Getvertexbufferobjectmanager (); // draw a rectangle. The position is x400, the position is y220, the width is 100, and the height is 100.

Rectangle3.setcolor (1, 1, 0); // set to Red: 1, Green: 1, and then yellow

This. attachchild (rectangle3); // The entity added to this scenario will be drawn and updated only after being added to the scenario.

}

(3) picture genie

Image genie animatedsprite (float PX, float py, string ptextureregionname, vertexbufferobjectmanager pvertexbufferobjectmanager)

Px, Py, Genie location

Ptextureregionname image name

/**

* Image painting genie

*/

Private void drawingpic (){

// Draw an genie

Animatedsprite pea = new animatedsprite (600, 30, regions. Pea,

Getvertexbufferobjectmanager (); // draw an image sprite position x 600, position y 30, and the image name references regions. Pea

This. attachchild (PEA); // The entity added to this scenario will be drawn and updated only after being added to the scenario.

 

}

 

(4). animation genie

Animation animation sprite (float PX, float py, string ptextureregionname, vertexbufferobjectmanager pvertexbufferobjectmanager)

Px, Py, Genie location

Ptextureregionname image name

Animation Genie's frame rate (long pframedurationeach)

 

/**

* Plane genie painting

*/

Private void drawingplane (){

// Draw an animated genie

Animatedsprite plane = new animatedsprite (610,140, regions. plane,

Getvertexbufferobjectmanager (); // draw the animation genie, position x 610, position y 140, and image Name Reference regions. Plane

This. attachchild (plane); // Add the entity to this scenario. The state will be drawn and updated only after the entity is added to the scenario.

// Specifies the frame speed. The duration of each frame, in milliseconds.

Plane. animate (180 );

Plane. setignoretouch (false); // you can specify false to prevent a touch.

}

(6). Delete the genie

Entity: attachchild (ientity pentity); attachchild adds an object

Detachchild (ientity pentity); detachchild deletes an object

 

/**

* Genie Deletion

*/

Private void removingsprite (){

Buttonsprite btnsprite = new buttonsprite (610,200, regions. back_btn,

Getvertexbufferobjectmanager (); // draw a button sprite position x 610, position y 200, and image Name Reference regions. back_btn

This. attachchild (btnsprite); // The entity added to this scenario will be drawn and updated only after being added to the scenario.

Btnsprite. setonclicklistener (New onclicklistener () {// register a key listener

@ Override

Public void onclick (buttonsprite pbuttonsprite, // response click

Float ptoucharealocalx, float ptoucharealocaly ){

System. Out. println ("detach btnsprite ");

Drawingsprite. This. detachchild (pbuttonsprite); // delete an object that is not in the drawing or update state after deletion

}

});

 

}

 

}

 

Oge_example project source code

 

 

 

 

Section 1 of [v2.x Oge-Example] plot an object

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.