Cocos2dx can be used to create a sprite. cocos2dx can be used to create a sprite.Method 1
The most common and simplest method
CCSprite *bg=CCSprite::create("sprite/background.jpg",CCRectMake(0,0,480,320)); bg->setAnchorPoint(ccp(0,0)); bg->setPosition(CCPointZero); addChild(bg);Method 2
Use textures to create sprite
CCImage *image=new CCImage(); image->initWithImageFile("sprite/plant.png"); CCTexture2D *texture=new CCTexture2D();
inversion principle
High-level modules should not rely on the implementation of low-level modules, but on high-level abstraction.
For example, the wall switch should not rely on the lamp switch implementation, but on an abstract standard interface of the switch. In this way, when we expand the program, our switch can also control different lights or even different appliances. That is to say, electric lights and other electrical appliances inherit and implement our standard switch interface, and
What is anchor point? It is hard to understand because we usually look at an image to determine the position of the Image Based on the image center. In cocos2d, the position of an image is determined by two dimensions: position, the center of the image, and anchor point. As long as we figure out their relationships, we will naturally be able to solve them.
Their relationship is as follows:
Actualposition. x = position. x + width * (0.5-anchor_point.x); acturalposition. Y = position. Y + height *
tolerated.
I try to read cocos2dx about setting the Setprojection function to see if the sawtooth can be avoided, so that the flip becomes natural when there are many ways to eliminate aliasing.
In the end, I failed, but it was too much food.
I then find alternatives to achieve the flop action, found the Ccscaleto to achieve, this process is indeed relatively difficult.
Below I put the key code of two kinds of scheme to be posted out, convenient for everybody to see.
1. First of all, use the Cc
Original article, reproduced please indicate the source: http://blog.csdn.net/zhy_cheng/article/details/8271154
The animation provided by the Cocos2d-x is mainly instantaneous animation and delayed animation.
An instantaneous action is an action completed immediately without time. The common base class of the instantaneous action is ccactioninstant.
A delayed action takes some time to complete. Therefore, almost all delayed actions use execution time as the first parameter, and they share a comm
tools to create a font texture Gallery, that is, a font file. I have been using glyph designer (although it is charged, it also has a cracked version, you know! )
Let's briefly describe how to use glyph designer, select and process your favorite font, select export in file, and generate a PNG image file and a fnt file. When using it, you can import it to the xcode project.
Iv. Tag alignment
You can set different Alignment Methods for tags by setting different anchor values.
// Try to set dif
Ccsprite is the most commonly used class. It uses images to display the Sprite on the screen. There are three ways to create the sprite ):
// 1. Create a file directly through ccspriteGenie
Ccsprite * sprit = [ccsprite spritewithfile: @ "1.jpg"];
Cgsize size = [[ccdirector shareddire] winsize];
Sprit. Position = CCP (size. Width, size. Height );
Sprit. anchorpoint = CCP (1, 1 );
[Self addchild: sprit];
(), resources. c_str ());//Update hierarchies, The underlying layer will be re-orderedMap-> reorderchild (m_tamara, newzorder );//Obtain layer objects by nameCctmxlayer * layer = map-> layernamed ("Trees ");//The corresponding genie can be obtained based on the location of the genie in the layer.M_tamara = Layer-> tileat (CCP (0, 11 ));//You can set the top-level to achieve the blocking effect. The level is inverted. 0 indicates the top-level.M_tamar
*scene = CCScene::create(); // 'layer' is an autorelease object HelloWorld *layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene;}// on "init" you need to initialize your instancebool HelloWorld::init(){ ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();CCSprite* pSp
Day01 notes using namespace cocos2d; = using_ns_cc; generally, the following # ifndef _ mylayer_h __# DEFINE _ mylayer_h _ --------------- is generally added to the header file to the macro: public cclayer generally adds a class to inherit cclayer: Init (); cclabelttf * plabel = cclabelttf: Create ("Sunda", "Arial", 36 ); // define a lableaddchild (plabel, 1); // Add a lableccsize size = ccdirector: shareddirector ()-> getwinsize () to the image scene (); // obtain the current coordinate plabel-
|! Frame. containsPoint (m_pContainer-> convertToWorldSpace (m_pContainer-> convertTouchToNodeSpace (touch) {m_pTouches-> removeAllObjects (); return false;} if (! M_pTouches-> containsObject (touch) {m_pTouches-> addObject (touch);} // CCLOG ("CCScrollView: ccTouchBegan % d", m_pTouches-> count ()); /* set the single-touch attribute when the touch point is 1. In particular, the m_bDragging attribute indicates that the touch action is to drag */if (m_pTouches-> count () = 1) {// scrolling m_tTo
mapTiledNum = this-> _ allMap-> getMapSize (); CCSize tiledSize = this-> _ allMap-> getTileSi Ze (); CCPoint point1 = (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> getPosition (); int x = point1.x * 2/tiledSize. width; int y = point1.y * 2/tiledSize. height;/* the default Y coordinate of the Cocos2d-x is from bottom to top, so do a subtraction operation */y = mapTiledNum. height-y; int tiledGid = _ allMap-> layerNamed ("fangluoxia")-> tileGIDAt (
Now the genie is at the originpoint position. It must go to the endpoint position along the arc: 1 Ccbezierconfig; 2 By. controlpoint_1 = CCP (-controlx, 0 ); 3 By. controlpoint_2 = CCP (- Controlx, controly ); 4 By. endposition = CCP ( 0 , Controly ); 5 Ccbezierby * bezierby = ccbezierby: Create ( 1.0f , ); 6 7 Ccbezierconfig; 8 To. controlpoi
The development of the program must take into account the memory optimization, after all, the memory of the iphone itself is not very large. This section mainly describes the cocos2d development of memory optimization, detailed table now, both can be the same sprite (picture) only once, but also can be rendered only once for the genie.The following is the procedure of the program, first block the previous code.let me introduce you.Ccspritebatchnode optimize game rendering efficiency. in >ccspr
when walking a mazetypedef enum{up = 0,//left,//Leftdown,//underright,//RightMaxdirection} mazedirection;//DirectionFor simplicity, a static array is defined that describes the value of each x, y change in each direction. Static Ccpoint POINTDIRECTION[]={CCP (0,1), CCP ( -1,0), CCP (0,-1), CCP (1,0)};Second Verificat
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