What is anchorpoint)

Source: Internet
Author: User
Tags addchild

1. the anchor is usually the geometric center of the image,

The values of the two parameters X and Y of anchorpoint (x, y) are usually real numbers between 0 and 1, indicating the position of the anchorpoint relative to the length and width of the node.

For example, the lower left corner of the node is used as the anchor, and the value is (0, 0 );

Use the center of the node as the anchor. The value is (0.5, 0.5 );

Use the lower-right corner of the node as the anchor. The value is ).

The default anchorpoint value of the genie is (0.5, 0.5), and the default value of other nodes is (), such as cclayer.

Related Operations: setanchorpoint (0, 0 );

Impact: 1. Mount position, 2. scaling, 3. rotating

Myanchorpoint. h

# Pragma once # include "cocos2d. H "using_ns_cc; Class myanchorpoint: Public cclayer {public: static ccscene * scene (); static myanchorpoint * Create (); bool Init (); /* original drawing */void draw ();/* screen size */ccsize winsize ;};

Myanchorpoint. cpp

# Include "myanchorpoint. H "/* Create a scenario */ccscene * myanchorpoint: Scene () {ccscene * scene = ccscene: Create (); myanchorpoint * layer = myanchorpoint: Create (); scene-> addchild (layer); Return scene;}/* Create a layer */myanchorpoint * myanchorpoint: Create () {myanchorpoint * pret = new myanchorpoint (); if (pret & pret-> Init () {pret-> autorelease ();} else {Delete pret; pret = NULL;} return pret ;} /* initialize the layer */bool myanchorpoint: Init () {/* initialize the parent class first */cclayer: Init (); /* obtain the screen size */winsize = ccdirector: shareddirector ()-> getwinsize ();/* Create an genie, test the influence of the anchor on the Mount position * // ccsprite * SPR = ccsprite: Create ("anchor3.png");/* Create an genie, test the influence of the anchor on Scaling * // * ccsprite * SPR = ccsprite: Create ("anchor1.png"); SPR-> setscale (2.0f); * // * Create an genie, test the influence of the anchor on rotation */ccsprite * SPR = ccsprite: Create ("anchor2.png");/* rotate 30 degrees with the anchor2.png as the pivot */SPR-> setrotation (30366f ); /* set the sprite position */SPR-> setposition (CCP (winsize. width/2, winsize. height/2);/* set different anches and mount locations. The default anchorpoint is in the geometric center * // SPR-> setanchorpoint (CCP (0, 0 )); // SPR-> setanchorpoint (CCP (0, 1);/* SPR-> setanchorpoint (CCP (1, 0); SPR-> setanchorpoint (CCP (1, 1); * // * Add the sprite to the layer */This-> addchild (SPR); Return true;} void myanchorpoint: Draw () {/* set the color of the drawing. The default value is white */ccdrawcolor4b (255, 0, 0,255);/* draw line */ccdrawline (CCP (0, winsize. height/2), CCP (winsize. width, winsize. height/2); ccdrawcolor4b (255,255, 0,255); ccdrawline (CCP (winsize. width/2, 0), CCP (winsize. width/2, winsize. height ));}

 

What is anchorpoint)

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.