[Gameplay3d] Development Guide-assets and authoring and gameplay: Game class

Source: Internet
Author: User
Assets and authoring)

Game resources are very important for a high-quality game. This doesn't just mean that the game resources should be suitable for game design, and they must be loaded with high quality and fast speed under the hardware limitations of specific platforms.

Binary game resources (Binary game assets)

A very practical way to ensure that you are always efficient is to bind and load all game resources in binary format. Common resources include images, fonts, sound effects, and 3D scenes. Most game engines always contain some types of packaging tools that allow developers to code and process what they want to process. The gameplay framework also contains an executable tool-gameplay-encoder.

Use fonts and 3D scenes

For fonts and 3D scenarios, you may want to support industrial standard file formats, such as TrueType, Collada, and fbx ).

Although these formats are popular and widely supported in tool selection, they are not considered as effective execution formats. The gameplay Library requires you to use the gameplay-Encoder execution file to convert these formats into the gameplay bundle format (. GPB) file described in this document.

Pre-compiled gameplay-Encoder Tool

The gameplay-Encoder executable tool has pre-compiled win7 and Mac OS X versions, which can be found in the <gameplay-root>/bin folder. The usage is as follows:

> Gameplay-Encoder <Options> files

Compile gameplay-Encoder

Although the gameplay-Encoder tool has been pre-compiled, you may want to customize it for yourself. To compile the gameplay-Encoder project, open the gameplay-Encoder project in vs or xcode and compile it into an executable file.

Content Pipeline)

The font and scene material pipeline works like this:

1. Find any TrueType font or Collada/fbx scenario file;

2. Run the gameplay-Encoder executable file to generate a gameplay binary version (. GPB file) by using the path and optional parameters of the font or scenario file );

3. Bind your game and file containing the gameplay library as a binary game package;

4. Load any binary game package and use the gameplay: bundle class.

Use a Binary Package

Use the gameplay: bundle class in CPP game code to load the encoded binary file (like a package ). This class provides methods for loading fonts and scenarios. The scenario is like loading a layered node (with many objects attached to it. These entities include a collection of grids, groups, cameras and lights. Gameplay: The bundle class also provides methods to filter some of the scenarios, so that you can load the part you want to load.

Release model package

When you release the game corresponding to your title, all images should be optimized and converted to the compressed texture format supported by OpenGL (es. Audio should be encoded to save storage space.

Games

Gameplay: The game class is the base class of all games created using the gameplay framework. You need to use CPP to extend this class and rewrite the event handling methods "initialize", "finalize", "Update", and "render" in the game core and lifecycle ". This is where you will write your own code to load game packages and implement game logic and rendering. After rewriting, the game class receives events and runs between the platform layer of the game and the lower layer as an abstract thing. The lower platform layer runs the game loop and reports it to the operating system.

The following are four methods you must implement when you start to write your own game:

# Include "gameplay. H"

 

Using namespace gameplay;

 

Class mygame: Public game

{

Void initialize ();

Void finalize ();

Void Update (float elapsedtime );

Void render (float elapsedtime );

};

The game: Initialize () and game: Finalize () methods are called at the beginning and end of the game respectively. This is where you will add code to load the game resource package in the game and reclaim it at the end of the game. The game: Update () and game: render () methods are called every frame of each operating system implementation in game: Platform from the loop of the game. This allows you to differentiate between controlling and updating your game status and rendering your game vision. You can use various built-in classes to help game rendering.

Access a game instance

Gameplay: The game class can be accessed anywhere in your game code. It implements a singleton mode. Call the static method game: getinstance () to obtain your game instance from any code.

Graphics and audio devices

After your game starts, the underlying graphics and audio devices will be automatically instantiated. He is preferentially called in the game: Initialize () method, and is used for any class that uses OpenGL (ES) 2.0 or open Al 1.1. Your game's graphics device will be created as a default 32-bit color frame buffer, a 24-bit depth buffer and an 8-bit template buffer for your use. These are active graphics hardware buffers that are rendered from rendering code.

For more advanced usage, you can use the gameplay: framebuffer class to implement alternate frame buffers. After the game: render () method, the frame buffer is immediately exchanged and presented to the physical display for users to watch. In any way, you can call the game: clear () method to clear the buffer. You can also call game: renderonce () in the Code. For example, if you call a method back and forth in the game: Initialize () method, it will be called only once, then switch/present to the display. During rendering initialization, such as loading scenarios, it is very useful to present ad-hoc updates to the screen.

Game subsystem Controller

Gameplay: The game class also manages game subsystem controllers, such as audio, animation, and physical controllers, and provides direct access to them using the getter method. These classes are used to manage and play vivid audio and animation in the game, and are dynamically updated in the physical system. These controllers are hosted in the gameplay: Game class, reflecting the lifecycle events that are operated in the game.

Game time and status

Once the gameplay: Game class instantiation starts, the game starts running time. You can call game: getgametime () to get the running time of the game. You can also call game: getabsolutetime () to obtain the absolute time since the first time you call game: Run. This also includes the pause time. You can call the game: Pause () method, and the game will enter the game: Paused status. If a user enters game: Play () on the platform, the game will be restored. At any time, in the game, you can obtain the game status by calling game: getstate (). The game status can be uninitialized, running or paused.

Input and perception

By creating your game and expanding gameplay: game, you will be able to add all required input event operations. In addition, there are some methods in gameplay: game to obtain the sensor data received currently. This architecture frees you (as a developer) from the details of platform differences, operating on the keyboard, touch and mouse events, and getting the accelerator status. The following describes how to override an input event:

# Include "gameplay. H"

 

Using namespace gameplay;

 

Class mygame: Public game

{

...

 

Void keyevent (keyboard: keyevent EVT, int key );

Void touchevent (touch: touchevent EVT, int X, int y, unsigned int contactindex );

Bool mouseevent (mouse: mouseevent EVT, int X, int y );

Void getaccelerometervalues (float * Pitch, float * Roll );

};

Control Input events

You have the opportunity to operate the mouse on the desktop or mobile device. You can only handle mouse events using the gameplay: touchevent () method (this includes supporting Bluetooth mouse ). However, this is not necessary. The default Implementation of the game: mouseevent () method returns false, which means that the user can allow the mouse event to automatically act as a touch event.

You can decide to cancel multi-touch support for the game when you don't want this method. You can call game: setmultitouch (false) to ensure that the platform treats and operates the touch time as a single point of touch. You can also call game: displaykeyboard () to show and hide the virtual keyboard to support it. You will want to integrate it into a point or interface in the game. text input is required.

You can call game: getaccelerometervalues () to pass the rule to the parameter, which will be popular for the currently passed value as the accelerator.

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.