Cocos2d and cocos2d

Source: Internet
Author: User

Cocos2d and cocos2d
1.


2. How to Implement Theory



We use two images as an example. The outermost graph is the diagram in the red box. The two images have the same size.

For the preparation, we will do two things:

1. Zoom out the second image and add it to the first image by rotating to the right. It looks like the first image.

2. Set the anchor of the first graph to the purple point (very important, so that the scaling can have a better effect)

What we do when the user's fingers slide:

1. run three actions in the first image at the same time, zoom in, rotate left, and shift

The moving position is more exquisite. The result is to move the purple point to the center of the screen. (This point is hard to calculate)


3. Difficulties


1. If we know the point in a Sprite, how can we find it corresponding to the anchor?

For example, if the width of an image is 500 and the height is 400, what is the anchor corresponding to the p (200,300) Point?

 float anchorPointX = 200 / width;   float anchorPointY = 300 / height;

That is, x and y at the current position are divided by the width and height of the image respectively.


2. A genie was originally in the center of the screen. Now there is a p (200,300) point. How can I move this genie so that the result is that the p (200,300) point is in the center of the screen?

Vec2 worldPosition = smallSprite->convertToNodeSpace(Vec2(WIN_WIDTH/2, WIN_HEIGHT /2));Vec2 pos = worldPosition - Vec2(smallSprite->getContentSize().width * 0.5, smallSprite->getContentSize().height * 0.5);

The two images can still be created successfully. What about 5 or 6 images?

I tried to add all the images in the same way as the two images. The scaling problem occurs because the multiples are too large and fuzzy. Therefore, only one group can be created.

0, 1

1, 2

2, 3

3, 4

4, 5

Two groups are displayed each time. The group 3, 4, and 5 are displayed at the beginning. The group 3 and 4 are hidden and displayed as 4 and 5. Move on to the left to hide the Group 4 and 5, and display the group 3 and 4. Once the user continues to slide to the left in the 3 state, it will become 2, 3, 3, 4.

The logic is like this. It still takes some time to implement it. That's it.

Http://www.waitingfy.com/archives/1754

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.