Quick-cocos2d-x Study Notes [4] -- add text, quickcocos2d

Source: Internet
Author: User

Quick-cocos2d-x Study Notes [4] -- add text, quickcocos2d

Text is encapsulated in the ui class in quick. It can create EditBox, menu, and text. In general, TTF and BMFont can be created.


The description of the api is very detailed, ui. newBMFontLabel (params), In the Parameter

  • Text: the text to be displayed.
  • Font: font file name
  • Align: horizontal alignment of text (optional)
  • X, y: coordinates (optional)
So we can use this code to create a text,

function MyScene:ctor()local labelBMFont = ui.newBMFontLabel({text = "Hello Cocos2dx",font = "futura-48.fnt",align = ui.TEXT_ALIGN_CENTER,x = display.cx,y = display.cy})self:addChild(labelBMFont)end

The effect is as follows,



The align parameter is equivalent to the anchor. By default, all the items created in quick are left-aligned. Therefore, align = ui. TEXT_ALIGN_CENTER is often used.

Note that the parameter name cannot be modified. Otherwise, an error is returned if quick does not recognize the parameter. Since we have mentioned that quick is a re-encapsulation of the native lua of cocos2d-x, let's look at how this newBMFontLabel is implemented, paste the code in the ui,

function ui.newBMFontLabel(params)    assert(type(params) == "table",           "[framework.ui] newBMFontLabel() invalid params")    local text      = tostring(params.text)    local font      = params.font    local textAlign = params.align or ui.TEXT_ALIGN_CENTER    local x, y      = params.x, params.y    assert(font ~= nil, "ui.newBMFontLabel() - not set font")    local label = CCLabelBMFont:create(text, font, kCCLabelAutomaticWidth, textAlign)    if not label then return end    if type(x) == "number" and type(y) == "number" then        label:setPosition(x, y)    end    if textAlign == ui.TEXT_ALIGN_LEFT then        label:align(display.LEFT_CENTER)    elseif textAlign == ui.TEXT_ALIGN_RIGHT then        label:align(display.RIGHT_CENTER)    else        label:align(display.CENTER)    end    return labelend


We can see that we still use the cocos2dx method to create BMFont-CCLabelBMFont: create (text, font, kCCLabelAutomaticWidth, textAlign). If you think that the quick parameter is uncomfortable, if you modify it, you can create it based on your favorite fields. Of course, this is not recommended.


The other is TTF, ui. newTTFLabel (params), which has many available parameters,

  • Text: the text to be displayed.
  • Font: The font name. If it is not a built-in TTF font, it is specified as the font file name.
  • Size: The text size. Because it is a TTF font, you can specify any size.
  • Color: The text color (Optional). It is specified with ccc3 (). The default value is white.
  • Align: horizontal alignment of text (optional)
  • Valign: vertical alignment of text (Optional). It is valid only when the dimensions parameter is specified.
  • Dimensions: the size of the text display object (optional), specified using CCSize ()
  • X, y: coordinates (optional)

Available values of the align and valign parameters:

  • Ui. TEXT_ALIGN_LEFT left alignment
  • Ui. TEXT_ALIGN_CENTER align horizontally
  • Ui. TEXT_ALIGN_RIGHT right
  • Ui. TEXT_VALIGN_TOP vertical top aligment
  • Ui. TEXT_VALIGN_CENTER vertical center aligment
  • Ui. TEXT_VALIGN_BOTTOM vertical bottom aligment
We can also write a simple example

function MyScene:ctor()local labelTTF = ui.newTTFLabel({text = "Hello Cocos2dx",size = 30,color = ccc3(255, 255, 0),align = ui.TEXT_ALIGN_CENTER,x = display.cx, y = display.cy})self:addChild(labelTTF)end

The effect is as follows,



I will not post the source code of how quick implements TTF. You can refer to it by yourself.


In addition, two types of TTF fonts are provided in the api,

Ui. newTTFLabelWithShadow (params)

Ui. newTTFLabelWithOutline (params)

The two are TTF fonts with shadow and stroke parameters, which are also provided in cocos2dx. Therefore, you can simply find out in quick and write an effect.

local labelTTF = ui.newTTFLabelWithOutline({text = "Hello Cocos2dx",size = 50,color = ccc3(255, 0, 0),align = ui.TEXT_ALIGN_CENTER,x = display.cx, y = display.cy,outlineColor = ccc3(255, 255, 0)})self:addChild(labelTTF)

The effect is as follows,



Label is basically like this. There is also a native Atlas, which is often used for digital tags in games ~



Plsql Study Notes 4

There are many brands of laptops, but from the recent computer warranty and after-sales service, the most important thing is the cost effectiveness, I recommend two brands of computers "Lenovo and HP"
Below I will introduce several computers, the landlord can consider,

Lenovo

Its Y430 series are among the first in terms of sales volume of computers and attention to the Ultimate Edition.
I want to introduce three models.
Y430a-pse

The configuration is as follows:
Processor Model Intel Core 2 dual-core P7450
Nominal clock speed 2.13 GHz
Front-End bus 1066 MHz
Level 2 Cache 3 MB
Kernel architecture Penryn
Platform technology Intel Platform
Motherboard chipset Intel PM45
Standard memory capacity 2 GB
Memory type DDRIII
Supports up to 4 GB memory
Hard drive/Optical Drive
Hard disk capacity 250 GB
Hard Disk description SATA
Optical Drive Type DVD recorder
Built-in design type Optical Drive
Graphics/sound effects
Low-end independent video card
NVIDIA GeForce 9300 m gs graphics chip
Stream processor count 16
Memory/Bit Width 256 MB/64 bit
Video memory type DDRII
Audio System built-in sound chip
Speaker Dolby certified sound effects, 2.1 audios (stereo speaker + subwoofer)
Display
Screen Size: 14.1 inch
Screen Ratio
Screen Resolution: 1280x800
Screen description LED WXGA
Size/weight
2350 GB laptop weight
Shape: 334x241x26-38mm
Case Material Composite Material
Network Communication
Wireless Network Card Intel 5100AGN
Nic description Mbps Nic
Support for Bluetooth
Modem 56 K
Red outer line infrared interface
Mouse/keyboard
Device touchpad
Keyboard description Lenovo notebook keyboard with high touch
Interface
USB interface: three USB Interfaces
Extended Interface ExpressCard
Card Reader-in-One Card Reader (SD/MMC, xD, MS, MS pro, SD Pro)
Video output HDMI high-definition port and standard VGA Interface
Other interfaces, such as 1394, RJ45, and full-array noise-resistant microphones, support for stereo audio headphone jack/audio output, and
Power supply description
Battery Type 6-core lithium battery
Power adapter 90 W power adapter
Others
Windows Vista Home Basic
Warranty Period: 3 years
Associated Software Package
Random attachment mouse
Optional accessory and notebook Gift Packs (purchased separately)
Other features: 1.3 million pixels support secure and easy-to-use Face Recognition
Quiet Mode with one click
Dolby audio 2.1 audio system
Electrostatic induction multimedia touch operation
Entertainment shuttle Sound Field Control
Hdmi hd output port
Other features: Lenovo one-click rescue/Lenovo flash link Ren Yitong
Environment requirements
Operating temperature 0-35 ℃
Operation humidity parameter error 10%-90% (no condensation)

The price is around 6100, which is definitely worth the money... In particular, it has good heat dissipation performance!

The second is y430-tfi.

Configuration
Intel Core 2 dual core T5800
Nominal 2 GHz clock speed
Front-End bus 800 MHz
Level 2 Cache 2 MB
Kernel architecture Merom
Platform technology: Intel®
Motherboard chipset Intel PM45
Standard memory capacity 2 GB
Memory type DDRIII
Supports up to 4 GB memory
Hard drive/Optical Drive
Hard disk capacity 250 GB
Hard Disk description SATA
Optical Drive Type DVD recorder
Built-in design type Optical Drive
Graphics/sound effects
Low-end independent video card
NVIDIA GeForce 9300 m gs graphics chip
Stream processor count 16
Memory/Bit Width 256 MB & #47 ...... remaining full text>
 
Study Notes from the first 4 seasons of jailbreak,

What do TV series learn? Are you talking about learning English? All script lines required? We recommend that you download it from the official website --#

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.