Quick-cocos2d-x Study Notes [3] -- display. newsprite create genie

Source: Internet
Author: User
Tags addchild

Game, no picture, no picture, can be called a game, so we should first look at how to create a genie using quick.


The quick API explains how to create the genie in detail, so it is very easy to create.

Display. newsprite (filename, X, Y, Params)

Filename: SPRITE file name

X: X coordinate

Y: Y coordinate

Params: Table parameters (not commonly used)


We can add the X and Y parameters for convenience during creation so that we do not need to set the location later. In addition, when we use cocos2dx for the sprite file name, we all know that there are direct reads from the file, and some are read from the cache frame, so to distinguish, quick uses "#" on the file name to distinguish them. If it comes with "#", the name is read from the cache frame.


In practice, modify the code in the myscene scenario created in the previous section.

The images used are,



Packaging tools create image sets


Normal Image File


Code,

Function myscene: ctor () -- Common File Creation wizard local SP1 = display. newsprite ("icon.png", display. width/4, display. cy) Self: addchild (SP1) -- creates an image cache display. addspriteframeswithfile ("Coco. plist "," coco.png ") -- create local SP2 = display by cache image name. newsprite ("#icon.png", display. width/2, display. cy) Self: addchild (SP2) -- create a ccspriteframelocal frame = display. newspriteframe ("icon.png") Local SP3 = display. newsprite (frame, display. width/4*3, display. cy) Self: addchild (SP3) End


Display Effect,


You can see these three input filename parameters, you can create the same genie effect.

In the code above, display. width is the screen width, equivalent to getwinsize (). width, and display. Cy is half of the screen height, equivalent to getwinsize (). Height/2


After the Wizard is created, some basic attribute settings such as zooming and rotating for the sprite are the same as those in the original usage. Here is no example.

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.