Elementary School in Cocos2d-x -- & gt; CCSprite basic processing (2)

Source: Internet
Author: User

In a game, our game background, UI background, and so on all need to use the Genie. Naturally, the role, npc, and door animation in our game will certainly use the genie...

It is estimated that I have read the previous environment setup and drawing. It should be clear that a new project has been created. If problems still occur during the creation of a new project, please refer to the previous article...

Upload the demo code as usual...

SpriteTestScene. h

[Cpp]
# Pragma once
# Include "cocos2d. h"
# Include "SpriteTestLayer. h"
Using namespace cocos2d;
 
Class SpriteTestScene: public CCScene
{
Public:
SpriteTestScene (void );
~ SpriteTestScene (void );
Static CCScene * scene ();
};

SpriteTestScene. cpp

[Cpp]
# Include "SpriteTestScene. h"
 
 
SpriteTestScene: SpriteTestScene (void)
{
}
 
 
SpriteTestScene ::~ SpriteTestScene (void)
{
}
 
CCScene * SpriteTestScene: scene ()
{
CCScene * scene = CCScene: create ();
SpriteTestLayer * layer = SpriteTestLayer: create ();
Scene-> addChild (layer );
Return scene;
}
SpriteTestLayer. h

[Cpp]
# Pragma once
# Include "cocos2d. h"
Using namespace cocos2d;
 
Class SpriteTestLayer: public CCLayer
{
Public:
SpriteTestLayer (void );
~ SpriteTestLayer (void );
// This method is inherited from the virtual function of the parent class. This method is called when the HelloWorld layer is created.
Virtual bool init ();
LAYER_CREATE_FUNC (SpriteTestLayer );
Private:
Typedef CCSprite * CCSPRITE;
CCSPRITE m_tamara, m_grossini, m_kathia;
};

SpriteTestLayer. cpp

[Cpp]
# Include "SpriteTestLayer. h"
 
 
SpriteTestLayer: SpriteTestLayer (void)
{
}
 
Bool SpriteTestLayer: init ()
{
CCSize s = CCDirector: sharedDirector ()-> getWinSize ();
/* Note: Do not copy the image to the resource of the project directly. The image cannot be obtained during running,
The resources under the project directory and the resources under the project path directory are not the same resource, and then I copy the new resources under the project path directory to the resource
And then refresh the project, and the newly added image cannot be refreshed. Why? If you know something, please leave a message... Thank you! */

CCSprite * sprite = CCSprite: create ("start.png ");
Sprite-> setAnchorPoint (ccp (); // you can specify the sprite's stroke (), that is, the upper left corner of the image.
Sprite-> setPosition (ccp (0, s. height); // you can specify the sprite position.
This-> addChild (sprite );
 
// Some basic sprite operations: scaling, rotation, and color mixing
M_tamara = CCSprite: create ("grossini.png ");
M_tamara-> setScaleX (2.5f );
M_tamara-> setScaleY (-1.0f );
M_tamara-> setPosition (ccp (100,70 ));
M_tamara-> setOpacity (255); // RGBA value RGB + transparency Value
This-> addChild (m_tamara );
 
M_grossini = CCSprite: create ("grossinis_sister1.png ");
M_grossini-> setRotation (120 );
M_grossini-> setPosition (ccp (s. width/2, s. height/2 ));
M_grossini-> setColor (ccc3 (255, 0, 0 ));
This-> addChild (m_grossini );
 
M_kathia = CCSprite: create ("grossinis_sister2.png ");
M_kathia-> setPosition (ccp (s. width-100, s. height/2 ));
M_kathia-> setColor (ccBLUE );
This-> addChild (m_kathia );
 
Return true;
}
SpriteTestLayer ::~ SpriteTestLayer (void)
{
}
Then, modify applicationDidFinishLaunching () in AppDelegate. cpp.

// CCScene * pScene = HelloWorld: scene ();
CCScene * pScene = SpriteTestScene: scene ();

PDirector-> runWithScene (pScene );

Well, the running effect is as follows:

 

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.