CreateJS/EaselJS: Bind two differnent kinds of operation logic to the same mouseEvent? - easeljs

I am doing a small game project named "puzzle game". Every piece of the puzzle should can be both moved and rotated. Whether I move the piece or roate the piece, I just do the same mouseEvent that move my mouse.
The differrence is that:
1) When the mousePoint is at the centre of piece , I will do pressMove;
2) When the mousePoint is at the edge of piece, if I move mouse, the piece will rotate according to the caculated angle.
But now, I don't exactly know how I do this.THANK YOU FOR ANY HELP.
For the roate, there is a example in this website.
(http://www.gamefromscratch.com/post/2012/11/18/GameDev-math-recipes...)
I want to do the same thing for rotating. And can move at the same time.

Related

LookAt while Hinge Jointed

I do not understand, why jointed object can't look at target.
Example: 2 boxes with hinge joint (anchor is at the touching place) and a target object. When I say A-box to lookAt target, I think it will just turn on X-axis. But both of the boxes start to shake. Why?
Take a moment to reflect on what a call to LookAt is trying to do.
It's rotating the transform while ignoring physics.
That's bound to create problems, since you're not rotating the whole system, you're moving one part of it. Your rotation with LookAt is "fighting" with the adjustments the physics system is trying to make.
To solve that conflict you can do one of the following:
Rotate the entire system (both cubes). This will involve putting them all under one transform, and having that transform rotate.
Use a physics-based approach. It won't be too hard, but won't be as simple as a function call. You'll probably need a simple PID controller such as the one outlined in this thread.

Unity 2D game Shooting Target Problems

so basically i have a target like the type for archery the 3 rings (bullseye, inner circle and outer circle)
now i basically used a cylinder to create these and then added to them rigidbody2D and a circleCollider 2D , now my problem is because the rings are essentially on top of each other i have them layered out on the z axis a little to make them all visible but when it comes to doing a raycast2d on the target it isnt picking correct ones up for example it goes from outer circle straight to bullseye and skips out inner circle yet all have colliders set up the same way
i cant figure out a way to overcome this and if not ill have to change to a different target where nothing overlaps in order to get it to work but i would really like the archery type targets
Thanks
You could just vary the distance from the camera for each ring so that the ones over the top are hit first.
Alternatively you could add tags to the three rings, use raycast all, and check the tags of all hit colliders to decide which one was hit first. For example, if all 3 register a hit, then you know the center was hit, and if the outer 2 register then you know it's the inner ring, and so on.
http://docs.unity3d.com/ScriptReference/Physics.RaycastAll.html

libgdx moving animated actor following the finger touch

In my game one crocodile is in water i have to guide that crocodile in water ,
it will follow my finger touch and will finish the path.
it should rotate when there is turn.
what approach should i use in libgdx...
Thanks
There is only one approach.
You capture the input (implement InputListener), unproject the pointer to your game world (Camera.unproject(...)), calculate the difference between the target vector and the position of the object that should follow it and move it in this direction, or use A* in case there are obstacles in between, calculate an appropriate path and then move along that path.

Programming controls for sprite

I am trying to make a snake kind of game on the iPhone. For that I plan to have a simple dot as the sprite which draws a line. The dot is controlled by two buttons on the left and the right of the screen enabling it to turn left or right. Now I really do not have any idea how to make the sprite move automatically forward and how to program the turning. It should not be exactly as in snake where it abruptly turns left or right but it should more be a smooth curve. I hope you're getting my point and I'd appreciate all kinds of thoughts! Thanks a lot!
Somewhat trying to make it like this:
http://www.bnet.im/images/screen_curve.png
There are a lot of ways of doing this, but one simple way would be to store the angle of the snake's trajectory (I've called it theta) and move it a fixed amount in every call to Update.
Assuming that the snake class inherits from CCNode:
-(void)Update:(ccTime)dt {
self.position = ccp(self.position.x + cos(theta)*dt,
self.position.y + sin(theta)*dt);
}
You could then update theta from your event handling logic by increasing it or decreasing it when the user taps to turn left or right.

iOS - Dragging objects along curved paths

I am tearing my hair out trying to figure out what seems to be a very easy problem. I know a lot of this stuff has been talked about tangentially, so apologies if this treads on well-covered ground, but I can't find anything specific to my solution (believe me, I've looked).
Basically I want to drag an object/sprite along a pre-defined, curved path (not just move it, but DRAG IT). Think of the iPhone's "Slide to unlock" thing, but instead of just dragging the slider left-to-right, make the path an arc or a wavy line.
My basic thinking was:
define a bezier path, set the object at the start point.
if the object is touched, check for hit detection on the bezier path in touchesMoved (or some similar function). if touches stay on the path, advance the sprite along the path until the path ends (in which case, task is finished) or the user's finger goes off the path (in which case, the object should go back to the beginning).
None of this is trivial (at least, that's how it seems). For example:
Doing hit detection on a Bezier path is a royal pain since you actually need to do it on the stroked portion, not the fill portion. And even then, I can't seem to find a way to do it on a path of any width -- only on the 1-point-wide path of the Bezier.
Moving an object partially along a path doesn't even seem possible: all of the animation methods move the sprite along the ENTIRE path. Also, doing this requires you to find the point on the path closest to the user's touch, which, if you've ever looked this up involves astoundingly complicated math.
I've thought of using rigid bodies to occupy all of the space EXCEPT the path, so the object can only move in the path. However, this requires the definition of curved rigid bodies some of which must be concave. Dead end.
Am I making this too hard? It doesn't seem that complicated. I don't need a whole solution, just a new way to think about this and kick in the right direction. Any help would be really appreciated.
How about this?
Consider the X Axis of your bezier
path.
Each time the user taps or interacts with the screen just look at the x portion of the touch
Map that X Coordinate with your path and move the object to the right position.
Yes, you are making this too hard.
Take the simplification suggested above (or along a circle, line, etc) if it works for, or if you really want to do it against a bézier curve, consider the following:
Look at the definition of the bézier curve
What you're looking for is to define a new object position P' from a current position P and a change in touch position D.
If you rephrase the original P(x,y) in terms of t (bézier curves are parametric), then the problem becomes finding how much t offset to add based on D.
Something involving the differential of the bezier fn at P might be a good way to do that. Ie, how much t would have been added had the curve just been a straight line coming from point P along the curve.
EDIT:
Transition between segments:
If each segment has t in [0,1), then you can detect t >= 1 and move on to the next segment, setting P to the end of the previous segment, and evaluating the movement again in relation to that point. There might have to be some heuristics involved if you have a lot of small points, etc.