Libgdx : how to attach actor to a rotated group - libgdx

I have a group actor with a circle image .png and then I spread small circles around surface of this group, I mean circle on angle 0 and circle on angle 60 and so on using the math equation:
x=cx+radius*cos(theta);
y=cx+radius*sin(theta);
The problem now I apply rotate action (rotateBy Action)on the main group and I want to add circle actor to this rotated group when the user tab note: this circle actor is not yet child of the main circle rotated group. I want to add this actor to the rotated group and show to the user as it attached to point of collision with surface of circle of the main group. See the image.
Sorry for my bad English.
image before:
http://imgur.com/TwJ7ldA
image after:
http://imgur.com/kRxuxle

I guess its pure maths...
find the collision point coordinates relative to origin of the group(x_rel, y_rel)
than add the actor to the group
addActor(newBall);
newBall.setPosition(x_rel, y_rel);

Related

Bullet, changing btCylinderShape pivot point

I'm using Bullet physics engine in a simulation.
I have a 3D node in my scene and i want to use a cylinder collision shape for it.(Yellow object)
Problem is that when i create a btCylinderShape , its Pivot point is in center of the cylinder,
but my 3D object has a different pivot point which is not in center (Its at bottom of cylinder for example)
So when i update my scene, collision shape doesn't match the 3D object as you can see in shot.
How can i change btCylinderShape pivot point to be in bottom instead of center?
you have to use compound shape.
try search for: bullet physics center of mass
https://code.google.com/p/jbullet-jme/wiki/CenterOfMass
http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=2209

actionscript: creating a soft mask using vector shape

I have an hourglass like vector shape and I'd like to use it to mask an image. I'd like to feather the edges - have a soft falloff in transparency that follows the contours of the hour glass. Any ideas how I can do this?
I tried using a gradient fill on a closed shape (using beginGradientFill() and curveTo() functions) but that falloff doesn't follow the contour of the vector shape, it can only go one direction.
Maybe there is a better solution but until somebody comes up with it... I assume you could do the following:
Draw whatever shape you want to use as mask into a transparent bitmap.
Scale a bit the bitmap down (or use a matrix while drawing its bitmapdata).
Apply a blur filter to it.
Put the bitmap's center to the masked clip's center so they are aligned.
Set the masked clip's cacheAsBitmap property to true.

I am trying to make 2 circles around a point and fill between these points and listen for a click between the circles

i'm trying to make something for a game i'm making. When someone clicks on the movieclip i want it to draw an inner circle and an outer circle. I'd like to fill between the circles with a opaque colour (purple in the image) so people can see basically a large thick circle around the movieclip but not touching the movieclip. I then need to check if the mouseclick happens between the two circles only.
The image below shows what i mean. The thing is the thickness of the purple bit has to be adjustable (not in game as such), if you click on 1 movieclip the thickness of the purple bit may be 10pixels, a different clip may be 50. Obviously checking for a click greater than inner circle x and less than outer circle only works on a straight line across from the clip, once you move up or down this doesn't work so well. Any help is much appreciated as i can't seem to work this out. I've tried drawing 2 circles and also tried using 2 movieclip circles but can't get it to work.
Seems i cant upload pictures on here. Easiest way is to think of a no entry sign without the / line going through the middle. The centre is the movieclip, the inside part of the red circle the inner circle and the outer is the outer circle but at no point does the red touch the movieclip
I would measure the distance from the center of the circles to the mouse click point. Then you just need to check is that distance greater than the inner circle radius and less than the outer circle radius.
Something along these lines:
var clickPoint:Point = new Point(mouseX, mouseY);
var centerPoint:Point = new Point(circleMC.x circleMC.y);
var dist:Number = Point.distance(clickPoint, centerPoint);
if(dist > innerRadius && dist < outerRadius){
trace("the click happened between circles
}

Rotate the group and scribbling on the group in a stage.. postting with code

Please this fiddle I have copied my complete project in it
here if you open the fiddle in the output you can see an image, scribble on the image selecting pen,add text etc(like this perform some functions).then rotate the group using rotate button and then try to scribble you will understand what is the problem exactly.
In me view Problem is I am having a stage and a layer is added to the stage and a group is added to the layer and different elements like lines text etc are added to the group. then group is rotated the i am trying to draw the line based on the mouse position of the stage.But it is not coming correctly because the group got rotated the x and y what we are taking to draw a line is from stage.I need to take the x and y from the group not from the stage is their any way.If hav't understand please ask me or post a reply.
This should get you fairly close: http://jsfiddle.net/k4qB8/24/
// This rotates that added active line along with your group.
// This makes the draw direction correct
activeline.setRotationDeg(0-rootGroup.getRotationDeg());
// Here you'll have to figure a way to calculate how much to move the
// line over so the draw is on the correct spot
// This is as close as I got it
if(Math.abs(rootGroup.getRotationDeg()%360)==0)
activeline.move(rootGroup.getX()-375, rootGroup.getY()-175);
if(Math.abs(rootGroup.getRotationDeg()%360)==90)
activeline.move(rootGroup.getX()-175, rootGroup.getY()+375);
if(Math.abs(rootGroup.getRotationDeg()%360)==180)
activeline.move(rootGroup.getX()+375, rootGroup.getY()+175);
if(Math.abs(rootGroup.getRotationDeg()%360)==270)
activeline.move(rootGroup.getX()+175, rootGroup.getY()-375);
Also, add some more logic for counter-clockwise rotation, as this doesn't work 100%.
I think the real solution would be to just draw on separate layers for each rotation, kind of like this:
if (rotation is 90) : draw on lineLayer1;
if (rotation is 180) : draw on lineLayer2;
if (rotation is 270) : draw on lineLayer3;
if (rotation is 360 || 0) : draw on lineLayer4;
This way you could just rotate the layers which are not drawn on to simulate the feel of rotation.

How can I created a curved health bar?

I'm making a game with a health bar and I am trying to make a health bar that is curved.
Currently I have a lineBar that has 20 segments that looks like this at the bottom left of the screen.
What I'd like to do is write a function that goes through and modifies the scaleY of each to get a curved bar.
I can easily scale them down in a straight line. So that it looks triangle ish.
I want exponential decay.
In normal math terms it might be something like y = Pa^x.
I developed a game with a curved health bar a while back, this is how I achieved it:
Step 1:
Create your curved bar. I suggest the Oval Primitive tool:
Draw your bar. I suggest creating a guide layer to demonstrate a whole-circle visual of your curved segment. Copy the bar onto another layer and make it a mask, this will be what reveals your healthbar. The mask and the segment should be MovieClips:
Step 2:
Set the registration point of your mask to the centre of your guide circle. Your mask will rotate around this point to reveal your actual bar. Rotate your mask so that it is to the left of your actual bar graphic:
Step 3:
Create a tween of your mask rotating clockwise across 100 frames (add more frames for finer progression). You can even apply a tween to your bar graphics where the colour changes from red to green as it fills, etc.
Step 4:
Use gotoAndStop() on this element to determine which frame you should stop on throughout the animation. The formula I use here is generally:
gotoAndStop( Math.round( currentHealth / maxHealth * x ) );
Where x is the amount of frames you created.
Hope this helps.