Quick-cocos2d-x Beginner's Game tutorial (v)---------------------aids and jump scenes

Source: Internet
Author: User
Tags sublime editor

Quick-cocos2d-x Beginner's Game tutorial (Fri)

In the previous chapter we created the game's menu scene and explained the creation of some basic elements, and in the next chapter we will let you know some of the tools that will be used in the next game development, and then teach you to create another game scene and jump to that scene.

Tools Introduction

Before you start to really write your code, you should be talking about the following tools. These tools allow us to better and more easily implement some of the functions of the program, such as map editing tools, particle editing tools, and so on. Although these tools in my previous tutorial has been a lot of trouble to say, but in order to do a real beginner tutorial, this section is a simple introduction to the use of these tools, after all, we will continue to use these tools in the following chapters. Still that sentence, hope to be helpful to the beginner.

Texturepacker

Texturepacker is a picture-editing packaging tool that packs multiple image resources in our game into a larger image, so loading images not only saves space but also increases speed.
The download of Texturepacker can be downloaded to its official website.

The use of the Texturepacker tool is simple, and each of its settings gives a corresponding hint, and here we pack the steps as follows:

    1. The Resource picture (PS: If the picture resource itself is large, it is not recommended to use Texturepacker for packaging, because the packaged resources are likely to exceed the hardware device's limitations on the maximum texture size. ) to the right window of Texturepacker.
    2. Set the format and location of the exported resource, where two files are exported, one of which is a list file that stores the properties of the picture information, which can only be. plist format; the other file is a packaged picture file, which can be a. PNG,.JPG,.PVR.CCZ, etc. format, However, it is recommended to pack in PVR.CCZ format, because the benefits of using this image format are two points: 1, you can make your application smaller because the image is compressed. 2, your game can start faster.
    3. Click the Publish button to export the resource.

To use this packaged resource in Quick, we first need to load it into the sprite frame cache. The following functions can accomplish this purpose:

1 display.addSpriteFrames(数据文件名, 材质文件名)
    • Material file name: composed of more than one picture;
    • Data file (plist file): Records information such as the position of the picture in the material file.
      Here is the structure of the plist file opened with Xcode, which I think will allow you to feel more intuitively about the concept of packaging.

The sprite frame cache Spriteframecache is used to store sprite frame Spriteframe, and Spriteframe Sprite frame objects can be used to track the information of sprites in all sprite frame caches. Caching Sprite frames can help improve the efficiency of your program. Where Spriteframecache is a singleton pattern, it does not belong to a sprite, and is used by all sprites.

The Addspriteframes method obtains the texture name of each texture from the metadata portion of the plist list file of the descendant, loads it into the texture cache, and then resolves the file in its properties table.

When we are going to use sprite frames to create a sprite, we can use the Newsprite method just as we created the Normal wizard earlier. But in order to distinguish it from the Image Creation wizard directly in the file, Quick specifies that if the picture name starts with a "#" character, then the picture will be read from the Spriteframecache, if it does not begin with "#", it is read directly from the file.

For the actual application of packaged files, we'll give an example later. Here you can first load the resource into the sprite frame cache, and add the following code in the Myapp:run () method as follows:

`

1 display.addSpriteFrames("image/player.plist", "image/player.pvr.ccz")

`

Tiledmap Editor

The Tiledmap Editor is a map editing tool that we can use to stitch together a single tile (or tile) into a complete map, which we also call the tile Map Editor.

The Tiledmap editor makes a map for a TMX-formatted file that can be well supported by Cocos2d-x (Quick). Its official is: http://www.mapeditor.org/.

In this game, we will use the Tiledmap editor to edit some of the game's map, the specific method we use in the detailed explanation.

Particle Editor

In this game, we will use the particle effect to render the game scene, make the game more dazzling, so I would like to say this particle editor is a thing!

Because the game often needs to have some special particle effects (such as fireworks, explosions, snow, etc.), so the particle system such a program module is bred in various game engines, Cocos2d-x (Quick) is no exception, it provides us with a powerful particle system. It's just that the particle system in cocos2d-x has a lot of properties that need to be set up and adjusted, and it's still a bit complicated to use.

So in order to be lazy, programmers have developed a particle editor, it can easily edit the beautiful particle effect, let you go to manually set the particle properties of the process.

There are two commonly used particle editors, one is Particledesigner, the other is particleeditor (I wrote an article about how to use the Particleeditor editor, so you can refer to it).

The particle editor we used in the tutorial is Particledesigner, and here's a particle effect I'm using with the editor.

Note: If you want to bring up a satisfactory particle effect, then you need to understand the whole particle system composition principle, so want to try their own children's shoes can refer to the "Particle effect" article.

We've done a rough introduction to the tools we'll use in development, so let's look at how to create a new game scenario.

Create a new game scene

It is very easy to create a new Lua file in the Sublime editor, just select file-New file in the menu bar to create a new document, and then save the document in. Lua in SRC? App? The scenes directory is ready. Here we create a new Lua file named Gamescene.

This gamescene scene will be the logical scene of the game, and the code for all the logical parts of the flight game will be implemented in this scenario. So let's start building a game scenario like this.

First, according to the form of the Mainscene.lua file, we add the following piece of code to the Gamescene.lua file in the gourd drawing scoop, the code will create a blank game scene for us.

1234567891011121314 local Gamescene = class (      return display.newscene ( ) end)  function gamescene:ctor () end   function gamescene:onenter () end  function gamescene:onexit () end  return gamescene

After adding the above code, a simple and background blackened gamescene scene is created.

The code about Gamescene we do this for the time being, in the next chapter after the analysis of the composition of gamescene we begin to write. Now let's jump to the gamescene scene to see the jump effect.

Jump scene

We know that the first game scene to run the game is the mainscene scene, so now open the Mainscene.lua file, let's add the code so that it can jump to the gamescene scene and add the position that is triggered when the Start button is clicked. The onbuttonclicked function. The code looks like this:

1234 cc.ui.uipushbutton. new ({normal =      :onbuttonclicked (function ()           app:enterscene ( " Slideint "      end)

Enterscene method We talked about the Myapp.lua file when we were just using this method to simply enter the scene, and here we add a special switch effect. Without deep parsing, let's look at the definition of the Enterscene method as follows:

1 enterScene(sceneName, args, transitionType, time, more)

Its parameters are:

    • Scenename: Represents the scene name of the jump scene, which is the scene name of the scene we are going to enter.
    • Args: Represents the parameter that jumps to the scene class constructor, and args needs to be a table.
    • Transitiontype: Represents the Transition animation type for scene switching, with approximately 30 transition animation types defined in Lua.
    • Time: Represents the transition from the current scene to the scenename scene.
    • MORE: Represents the transition effect additional parameters.

So, to app:enterScene("GameScene", nil, "SLIDEINT", 1.0) switch from the current scene to the gamescene scene, the transition animation is the Slideint type (the new scene gamescene from the top, and the existing scene mainscene from the bottom), the entire switching process takes 1 seconds.

Transitiontype can be some of the following types:

  • Crossfade: Fades out of the current scene while fading into the next scene
  • Fade: Fades the current scene to the specified color, the default color is ccc3 (0, 0, 0), and the last parameter of the wrapscenewithtransition () can be used to specify the color
  • Fadebl: Fade out of scene from lower left corner
  • Fadedown: Fade out of scene from bottom
  • FADETR: Fade out scene from top right corner
  • Fadeup: Fade out of scene from top
  • Flipangular: The current scene is tilted and flipped to the next scene, which is flipped from the left by default and can be specified as:
    • Acl Transition_orientation_left_over, start from the left.
    • Acl Transition_orientation_right_over, start from the right.
    • Acl Transition_orientation_up_over start at the top
    • Acl Transition_orientation_down_over start at the bottom
  • FLIPX: Flip horizontally, default from left to right, additional parameters available as above
  • FLIPY: Vertical Flip, default from top to bottom, available additional parameters ibid.
  • Zoomflipangular: Zoom in and out at the same time, additional parameters available
  • ZOOMFLIPX: Zoom in and out horizontally, with additional parameters as above
  • ZOOMFLIPY: Zoom in and out vertically, with additional parameters available as above
  • Jumpzoom: Jump Zoom Toggle Scene
  • MOVEINB: New scene enters from bottom, existing scene exits from top at the same time
  • MOVEINL: The new scene enters from the left and the existing scene exits from the right side
  • MOVEINR: The new scene enters from the right and the existing scene exits from the left side
  • Moveint: New scene enters from top, existing scene exits from bottom at the same time
  • Pageturn: Page Turn effect, if the specified additional parameter is true, the page is left to the right
  • Rotozoom: Rotating Zoom Toggle Scene
  • Shrinkgrow: Narrowing cross-switching scenes
  • SLIDEINB: The new scene enters from the bottom, overwriting the existing scene directly
  • SLIDEINL: The new scene enters from the left, overwriting the existing scene directly
  • SLIDEINR: The new scene enters from the right, overwriting the existing scene directly
  • Slideint: The new scene enters from the top, overwriting the existing scene directly
  • Splitcols: Switch into a new scene in multiple columns
  • Splitrows: Switch into a new scene in multiple lines, like a shutter
  • Turnofftiles: The current scene is divided into blocks, and is gradually replaced with a new scene

When the player is refreshed, we will see the effect of the jump scene.

Quick-cocos2d-x Beginner's Game tutorial (v)---------------------aids and jump scenes

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.