Cocos2dx 3.0 transition article (30) grey machine or 3D good (Sprite3D)

Source: Internet
Author: User

Currently, I rarely post a series of blog posts about the 3.0 transition, for many reasons. One reason is the game development progress. Although the above does not put any pressure on me, I have been busy myself. On the other hand, this is my personal private life. In September, this is indeed the autumn of many things. Sometimes I really cannot study new things with all my thoughts.
Some people will certainly say: How do you have time to write a blog titled "Fun. My answer is rational: Do you need to take care of it ?!
I am not very familiar with the development and research of public platforms. It is also easy to write, so I don't have to spend too much time (at most I can play tricks ). In addition, you can record your previous learning experience, so that you do not forget your learning experience for a while ~~.

--------
Back to the question,Cocos2d-x v3.1 RC0 released this morning, had to feel cocos2dx version of the release of the fast, if you can vomit, I just want to say :... haha... (someone tells me what a sneer means). After downloading the latest version, you must initialize the setup. py bowl cake in cmd (why do I have the illusion that I am dealing with setup. py every week ?), However, you do not need to reset the NDK, SDK, and ANT paths this time. It will help you find them. I don't know if this feature is 3.0rc0 or only available in this version. I can't remember it.

Next we will go to the most anticipated gray-machine link.The new Sprite3D class is used here.First, let's look at several APIs.

/// Creates a Sprite3D, create static Sprite3D * create (const std: string & modelPath); // creates a Sprite3D. it only supports one texture, and overrides the internal texture with 'textpath' static Sprite3D * create (const std: string & modelPath, const std: string & texturePath ); // set texture, set the texture void setTexture (const std: string & texFile); void setTexture (Texture2D * texture );

In this case, modelis a file of the object, and I am also the first to contact this product. The principle should be similar to the basic relationship between plist and png.

Create a 3D gray machine.Will I tell you whether the gray machine resources are obtained directly from the Cocos2dx test resources?

Auto huiJi = Sprite3D: create ("boss1.obj"); huiJi-> setTexture ("boss.png"); huiJi-> setPosition (Point (350,350 )); huiJi-> setScale (20.f); // because the image is small, the magnification here is greater.

The effect is as follows:



Of course, since it's 3D, do you need some special action effects? Here I think it is best to use rotation:
Auto rep = RepeatForever: create (RotateBy: create (3,360); huiJi-> runAction (rep); // keep turning
The effect is as follows:


Well, in order to create a civilized and healthy blog atmosphere, I will first talk about the gray machine introduction above.

Since Sprite3D has all come out, the RotateBy3D product cannot be hidden.!

Of course, In fact, there is no RotateBy3D class. Currently, RotateBy is used to achieve 3D Rotation., The API is as follows:
static RotateBy* create(float duration, const Vec3& deltaAngle3D);
Needless to say, the first parameter is the rotation time. What is Vec3 of the second parameter? I don't know either. Well, the usage is easy to understand. The parameters in Vec3 are as follows::
Vec3(float xx, float yy, float zz)
The xx, yy, and zz parameters can be understood as x, y, and z in three-dimensional coordinates. The horizontal line is the X axis, the vertical line is the Y axis, and the vertical line is the Z axis. Therefore, if the Vec3 parameter is like this Vec3 (360,0, 0), it indicates that the object is rotated in the x direction.The implementation is as follows:
auto actionBy1 = RotateBy::create(4, Vec3(360, 0, 0));huiJi->runAction(actionBy1);
I don't know the running effect. You can try it yourself.

If you do not want to let the gray machine move, you can set a rotation angle for it. You can use the following API:
virtual void setRotation3D(const Vec3& rotation);
The principle is the same as that of RotateBy3D:
huiJi->setRotation3D(Vec3(90,0,0));
Rotate the gray machine 90 ° on the x axis. The effect is as follows:

For your misunderstanding, I would like to emphasize that RotateBy3D is not only effective for the objects created by Sprite3D, but also for other objects, such as Sprite.


Well, I can't continue with the gray machine topic. Let's talk about it.

Respect originality. for reprinting, please indicate the source:

Related Article

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.