Move Sprite Body randomly using BOX2D - cocos2d-iphone

I am using a tile map+cocos2d+ box2d based game and i have a some issue that how to move randomly enemy body with randomly force in tile map??
Please any one know tell me..
Thanks

Related

How to set up a score board using SFML and Box2D in C++

I want to set up a scoreboard for these two players (Pikachu)
My questions are:
how to detect when the ball touches the ground?
how to setup an object that can change during the game?
like the two in this picture:
I'm very new to SFML and Box2D, so even if I try to read the source code to see what I can use to implement things above, I still have no idea.
Can anyone give me some clues?
To create a scoreboard similar to the one in the image provided you can put text on the screen that holds the current score of the players and then placing it in the position where you want the score to be placed on the screen. In SFML this would be done by creating a sf::Text object.
To answer your other questions.
1.how to detect when the ball touches the ground
A simple way of doing this would be to check the Y value of the coordinates of the ball and from that determining if the ball is touching the ground.
2.how to setup an object that it can change during the game.
I am unsure what you mean by this.

Detecting Collision using Bounding Box

I am new to cocos2d-x and i am developing a game using cocos2d-x in xcode. In my game I added player sprite and Obstacle sprite. Obstacle sprite is moving continuously from right to left.
Now i am trying to add collision between the two sprites. So that I am using bounding box.Following is my code. but it is not working. this is first time that i am using bounding box.
if(obs1->boundingBox().intersectsRect(man->boundingBox()))
{
obs1->stopAllActions();
}
I created both the sprite in init() function and declare the above code in init function. Please help me to solve this.
you should be using if xxx->containsPoint()

How to create a b2body using box2d that is continuously moving left and right and doesn't fall down when player jumps on to it?

I am working on a platformer game using cocos2d with box2d in which i have ground body that must continuously move to left and right, but doesn't fall when player jumps onto it. I am not able to do so, my body falls when player jump onto it. Provide me some link or code to do so.
I think the best solution is to move the sprite for the platform, not the platform itsef.
Instead of creating a small platform for the jumping, create a rectangle that extends across the entire pit.
Only move the sprite over the region that you want the player to jump on to (i.e. move it left and right so the player knows the "safe" area to jump).
Use the b2ContactListener to detect the collision between the rectangle and the player. If they are in contact and the player is over the moving sprite, then don't do anything different.
If they are in contact and the player is NOT over the moving sprite, disable the collisions response in the PreSolve event of the b2Contact listener and for the entire time the player is in contact with it. The player should fall through to the pit below.
You could also use a sensor body for the moving platform to give you a better "contact mechanism" than just the sprite. So if the player is in contact with the "platform sensor" and the "rectangle across the pit", don't do anything in the PreSolve event. Otherwise, if they are only in contact with the "rectangle across the pit", let them drop through it.
Does this work?

Scroll tile map with joystick

In my game i am using tile map and sneaky joystick and I want to perform following task in my game.I am using box2d in my game.
I am create sprite body using box2d and also create static body for tile map.
My main problem is when my sprite moves that time tile map can not scroll.
Please help me.
Thanks
I am not sure what code you are using for your joystick but, Here's what I used when I made use of joystick for my game. Its very simple to use and easy to understand.
Hope that help you.. ! :)

Cocos2d scroll layer on Sprite drag

I have designed a small tutorial named "Stacker", As the name suggests, The game involves stacking blocks on each other. I have a large number of blocks to be stacked and hence all cant be accomodated in the screen itself... I m new to cocos2d and box2d but have managed to create a body with its adjoining sprite wen a user clicks on the screen. I have used MouseJoint to give movement to the body till the user performs the drag action that is till the user takes his finger off the screen.
The problem is that i need to follow the sprite (actually need the camera to follow the sprite) when the user drags it above the screen space, i referred the following links with no success... i guess wat i need is to move the body to a virtual coordinates which m not getting coz even if the screen does shift using the camera methods, but the sprite doesnt move with respect to the screen...
cocos2d forum link
flash concept but box2d
Can some1 guide me in case i need to have some pre-requisites before following camera in the manner i specified.. Thanx!
Ok Guys!
Got it guys! Had to take a global variable which records the increments per frame, The increments were equal to the layer movement which i did by setting the position of the layer to a unit less in every frame! Then set the Mouse join to the target which is (ScreenCoordinates + increment) dis too has to be done in every frame!
Done!
Cool method but needed a bit of brainstorming!!