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

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!

Related

SFML, background objects

[Hi everybody.
I am currently creating a Lion King game(C++, SFML).
I already have a background for a specific level(original background from the game, it's a sprite that i found).
The problem is this -
I want to be able to collide with all those big rocks: collusion from underneth means that it's a "celling" of some sort, collusion from above means that I land (and be able to walk) on the rock, etc.
How do you think I should approch that problem? Should I have a map with all coords of the rocks(by pixels) and then check for collusion? Ss there a better way to do it?
Thank you!]1
enter image description here

Blend modes and effects such as glow in Cocos2d?

I am new to this forum, started working as an animator: Don't know anything about cocos, so my question is, can we make composition in cocos 2d, like how we change blend modes and all in Photoshop ? Also is it possible to generate effects such as glow in cocos 2d ?
Please sort out my doubts guys. Thank you :)
Sure you can..
e.g:
sprite.blendMode = [CCBlendMode blendModeWithOptions: #{
CCBlendFuncSrcColor: #(GL_SRC_ALPHA),
CCBlendFuncDstColor: #(GL_ONE_MINUS_SRC_ALPHA),
}];
for effects check CCEffect class, you can add blur, brightness, contrast and many more

Tracing a bezier curve from an image for a cocos2d game

I was wondering if there is a tool that will allow me to construct/trace a closed bezier curve based on a background image?
Basically I have a background image that represents some 2d curve which could be of some weird shape like a race track and I want to place some items along this path.
I figured that if I can derive a quadratic bezier curve that will overlap the image I would be able to use the mathematical equations for this curve to compute individual points along its path..
Does anyone know if such tool exists? Is my approach reasonable or totally off and there is a much simpler solution?
Thank you in advance.
I suggest building it yourself. It shouldn't be too difficult to build a level creator where you add your own background image, place your bezier key points along where they need to be and export the points into a plist. It'll even give you room for extending it and customizing it for your game.
Also, if you're planning on tracing a path along a road for a racing game, consider constructing the background from smaller road/tree/grass sprites. This way you can give them specific properties (such as canDriveOn, canHit and so on) and based on customized behaviour defined for each one of them, your 'driveable' path would be derived implicitly.

Having problems understanding body positioning in Box2d. Any pointers on how things work?

I'm struggling to learn and understand box2d. Here is my problem:
I'm trying to make a simple car, the car body looks like this for now:
Now I'm trying to add a wheel, I create the wheel body and I assume I'll link the wheel to the car body using a b2RevolutionJoint.
Until I get to that part I just want to be able to position the wheel in its place, so in relation to the bodyCar Body. How do I do this correctly?
What I've seen online is something like this:
bodyDef2.position.Set(axle2->GetWorldCenter().x + 1.3*cos(-M_PI/3), axle2->GetWorldCenter().y + 0.3*sin(-M_PI/3));
However, I don't understand the cos and sin parts of that expression.
What I'm trying to do is this:
backWheelDef.position = b2Vec2(carBody->GetWorldCenter().x - 20.0/PTM_RATIO,carBody->GetWorldCenter().y);
Since my carBody vertices definition looks like this:
b2Vec2 vertices[] = {
b2Vec2(100.0/PTM_RATIO,15.0/PTM_RATIO),
b2Vec2(100.0/PTM_RATIO,30.0/PTM_RATIO),
b2Vec2(50.0/PTM_RATIO,65.0/PTM_RATIO),
b2Vec2(20.0/PTM_RATIO,65.0/PTM_RATIO),
b2Vec2(0.0/PTM_RATIO,45.0/PTM_RATIO),
b2Vec2(0.0/PTM_RATIO,15.0/PTM_RATIO)
};
The result of the above way of positioning the wheel looks somehow correct (see below screenshot) but if you look at the above numbers it doesn't make much sense.
Since the carBody width is 100.0/PTM_RATIO I assume the GetWorldCenter().x would return a value equal to 50.0/PTM_RATIO.
So the wheel position would be after calculation at 30.0/PTM_RATIO, right?
Well, if you look at the result below the wheel x positioning seems to be at 20.0/PTM_RATIO.
Can someone please explain how things work with positioning bodies in relation to other bodies works in Box2D? Once I'm clear with these kind of things I'll move on to linking them using joints
Thanks a bunch!
LATER EDIT BASED ON iforce2d ANSWER:
Thank you iforce2d for answering and thank you for all the good insight you provide in the box2d world. What you're saying is perfectly true but this wasn't my question.
Once I've figured out that GetWorldCenter returns the center of gravity and GetPosition returns the position origin of the object it was easy to place my wheel exactly where I needed it to be in relationship to the carBody. Even though I still got the behaviour of it appearing under the body I knew this would be fixed once I add joints into equation.
Now I have another question that somehow relates to this positioning problem. Take a look at the image below:
Is this the right way my joints should look once I set their anchor points as below? I'm a little confused by them going from origin instead of them going from anchorPointA to anchorPointB
Thanks again!
You are placing the wheel inside the car body to begin with, so in the first two or three time steps the two bodies will move to correct the overlap. It probably happens so fast that you don't see it, but the tell-tale signs are there, namely the wheel being positioned exactly at the edge of the car, and the car body being rotated a tiny bit.
If you pause the simulation (just don't call Step) you should see the bodies where you expect to see them.
Once you add the joint, the default behavior is for the two joined bodies not to collide with each other, so you wont see this problem.

Get location of vertices for Collision Detection OpenGL

I am trying to figure out how to get the vertices of my cube after it has been rotates with glRotate3f()
Im using a sphere bounding box to narrow dow the possible collisions but I need to know the exact vertices to get an accurate collision. Can anyone help me figure this out. Thanks.
Perhaps not the answer you're looking for, but you're approaching your problem from the wrong angle. OpenGL should be used to draw your scene and only that. Scene management and anything that goes along with it (transformations, deformations...to name just a few) should be handled by you (or an appropriate framework).