Box2D check for a POTENTIAL collision - libgdx

I want to check in box2D, if I placed a body right there, would it be in another body, and if not, I don't wanna place/move a body right there.
I am using LIBGDX

Try Box2D raycasting:
http://www.iforce2d.net/b2dtut/raycasting
http://www.iforce2d.net/b2dtut/world-querying
/I should place it as a comment but I cant :/

Related

I have got a problem with the placement of the reset button on the guess game at developers.mozilla.org inside a web page, because it is placed wrong

I have started to learn JavaScript and was going through the tutorial on https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/A_first_splash with the guess game and want to incorporate the guess game into a web page to see how I can ran the game in a div container. All works fine up to when the game is over or the game is won and the 'Start new game' button comes up and the document.body.appendchild(resetButton); is executed.
The button is placed at the end of my page after the Footer and not inside the div container. What am I doing wrong and what can I look at to change the code to let it come up at the bottom of the container under the 'Enter the guess' bar as in the example?
In the example everything is under the body tags, but I have created a under the page to run the game in.
I have also tried to run document.body.append(resetButton); and even changed the .body to document.div.appendchild(resetButton); code to see if I can place it at the correct spot. When I change the .body code it gives me an undefined error on append.
I think you can use insertAdjacentElement method, it allows you define the inserting position.
It accepts these values:
'beforebegin': Before the targetElement itself.
'afterbegin': Just inside the targetElement, before its first child.
'beforeend': Just inside the targetElement, after its last child.
'afterend': After the targetElement itself.
Example:
document.body.insertAdjacentElement('afterbegin', element);

Overwrite pixel in cocos2-d

I'm writing with cocos2d-x, and have a problem:
For example, there are two sprites: a human and his clothes. I use fade (cascade opacity) to make it disappear, but during this the user can see the parts of the human body which were supposed to be hidden by the clothes. How to avoid this? How can I use render for that? Is there a way to overwrite pixels when render in cocos or OpenGL? Can anyone give an example?
You can use CCClippingNode to do the job.
CCClippingNode::create(cocos2d::CCNode *mask) (2.x type)
CCClippingNode::setInverted(bool)
It is used to create a clipping region. And you can use it to cover the body. Add the body in the clippingNode by addChild and use cloth as mask.

Ragdoll effect in box 2d

I want to make a body with ragdoll effect. How this can be achieved in box2d. I want to body keep straight even it fall down it can stand up itself.
There are lots of basic ragdoll tutorials.
To make it stand you could do the following:
1.
Make the joints springy. Make the joints have a target angle and a motor torque to resist rotation and move them back into a standing position.
2.
Use a force to lift the character up.
if (headBody.position.y < normalHeadHeight) {
headBody.applyForce(b2vec2zero, b2vec2(0,100));
}
This will lift the character up off the ground if their head goes below its normal height.
Notes
If you want it to look more like the character is really alive and moving under their own free will it will take a lot more work.

AS3: weird getBounds() result

EDIT2: It seems that the big numbers are created because the movieclip doesnt hold any bipmapdata, but Im yet not sure about it, but my real mistake was that I just forgot "this" infront of one "getBounds" ... project size was to big and I couldnt find the bug =)
EDIT: tried to use seperate containers, for the movieclips, and did all this in the root class ... everything worked fine, when I used seperate containers and attached everything to the charakter class it got screwd up again
OLD:
Hey I am making a game right now and I want to get the bounds of the charakter body.
To understand how I did set the whole thing up I explain the hirarchy.
The class of my flash document is "game.as". "game.as" adds a Child of the class Charakter
my Charakterclass has a Movieclip for every body part, for example the "head"
every bodypart has a movieclip which contains the picture of the bodypart, in this case "head".
When I now try to use the getBounds(head.mc) inside the "head" class I get really weird results. ussualy something around x=64001, y=64001, width = 0, height = 0;
I found a way how to solve this problem by simply using the getBounds(head.mc) function not inside the head, but inside the Charakter class .... but this is not what I actually want to do, I would like to use the getBounds(head.mc) function inside the head class.
Any ideas why the results are so weird or what I have to do? Im very thankfull for every opinion, because this doesnt seem logical to me xD
getBounds() is inaccurate. Please read the following posts to understand the issue.
getBounds "wrong" results (Source)
When getting bounds of an object relative to it's OWN coordinate system,
those values will NOT be scaled.
getBounds() returning incorrect height (Source)
From inside head_mc, try getBounds(this.parent); (you may want to test to see if the parent exists first) - this should give you the bounds of your head_mc as its container sees it, which I think is what you want, but called from inside head_mc, as you request.
bitmapdata is right, though - getBounds() can sometimes give some odd results. It looks to me like you might be asking the question before you add head_mc to the stage, and are therefore getting the undefined values for width/height/x/y.

HTML5 Canvas - circle animation with image

Im trying to get something like this --> http://jsfiddle.net/NhvAZ/10/ but with image inside circle.
I did exactly the same way like on example above, but it doesn't work with image. Here is my code: http://jsfiddle.net/uyEaq/
Someone could tell me what I'm doing wrong?
Well that was really confusing, but looking at some of the previous iterations of the fiddles you've given I think I know what you want.
You want an ever increasing pie slice of an image to appear, right? Clipping can do that for you. Here's an example using some of your code:
http://jsfiddle.net/QMZg2/