Drag and drop is not working properly with jigsaw puzzle - actionscript-3

I am working on a jigsaw puzzle for children age 4.
The puzzle contains 16 pieces called p1 to p16.
The problem is when i drag and drop for example piece p1, p2 and p15 and p16 in to place and then start dragging a piece with a lower number for instance p4 then piece p4 is visible only on top of p1 and p2 but not visible on top of p15 and p16. I do understand that is because of the stacking order, but i am wondering if it can be solved.

simplest solution is to just call the addChild() method, whenever you start to drag any of your instances.
something like here:
function yourMouseDownHandlerFunction(e:MouseEvent):void {
e.currentTarget.startDrag();
addChild(e.currentTarget);
}

Related

how can i control animation using big-bang so it loops

does anyone know how i can write a function for big-bang which basically loops an animation.for my task i have an animation of a car which currently goes from left to right but ends when it touches the right hand side,however,i want it to repeat itself so it continuesly goes left to right back to left and right non-stop.this is the excerise description
Exercise 45. Design a “virtual cat” world program that continuously moves the cat from left to right. Let’s call it cat-prog and let’s assume it consumes the starting position of the cat. Furthermore, make the cat move three pixels per clock tick. Whenever the cat disappears on the right, it reappears on the left. You may wish to read up on the modulo function.
i dont understand how the modulo function would be used here can someone explain
; WorldState - Image
; places the cat into the BACKGROUND scene,
; according to the given world state
;when the cat dissapears on the right it reappears on the left
(define (render cw)
(place-image CAT cw X-CAT background))

AS3 dress up game drag & drop not working

I'm making a dress up game and ran into the following issue.
I know how to make things drag and drop, however whenever the movieclip is situated in a layer below another, it will not let me drop it / does not register the mouse release.
In this case for example - The very top layer is the doll's hair. Under this layer are articles of clothing, and under that is the doll base. Like so : https://gyazo.com/a0ea8eae2ee5505874f4207a888249bf
I can pick up a top from the inventory but cannot place it on the doll because my cursor is over the hair from the very top layer. In a way, it seems like the hair layer is acting as a barrier between the cursor click and the article of clothing. Is there any way around this?
Here is a link to the game as it is now - i'm sure you will see the issue quickly if you attempt to move things around.GAME LINK
Here is the code for one of the clothing layers, if needed.
tshirt.addEventListener(MouseEvent.MOUSE_DOWN, drag17);
tshirt.addEventListener(MouseEvent.MOUSE_UP, drop17);
function drag17(event:MouseEvent):void
{
event.target.startDrag();
}
function drop17(event:MouseEvent):void
{
event.target.stopDrag();
}
Sorry for the rather crude explanation, and thank you in advance!
the problem
You are exactly right about the hair getting in the way.
method 1
One way to fix that would be (assuming you dropped the hair there):
function drop17(event:MouseEvent):void
{
event.target.stopDrag();
event.target.mouseEnabled = false;
}
In your hair example, the hair needs to have mouseEnabled set to false so that it won't be able to be your target by mistake on a mouse event. If the hair wasn't "dropped" there, set mouseEnabled to false for the hair wherever it makes sense to do so... maybe when it is first constructed or instantiated.
method 2
An alternative method is to force the item that you picked up to come to the front of the z order. Like this:
function drag17(event:MouseEvent):void
{
addChild(event.target); // this doesn't add another Sprite or movie clip, it just moves it to the top of the z order. Trust me.
event.target.startDrag();
}
With your dragging element now at the top, nothing will be "between" it and the mouse. This method probably looks cleaner since the thing you are dragging isn't getting lost behind other things. This will force you to deal with the eventual need to place the item in the correct z-order when you drop it, but that could easily be done by doing addChild to a clothesContainer or something like that. That would be another question though.

Rotation issue While Reflected (2D Platform Game)

My player's arm is programmed to follow my mouse and rotate accordingly and I've programmed bullets to be fired using this rotational value
(Math.atan2(this._dy, this._dx) * 180 / Math.PI
where _dy is the y location of the mouse (-) the y of my player's arm and the _dx is the x location of mouse (-) the y of my player's arm.
However, when I program the player to reflect when the mouse has crossed the x-coordinates, the bullet angle is also reflected. How would I fix this issue?
I've already tried subtracting 180 from the angle but it still doesn't fire towards the direction of the mouse.
First, make sure you have this parent-child-sibling relationship:
"A" should be the parent of "B" and "C". "B" and "C" should have no direct link. Their connection is that they have the same parent. So when you want to move the character, move the parent, and both will move. Now, for the good stuff:
Use key frames and sibling relationship
beginner level approach
Make the character and the arm both children of the same parent display object container (Movie Clip in this case). Now, instead of flipping anything by xScale, which I assume you did, you can just have both MC children (arm and character) go to frame 2 (or whatever is available) where the graphics are flipped.
xScale body, move arm to frame 2, change z order
moderate level approach (best result)*
Alternatively, you could do that same "sibling" setup as above, and then scale the character but not the arm (I think scaling the arm will mess it up again, but you could have the arm go to frame 2 and have it drawn reversed so the thumb and handle are pointing the right way. Bonus points for changing the z stacking order so the arm goes to the other side of the body. xScale for only the body allows you to only have one set of frames for animation of his legs and torso etc. but also avoid scaling the arm at all).
Global properties
advanced approach
A third option is to use global rotation and global points. I won't illustrate that here because I'm not that advanced and it would take me a while to figure out the exact syntax. If you already have mastered global properties, try this; if not, try one of the ones above.
* Example (best result)
if (facingRight == true && stage.mouseX < totalChar.x){
// totalChar is on the stage
// and contains two children:
// armAndGun and bodyHeadLegs
totalChar.armAndGun.gotoAndStop(2);
// in frame 2 of the arm MC, draw the
// arm and gun in the flipped orientation
totalChar.addChild(bodyHeadLegs);
// re-ads body to parent so it's
// z-order is above the arm;
totalChar.bodyHeadLegs.xScale = -1;// flips body and any animation of legs and head
facingRight = false;
// use a variable or property like this
// to keep him from constantly flipping
}
You'll need similar code to flip him back the other way.

ActionScript 3 Simple Projectile Pathing

Good evening (at the time of writing)
The research I've done on this topic has turned up numerous fruitful code blocks regarding various situations similar to mine, but not quite identical. If one exists which I have not uncovered, I would be grateful for a link!
I have a few pertinent criteria, all on a 2d plane, and the question is related to 2d projectile pathing:
1) Object A: position ax,ay
2) Object B: position bx, by
3) Object P: (projectile) origin position bx,by
Object P leaves object B's X/Y position at a static velocity, traveling toward object A's X/Y position.
Objects A and B continue to move along their paths, irrespective of object P's trajectory. Object P continues to move from ax,ay to bx,by and beyond. I think I just need the angle and velocity, and don't need to continue to track beyond that (just increment movement steps accordingly till off-stage, where the object is disposed).
I'm working in Actionscript 3, any help would be greatly appreciated. Thanks!
In most case in 2D x-y plane, it is usually easier to handle movement and momentum in planar(separate in x-axis and y-axis) fashion than polar(angle+distance) fashion. I couldn't get the exact behaviour of projectile you want, so I assume you want a simple, dumbfire-rocket style projectile (which keeps initial direction).
:: 1. Projectile initiation ("Firing" of projectile)
var duration:int //(duration of flight(until getting to (ax,ay) described in number of frames)
var spdX:Number //(x-axis part of speed, described in pixels per frame)
var spdY:Number //(y-axis part of speed, described in pixels per frame)
spdX=(bx-ax)/duration;
spdY=(by-ay)/duration;
:: 2. Projectile movement (listen to ENTER_FRAME Event, executed once per frame)
projectile.x+=spdX;
projectile.y+=spdY;
:: if you want to change velocity of projectile, simple multiplication will handle it.
public function adjustSpeed(ratio:Number):void
{
spdX*=ratio;
spdY*=ratio;
}

AS3: How to make movieclip appear on middle of a separate mc container?

I've been searching and having trouble doing this the right way.So my player has 2 arms which are joined in one mc. Now I'm trying to make the body(which is doesn't belong on the container mc) go between them, so it's like R arm first then body then L arm. The 2 arms rotate on mouse direction, i don't want the body too. Any ideas what way I should go?
EDIT:
please see my sample image
The checked thing is the result I'm looking for. But since the 2 arms is combined on one MC, I can't make the body appear on the middle between the 2 arms.
You should change your nesting model like this:
And then store your arms in an Array or a Vector, and change every arm's rotation separately.
It's the only way