Raphael JS - Simultaneous animations - raphael

I'm having an issue with Raphael JS. I'm going to explain it with a drawing:
Basically, I want that when the red dot moves, the path keep being connected to it, it should move along with it.
What I was trying at first was using animate on the red dot, and animateWith on the paths. Did not work out.
Can someone point me in the right direction? I want to create my own animation with a timer etc, but I want to check if this is a good idea.
Also, at some point all of the dots are going to move and the paths between them will still be connected. I don't know how to figure that out.
Thanks

The trick in this case would be to a) know where all of your circles will be for a given window of time and b) animate the path attribute of your connector lines over the same timespan as the circles. So, if your center circle is going to animate to (nx,ny) and your satellite circle is going to animate to (cx,cy), you'll need to animate the corresponding connector like this:
cl.animate( { path: [ "M", nx, ny, "L", cx, cy } }, duration, easing_method );
But you'll have to be careful to keep the duration and the easing method the same, or you'll get slop.
Obviously there are any number of possible state management strategies you could use -- without code it's difficult to guess. But I've mocked up one possible solution here.

Related

(UE4) Moving ball jumps unintendedly in places where geometry "connects". How do i fix this?

I am trying to make a very simple runner game, where a ball moves forward infinitely and your goal is to not let it bump into obstacles. I made a simple level with UE4 geometry, the ground is made out of different geometry objects. These objects are placed really close together, so there are, presumably, no gaps.
The engine is simulating physics for the ball.
I move this ball by executing this code every Tick:
FVector MoveForce(0, 1000000, 0);
BallMesh->AddTorqueInRadians(MoveForce);
I tried AddForce and AddImpulse before, they gave me the same result.
Here are the blueprint's components and Physics+Collision Details
Blueprint Screenshot
The main problem is, in places where the geometry connects (also on non-flat geometry), the ball just jumps, like there is a trampoline. And I can't figure out why this is happening.
Here is an example of the ball moving forward (to the left relatively to us) and then just jumping up.
enter image description here
I tried using new physical materials, disabling PCMs, changing the level's geometry. Nothing changed regarding the problem.
try if increasing mass would help,
I think this is happening because in collision detection it is not always very smooth but discrete in nature
also see if there collision primitive doesn't miss-aligned to each other.
The force you gave to the ball is quite large. In reality for that force, the ball should jump high in places of contact...because there is an addition to the upward normal force.
Solution:
virtual void AddTorqueInRadians
(
FVector Torque,
FName BoneName,
bool bAccelChange
)
When calling the function AddTorqueInRadians, set the boolean value of bAccelChange to true and see. This will allow you to use less force, as here torque is taken as change in angular acceleration instead of physical torque (mass will have no effect). This should work. And Bone Name is none.
Something like this:
FVector MoveForce(0, 20, 0);
BallMesh->AddTorqueInRadians(MoveForce, None, true);
Also, Uncheck MassInKg in blueprints for mesh.

Changing the displayed direction of an image while it's moving in OpenGL

I'm doing a little something in openGL now and I'm trying to make it so that whichever direction an object is heading, that object displays that direction clearly.
e.g.
If an object that is a dog is heading SW, it should be pointing southwest.
Is there any simple way to do this? glRotatef seems like it would be a valid option at first but I feel like it would get sticky when trying to calculate the angle and all. Especially since this would need to be updated constantly.

How do you make a CCSprite appear as slanting like the star wars intro?

Skewing x and y coordinates doesn't give that kind of effect. Any ideas on how to achieve this kind of effect? I already use cccamera but there are no examples on how to properly implement this. This image btw is from cocos2dx tried the c++ code still didn't work
I feel I need to share this once and for all. So this is how camera works when you want a slanting ,45degree or pseudo3d view of your background :
First set your director to 3d perspective
[director_ setProjection:kCCDirectorProjection3D];
If you only want some of the sprites to appear this way then remember this
all nodes have camera (cocos2d v.3 doesn't seem to have it anymore I don't know why)
so you do this:
[mysprite.camera setEyeX:0 eyeY:-40 eyeZ:10];
[mysprite.camera setUpX:0 upY:0 upZ:1];
Play with the values that fits your need. Hope it will help others!

Keeping Velocity Constant and Player in Position - Sidescrolling

I'm working on a Little Mobile Game with Cocos2D-X and Box2D.
The Point where I got stuck is the movement of a box2d-body (the main actor) and the according Sprite. Now I want to :
move this Body with a constant velocity along the x-axis, no matter if it's rolling (it's a circleshape) upwards or downwards
keep the body nearly sticking to the ground on which it's rolling
keep the Body and the according Sprite in the Center of the Screen.
What I tried :
in the update()- method I used body->SetLinearVelocity(b2Vec2(x,y)) to higher/lower values, if the Body was passing a constant value for his velocity
I used to set very high y-Values in body->SetLinearVelocity(b2Vec2(x,y))
First tried to use CCFollow with my playerSprite, which was also Scrolling along the y-axis, as i only need to scroll along the x-axis, so I decided to move the whole layer which is containing the ambience (platforms etc.) to the left of my Screen and my Player Body & Player sprite to the right of the Screen, adjusting the speed values to Keep the Player in the Center of the Screen.
Well...
...didn't work as i wanted it to, because each time i set the velocity manually (I also tried to use body->applyLinearImpulse(...) when the Body is moving upwards just as playing around with the value of velocityIterations in world->Step(...)) there's a small delay, which pushes the player Body more or less further of the Center of the Screen.
... didn't also work as I expected it to, because I needed to adjust the x-Values, when the Body was moving upwards to Keep it not getting slowed down, this made my Body even less sticky to the ground....
... CCFollow did a good Job, except that I didn't want to scroll along the y-axis also and it Forces the overgiven sprite to start in the Center of the Screen. Moving the whole Layer even brought no good results, I have tried a Long time to adjust values of the movement Speed of the layer and the Body to Keep it negating each other, that the player stays nearly in the Center of the Screen....
So my question is :
Does anyone of you have any Kind of new Approach for me to solve this cohesive bunch of Problems ?
Cheers,
Seb
To make it easy to control the body, the main figure to which the force is applied should be round. This should be done because of the processing mechanism of collisions. More details in this article: Why does the character get stuck?.
For processing collisions with the present contour of the body you can use the additional fixtures and sensors with an id or using category and mask bits. For of constant velocity is often better to use SetLinearVelocity, because even when using impulse velocity gets lost at sharp uphill or when jumping. If you want to use the implulse to change the position of the body, then you need to use the code for the type of this:
b2Vec2 vel = m_pB2Body->GetLinearVelocity();
float desiredVel = mMoveSpeed.x; //set there your speed x value
float velChange = desiredVel - vel.x;
float impulse = m_pB2Body->GetMass() * velChange;
m_pB2Body->ApplyLinearImpulse( b2Vec2(impulse, mMoveSpeed.y), m_pB2Body->GetWorldCenter());
This will allow maintain a constant speed most of the time. Do not forget that these functions must be called every time in your game loop. You can combine these forces, depending on the situation. For example, if the at the beginning you need to make a small acceleration, it is possible to use ApplyForce to the body, and when a desired speed is to use ApplyLinearImpulse or SetLinearVelocity. How correctly to use it is described here: Moving at constant speed
If you use world with the normal gravity(b2Vec2(0, -9.81)), then it should not be a problem.
I answer for this question here: Cocos2D-x - Issues when with using CCFollow. I use this code, it may be useful to you:
CCPoint position = ccpClamp(playerPosition, mLeftBounds, mRightBounds);
CCPoint diff = ccpSub(mWorldScrollBound, mGameNode->convertToWorldSpace(position));
CCPoint newGameNodePosition = ccpAdd(mGameNode->getPosition(), mGameNode->getParent()->convertToNodeSpace(diff));
mGameNode->setPosition(newGameNodePosition);
P.S. If you are new to box2d, it is advisable to read all the articles iforce2d(tuts), they are among the best in the network, as well as his Box2D Editor - RUBE. At one time they really helped me.
I do not know if this is possible but I have an idea:
Keep the circle at a fixed position and move the background relatively. For example, during the course of the game, if the circle has a velocity of 5 towards left then keep circle fixed and move screen with velocity 5 towards right. If circle has 5 velocity towards left and screen has 3 velocity towards right, then keep circle fixed and move screen with 8 velocity towards left and so on. This should allow you to fix the circle at the center of the screen.
Another method would be to translate the entire screen along with the ball. Make everything on the screen an object that can have a velocity. And the x-component of the velocity of the ball (circle) should be the velocity of all other objects. This way, whenever the circle moves, all the other objects will try and keep up with it.

Box2D small pocket hole creation

I have a simple question about a game I am making using box2D and cocos2D. I started using the physics engine yesterday so I am rather inexperienced with its usage and capabilities. My game involves rolling a ball around the screen using the accelerometer. I want to add holes to the ground that if the ball rolls into, it will then require a greater acceleration via the accelerometer to escape the hole pocket. I've toyed with friction, linear damping, modifying the accelerometer's gravity vector, and tried adding attractive forces but I haven't had too much success and some of it doesn't really simulate well what I want happening. Basically I just want to create some sensors and give them the properties of a small pocket a ball can fall in to. Any tips and advice is much appreciated. Thanks
I suggest you to use Level Helper . Its an awesome tool to create physic based games.
You can find it here
You could take the y position of the ball every frame and if it is below a certain threshold, then it is in a hole. Based off on this, if the ball is in a hole, reduce the sensitivity. When the ball exits the hole, put the sensitivity back to normal.
As for creating the holes, use Vertex Helper to create bodies that will correspond to your sprites.
If you need more explanation, feel free to ask.
Elaborated:
Now, basically in the picture, I am depicting what I tried to describe earlier. All you really have to do is to change the tilt sensitivity if the player's Y position is below a certain point. I just used 50 as an example.
Some pseudocode:
- (void)update:(ccTime)dt
{
if (player.position.y >= 50) { //If the player's y position is above or equal to 50
if (sensitivity != normalSensitivity) { //We don't need to set it every frame, so lets check
sensitivity = normalSensitivity;
}
}
if (player.position.y < 50) { //If player's position is below our threshold of 50
if (sensitivity != limitedSensitivity) { //Check so we don't set the sensitivity every frame
sensitivity = limitedSensitivity;
}
}
}
Now, as far as Vertex Helper is concerned, it is an open source tool (I believe) that helps you define vertices for custom shapes that can then be copied and pasted directly into your box2d or chipmunk cocos2d project. It can be fond here.
I suggest googling around for tutorials on how this is used. It is very simple, but you may need a quick reference to get you started.
Finally, something to remember, is that box2d can only work with convex shapes, not concave.
A convex shape is a shape where in is impossible to draw a line from any vertex to another without passing through the shape itself. Basically something that has no indentations in it.
I hope this helped. I'm not sure I can elaborate anymore than I have, but if you have more specific questions, feel free to ask.