Cocos2dx to realize the flop effect (Ccscaleto and Ccorbitcamera two ways)

Source: Internet
Author: User
Tags addchild

Because the project needs to realize the effect of the flop, so in the process of completion of this article written down, think still feel a little hard.

began to find solutions on the internet for a long time, basically is a solution, is to use Ccorbitcamera this action class to simulate the effect of the flop.

But I have always been unsatisfactory in the use of the effect.

This can be done with the Ccorbitcamera class, but if you move the card to the left, lower left, or other position that is not in the center of the screen, then the effect is not, the position of the flop is wrong, similar to the 3D.

Looking for a long time finally know what is the reason, cocos2dx inside there is such a word,

Ccdirector::shareddirector ()->setprojection (kccdirectorprojection3d);

This is the 3D,COCOS2DX supports both perspective projection and orthographic projection, so I changed the kccdirectorprojection3d to kccdirectorprojection2d, yes, I feel it.

Such a set flop action is not a 3D sense, is the normal feeling of this flop.

But the other pictures in the project saw jagged, which is not 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 Ccorbitcamera class to achieve the effect of the flop (I encapsulated it into a function).

void Helloworld::showobtaniuseorbitcamera (Ccsize visiblesize) {if (M_pcardfront!= NULL) {this->removechild (m_pCa
	Rdfront);
	} if (M_pcardback!= NULL) {this->removechild (m_pcardback);
	M_pcardfront = Ccsprite::create ("Cardfront.png") on both sides of the loading card;
	M_pcardback = Ccsprite::create ("Cardback.png");
	/*m_pcardfront->setposition (CCP (visiblesize.width/2-100,visiblesize.height/2+100)); M_pcardback->setposition (CCP (visiblesize.width/2-100,visiblesize.height/2+100)); * * m_pCardFront->
	SetPosition (CCP (VISIBLESIZE.WIDTH/2,VISIBLESIZE.HEIGHT/2));
	M_pcardback->setposition (CCP (VISIBLESIZE.WIDTH/2,VISIBLESIZE.HEIGHT/2));
	This->addchild (m_pcardfront,5);
	This->addchild (m_pcardback,5); Animation sequences (delay, display, delay, concealment) ccsequence *pbackseq = Ccsequence::create (Ccdelaytime::create (0.5f), Ccshow::create (),
	Ccdelaytime::create (0.5f), Cchide::create (), NULL); Duration, Radius initial value, radius increment, elevation initial value, elevation increment, offset angle from x-axis, offset angle from x axis Ccorbitcamera *pbackcamera = Ccorbitcamera::create (1.0f, 1, 0, 0,-90, 0, 0);
	ccspawn* pspawnback = ccspawn::create (pbackseq,pbackcamera,null);

	M_pcardback->runaction (Pspawnback); Animation sequence (delay, hide, delay, display) ccsequence *pfrontseq = Ccsequence::create (Ccdelaytime::create (0.5f), Cchide::create (),
	Ccdelaytime::create (0.5f), Ccshow::create (), NULL);
	Ccorbitcamera *plandcamera = Ccorbitcamera::create (1.2f, 1, 0, 0,-360, 0, 0);
	ccspawn* Pspawnfront = ccspawn::create (pfrontseq,plandcamera,null);
M_pcardfront->runaction (Pspawnfront); }
The above note is written more detailed, in fact, is not difficult, is the back of the display when the positive hidden, the front shows the back hidden, is such a thing.

There is a -90,-360 is the angle of rotation, you can try to change it to see what effect.

The following is a chart of the effects of the operation:

This is the reverse from the back to the front, but note that in "3D mode", position is set in the middle of the screen will have this effect, if the setting in other locations is not the effect, you can try.

If set to 2d mode will not have this situation, but do not know your own project picture will not appear jagged, jagged situation I did not find a solution.

2. Flip with Ccscaleto implementation

It was because of the jagged situation that I did not solve, so I was looking for alternatives, so I found the ccscaleto to achieve.

Here is the key code:

void Helloworld::showobtaniusescaleto (Ccsize visiblesize) {if (M_pcardfront!= NULL) {this->removechild (M_pCardFro
	NT);
	} if (M_pcardback!= NULL) {this->removechild (m_pcardback);
	M_pcardfront = Ccsprite::create ("Cardfront.png") on both sides of the loading card;
	M_pcardback = Ccsprite::create ("Cardback.png");
	Turn the cards upside down m_pcardfront->setflipx (true);
	M_pcardfront->setposition (CCP (visiblesize.width/2-100,visiblesize.height/2+100));
	M_pcardback->setposition (CCP (visiblesize.width/2-100,visiblesize.height/2+100));
	This->addchild (m_pcardfront,5);
	This->addchild (m_pcardback,5); Animation sequence (delay, hide, delay, hide) ccsequence *pbackseq = Ccsequence::create (Ccdelaytime::create (0.5f), Cchide::create (),
	Ccdelaytime::create (0.5f), Cchide::create (), NULL);
	ccscaleto* pscaleback = ccscaleto::create (1.2f,-1,1);
	ccspawn* pspawnback = ccspawn::create (pbackseq,pscaleback,null);

	M_pcardback->runaction (Pspawnback); Animation sequence (delay, display, delay, display) ccsequence *pfrontseq = Ccsequence::create (ccdelaytime::creatE (0.5f), Ccshow::create (), Ccdelaytime::create (0.5f), Ccshow::create (), NULL);
	ccscaleto* Pscalefront = ccscaleto::create (1.2f,-1,1);
	ccspawn* Pspawnfront = ccspawn::create (pfrontseq,pscalefront,null);
M_pcardfront->runaction (Pspawnfront); }

The main thing here is to turn the front of the card setflipx (true) This function to flip, and then around the Y axis to simulate a rotation, if still not very clear also please reader write code to try the effect.

Ccscaleto parameters are set mainly to revolve around Y, the specific conditions can also try their own effect, practice is the only test of truth standards, can be set to (1,1), (1,-1) and so on to try the effect.

Well, that's pretty much the case.

You can try to write a helloword effect, deepen the impression.

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.