Quick-cocos2d-x tutorial 9: instance plus background image

Source: Internet
Author: User

After combing the various directories of the quick-cocos2d-x framework, we started our instance tutorial, after helloworld, add a picture, lua editor, I used lua editor, not bad.

  • First, create a game01 instance by referring to the tutorial. Command: create_project-p com. cocos2dlua. game01-r landscape
  • Use quickplayer to open game01 and display helloworld. Normal.
  • Open config. lua in the game01 \ scripts directory and find:
  • -- Design resolution
    CONFIG_SCREEN_WIDTH = 960
    CONFIG_SCREEN_HEIGHT = 640
  • Change 960 to 1136, because we will use the iPhone 5S test, so it is 1136*640
  • Find a background image with a size of 1136*640. we name it bg01.jpg and place it in the game01 \ res. The res contains a framework_precompiled.zip file, which must not be deleted.
  • MainScene. lua file in game01 \ scripts \ app \ scenes,
  • Function MainScene: ctor ()
    Ui. newTTFLabel ({text = "Hello, World", size = 64, align = ui. TEXT_ALIGN_CENTER })
    : Pos (display. cx, display. cy)
    : AddTo (self)
    End
  • Delete the code in ctor () and end. You can also use -- comment before each line, or add -- [[, add] before the code end to annotate the entire segment.
  • Function MainScene: ctor ()
    Local bg = display. newSprite ("bg01.jpg ")
    Bg: setPosition (display. cx, display. cy)
    Self: addChild (bg)
    End
  • Then, the background image is displayed. Display. newSprite () is used to create a new genie with images. display. cx is the center of screen x, display. cy is the center of screen y, and addChild () is used to add an object.
  • We recommend that you view the display. lua in the framework, which is specific implementation and some function descriptions.

Related Article

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.