Develop a game on the shoulders of giants (3)-Simplified orx text output and further learning

Source: Internet
Author: User

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Discuss newsgroups and documents

Preface

In the previous section, we built a hello World Program completed with orx, remembering the previous example of using N to complete the hello World Program. Maybe this is the most complicated one. The problem is that the output of the text in orx is the same as that of the object, so it is very troublesome. After all, simple text does not need to be configured with so many attributes of the object. (Refer to the previous section) In fact, after communicating with iarwain, I finally confirmed the simplified method, that is, writing my own functions as packaging. As a precondition, you must first learn how to use the config-related APIs in orx.

Configure related APIs

There is a detailed page description on the orx Wiki
This API. The main APIs are composed of orxconfig_setxxx and orxconfig_getxxx, which is relatively simple. I will not give too many examples.
Section processing is also relatively simple. Push and pop are used to use a section and restore it. seclect is used to select a section for a job, but there is a special place, these APIs will create a section when the section does not exist.
This is what I need.

Simplified text output

The following describes how to simplify text output. The previous section analyzes the complexity of output text in orx. The main reason is that the text simulates the creation of an object and has all other functions of the object, therefore, a simple text attribute is divided into three sections, which makes it complicated. My idea is to put all the attributes in one section, and still follow the original path, create an object based on the object creation method. In fact, because the implementation of orxobject_createfromconfig is complicated, I will not repeat the original steps, dynamically construct the three required parts of this API, and then use the original API to create it. Although the efficiency may be lower, the original function is used to the greatest extent.

In a simple example, in the original helloworld example, there are three helloworld configurations, as shown below:

[Helloworld]

Graphic =
Helloworldgraphic

[Helloworldgraphic]

TEXT =
Helloworldstring
Color =
(255.0, 0.0, 0.0)

[Helloworldstring]

String =
"Helloworld"

In fact, we only need two valid content.
Color =
(255.0, 0.0, 0.0)

String =
"Helloworld"

That is to say, I want

[Helloworld]

Color =
(255.0, 0.0, 0.0)
String =
"Helloworld"


This configuration can achieve the original effect. Think about it. If there are only three lines of configuration, the other four lines are useless links and sections. To completely restore the original effect and make its name the same, you only need to use the orx configuration API in this way.


Orxobject * createtext (orxstring _ ztextsection)
{
Orxconfig_pushsection (_ ztextsection );
Orxconfig_setstring ("graphic"
, _ Ztextsection );
Orxconfig_setstring ("text"
, _ Ztextsection );

Orxobject * pstreturn = orxobject_createfromconfig (_ ztextsection );

Orxconfig_popsection ();

Return
Pstreturn;
}

That is to say, by connecting the required graphic and text segments to itself, the idea of using the config method is entirely from iarwain ....... I can only say that too many things have been simplified, and the tiny ini configuration can be played with such superb features, it may be something that Ms cannot imagine ..............

Further study

In fact, the common text in orx shares too many things with the object. If there are too many things to talk about, we will see the situation I mentioned earlier, because I explained an API and ran through orx, here, we only propose several special configurations. (Although it is a special configuration, it is not special to the text, but also applicable to common objects. It only indicates that it is more useful)

Location

First, the position attribute indicates the position. When it comes to position, we have to talk about orx's world coordinate system, because it is special.
Orx, as a 2D engine, does not fully use the screen coordinate system, but moves the screen coordinate system to the center of the screen (strictly speaking, it is the center of creating the viewport, which is described below). That is to say, take the center point of the screen as the origin, the positive axis of X on the right, and the Y on the bottom.
In addition, because orx uses the Z buffer to solve the occlusion problem, there is also the Z axis coordinate, the Z axis coordinates point from outside the screen to the screen. That is, the screen is negative, and the screen is positive.
At least, by default, orx's world coordinates are like this. As a result, position is used. You can specify coordinates.

For example, if I didn't specify any position, the text is created at the origin by default. Now I specify-100,-100, which indicates that the text is displayed at the center of the screen, the text is displayed at a position of 100 pixels on the left. For example:

Central Point

In fact, there are a lot of typographical problems for text. For example, alignment to the left and alignment to the right is a central point problem for the object. The text here can be typeset using the central point. Of course, the problem of multi-line text is more complicated and requires manual layout. First, let's look at the attribute metadata.
Centers = center (+ truncate | round) | left | right | top | bottom | [vector]; NB: truncate and round will adjust should values if they are not integers; Z is ignored for 2D graphics;

When you configure helloworld as follows:

[Helloworld]

Color =
(255.0, 0.0, 0.0)
String =
"Helloworld"
Position =
(0.0, 0.0, 0.0)
Signature =
Center


The display effect is as follows:

Compare it with that when no center point is set:

By default, the center is on the left. You can choose to configure the options in the above description and allow combinations, such as Left top, left bottom, which is incredible ........

Even, you can zoom in and zoom in at the very beginning of its wealth .........

[Helloworld]

Color =
(255.0, 0.0, 0.0)
String =
"Helloworld"
Position =
(0.0, 0.0, 0.0)
Signature =
Left + bottom
Speed =
(10.0, 0.0, 0.0)
Scale =
2.0


Let's try it by yourself. You know, you can display helloworld in a variety of ways, but you don't need to change a line of code or compile the program again, you only need to change the configuration ....... There is no easy-to-use editor yet. It is hard to imagine what orx will do after a good editor ............

 

The author of the original article retains the copyright reprinted. Please indicate the original author and give a link

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

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.