I have a CCNode subclass and I have draw several lines on it. And I want to add this CCNode subclass to other Layers. However I don't how big this CCNode is. And the center of coordinate is the lower left corner of screen.
So my question is how can I change the CCNode size? And how can I change the center of coordinate when I am using my custom CCNode?
Now I am using Cocos2d-x-2.1.5
CCNode Size means I think it is setContentSize.
You can user setPosition method of CCNode to change position.(to change the center of coordinate) It depends on AnchorPoint also.
Just refer CCNode.h. You will get to know what you have to do.
Related
I'm trying to achieve a circular movement of KinematicBody around another body. I tryied this function:
public void updateCircular(float speed, Vector2 center){
Vector2 radius = center.cpy().sub(this.body.getPosition());
Vector2 force = radius.rotate90(1).nor().scl(speed);
this.body.setLinearVelocity(force.x, force.y);
}
But it's work fine only for DynamicBody connected with DistanceJoint. Changing body type to KinematicBody changes the behavior of the body. The body ceases to move in a circular orbit and passes to a spiral motion (Constantly increases the radius as if the centrifugal force is consumed by it). I need as much as possible a perfect circular motion. How can I achieve this?
Sorry for bad English.
The easiest way, in my opinion, is to just create a distance joint between some static body and your kinematics body. This way the body stays a certain radius from the other(creates a circle) and then you could just use set velocity to change its speed.
If the rotating body has to be a kinematic body, then to get uniform circular motion with fixed radius, we can add an extra velocity component perpendicular to the velocity vector. We can calculate the difference in distance of rotating body with the center. The velocity can be calculated by dividing this distance by time step per frame. This will move the body towards or outwards from center whenever rotating body is going outwards or coming inwards to the center. Add the below velocity to your calculation.
float dst=rotatingBody.getPosition().dst(pivotBody.getPosition());
//radius is the distance of center to the rotating body
float delta=dst-radius ;
//dt is time step per frame
float c2=delta/(dt);
Vector2 centripetalVector=new Vector2(pivotBody.getPosition()).sub(rotatingBody.getPosition()).nor().scl(c2);
I have written a tutorial on how to achieve a rotating shield around a moving dynamic body as center in libgdx. It can be found here along with the full code.
I have defined VIEWPORT_WIDTH and VIEWPORT_HEIGHT values. After that I would like to set all my objects to the center of this area.
By default I see all of my graphical items, sprites at the left corner. I use now this code:
camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
camera.position.set(camera.viewportWidth/2f, camera.viewportHeight/2f, 0);
How can I set "always center"?
An OrthographicCamera is always looking directly at its center. The center is equal to the position of an OrthographicCamera.
Thus, if you want to center your camera onto a certain object, you set the camera's position to the position of what you are trying to center on. For example:
camera.position.set(sprite.getX(), sprite.getY(), 0);
I am trying to get an effect like this:
http://www.welcomeanimations.com/welcome_animated_gifs_rotating_sign_orange_chrome_k_1.htm
I have tried all sorts of things:
Matrix translation/rotation - spins the text around the 'Z' axis, instead of 'Y'
Adding TextField to a sprite, and Sprite.rotationY++: reg. point is upper left corner
Adding to MovieClip - same as above (an article said MovieClip's reg. point was centered).
This should be trivial?!?! Help me stackoverflow, you're my only hope!
So you have to remember, Display objects scale and rotate around their local coordinate system. so when you put a textfield in a sprite, you need to center it in that sprite's coordinate system. And doing that for textfields is annoying because their width/height isn't always accurate but there is trick for that: get visual bounds, but normally you can take half of somethings width and height
I've created a prototype for you on wonderfl so you can see the solution working in action. Click on the blue square to see how the local coordinate system messes with the rotation
Finally as you use thing you might find things not rotating in 3D space quite right, this should be able to fix that.
I have this background that I'm using for a section, and it starts with a small arrow engraving at the top:
However I'm trying to get it when it repeats to clip out the top arrow part, just leaving the texture in the middle part. I was wondering if it was possible to do it with something like webkit? Thanks
You can't. You need to come up with another method of doing so. There are a number of ways to do this. Personally, I would use only the arrow, but use inner box-shadow for the shadows on everything else. This way you have smaller image being used, and it will always fit the size of the container.
Break up the background image from the pointer and make the two separate sprites. You can get tricky with the pointer and have it point in all 4 directions in the same image. This will allow you to pop up the bubble in all directions from the source.
You can't repeat both x and y on a usable sprite.
I have a maximum of three sprites in my projects.
One for non-repeating elements, another for repeat-x, another for repeat-y.
I find the clip property pretty much useless.
I have a movieclip with the mesurements of a rectangle. When the application is launched the movieclip is being scaled before placed on the stage as following.
menu.width = 400;
menu.scaleY = menu.scaleX;
this is a smaller size than the original.
the position of the movieclip at this moment is in the middle on the x and top of the stage on the y.
when i click iti would like to do a tween with tweenlite wich scales it to its original(bigger) width and height and position it in the center of the stage on x and y.
the problem is when i position it with tweenlite, it gets done according to its old scale and not according to its new(bigger) scale so the movieclip isnt placed in the exact center of the stage.
Anyone know how i can resolve this?
I tried to compensate by adding a bigger number on the position so it gets positioned in the right way.
But when i click it again i would like it to rescale to its beginning scale and position so it would be very messy to compensate again. Is there any easier way to do this kind of tween?
I doubt that i'm being clear to what i want but i hope i am after all.
The easy and way of tween position and scale is probably to add the menu to a container.
You would then on one hand tween the position of the container, and on the other apply the scale to the menu it self without having to recalculate the proportional position if the scale changes.
This way you can even control the registration point of the menu within the container. e.g. to always scale from the middle...
This can be done with a matrix as well if you want to avoid to stack objects, but honestly it can get really tricky whereas the container method is bullet-proof.