AS3 - Diagonal Movement
Hello, I was wondering if anyone could help me with some diagonal AS3 movement. Here is the code I'm using:
Code: stage.addEventListener(KeyboardEvent.KEY_DOWN, movePlayer); function movePlayer(event:KeyboardEvent):void{ if(event.keyCode == Keyboard.LEFT){ player.x -= 3; } if(event.keyCode == Keyboard.RIGHT){ player.x +=3; } if(event.keyCode == Keyboard.UP){ player.y -= 3; } if(event.keyCode == Keyboard.DOWN){ player.y += 3; } } It works great, except for the fact that I cannot get the player to move diagonally. Also, when I press down one of the arrow keys, the player moves in that direction three pixels (just like it should), then briefly pauses, then continues to move in that direction. How can I make it so that the player can move diagonally by holding two of the arrow keys at the same time and that the player steadily moves in the correct direction, without pauses after the first three pixels moved?
By the way, I know that I can make the player move diagonally by testing to see if right and up are held, left and up, right and down, and left and down, but then I will need to use four more if statements. Is there a way to do this without those excessive if's?
Ultrashock Forums > Flash > ActionScript
Posted on: 2009-01-01
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Diagonal Movement
Hi everyone,
what i'm trying to do is move an object (spaceship mc) from random off stage positions accrss the stage at different times (not trigered by key press). The movement of the spaceship is to be in diagonal paths.
For the off stage random positioning I don't have a clue! I'm thinking of maybe storing start and end positions in an array (so not using random).
For the angle of movement I obviously need to use sin and cos to determine the movement. Any help implimenting this would be really helpful, as i'm not that good with trig in Flash just yet.
hope you can help
Thanks
Diagonal Movement
Hello,
With actionscript how can I move a movie clip from one position, Diagonally to a another position and then stop?
Diagonal Movement
hey,
i have a "gun" following the mouse... and when you click, a bullet appears and goes towards the mouse...
here is my code for the following of the mouse...
Code:
angle2 = Math.round(angle/Math.PI*180);
angle = Math.atan2(opp, adj);
opp = ((_root.guy._ymouse-this._y));
adj = -1*(_root.guy._xmouse-this._x);
this._rotation = -1*angle2;
then... i want the bullet to move towards the mouse... so i added this code...
Code:
_root.bullet._y += (oop);
_root.bullet._x += (adj);
and that works fine... but the problem is that when the mouse is farther away, the bullet goes faster... and when its close it goes slower...
so i tried another code...
Code:
_root.bullets._x += 1;
_root.bullets._y -= (oop/adj);
but now... the bullet move faster and slower depending on the angle the gun is at...
so is there a way to get it to move at a steady speed no matter what?
[F8] Diagonal Movement
I realise this is probably as easy as but I haven't found any info on it yet. I have a movie clip that I can move in four directions (up, down etc. using Key.isDown(Key.UP)). I am now trying to get it to move in a diagonal when two buttons are pressed eg UP and RIGHT. Is this possible, if so how? If not what do I do?
Cheers,
Pete
Simple Diagonal AC Movement- - -help Please
I'm having great difficulties making a movieclip move onmouseover. I need to do this in AC as opposed to tweens to cut down on the file size. My scenario:
I have a movieclip at the bottom right corner of the movie (nearly all of the movieclip is outside of the stage) When the mouse is passed over the partial movieclip still on the stage, it will move onto the stage entirely, and when the mouse moves off, it moves back to the original position.
Sorry for the long winded explanation. I'm guessing this would deal with easing? This is why i'm not sure on what to do, i'm fairly new when it comes to dealing with the mouse movements and movieclips combined. ANY help at all would be excellent. Take care.
Victor.
Diagonal Keyboard Movement
I'm trying to get the characters in this Flash game to move diagonally - it works, but the following occurs:The character is walking twice as fast as it does when going left, right, up, down
The walking animation doesn't play
PHP Code:
onClipEvent (load) {walkSpeed = 3;stop();}onClipEvent (enterFrame) {if (Key.isDown(key.DOWN)) {_y += walkSpeed;this.gotoAndStop(1);}if (Key.isDown(Key.UP)) {_y -= walkSpeed;this.gotoAndStop(2);}if (Key.isDown(key.LEFT)) {_x -= walkSpeed;this.gotoAndStop(3);}if (Key.isDown(key.RIGHT)) {_x += walkSpeed;this.gotoAndStop(4);}if (Key.isDown(Key.LEFT) & Key.isDown(Key.UP)) {this.gotoAndStop(5);_x -= walkSpeed;}if (Key.isDown(Key.RIGHT) & Key.isDown(Key.UP)) {this.gotoAndStop(6);_x += walkSpeed;}if (Key.isDown(Key.DOWN) & Key.isDown(Key.LEFT)) {this.gotoAndStop(7);_x -= walkSpeed;}if (Key.isDown(Key.DOWN) & Key.isDown(Key.RIGHT)) {this.gotoAndStop(8);_x += walkSpeed;}if (!Key.isDown(key.UP) & !Key.isDown(key.DOWN) & !Key.isDown(key.LEFT) & !Key.isDown(key.RIGHT)) {this.gotoAndStop(9);}}
Can someone show me the way?
Diagonal Movement. PLZZ Help
Sup people, im trying to make an object move in a diagonal direction, when i click on a button.prefferably moves down and to the left, my code is all screwed up and i cant see straight anymore, so thanks for any help!
this is the code i have on my button
ActionScript Code:
on (release) {
_root.object.pos = 100;
_root.object = pos-_y;
}
onClipEvent (load) {
_y += y/speed;
_x += x/speed;
}
this is the action on the object...as is, its moving to a location were it will be moved from
ActionScript Code:
onClipEvent (load) {
speed = 5;
pos = -100;
}
onClipEvent (enterFrame) {
y = pos-_y;
_y += y/speed;
}
onClipEvent (load) {
speed = 5;
pos = 200;
}
onClipEvent (enterFrame) {
x = pos-_x;
_x += x/speed;
}
i know it looks terrible
Help With Math For Restricting Movement To Diagonal.
HI
i'm trying to restrict the movement of a mc to the diagonal. so even if i click and drag it towards the x direction, it moves the corresponding distance on the diagonal which is, the 45 deg angle line.
same with the y direction..
so when i click and move the mouse haphazardly, all the object does is to follow it on the diagonal.
But i just cant figure out the math for it. i mean, theoretically i think i need to use the x-component of the mouse when its angle is < 45 and the y-component when its angle is > 45. but how do i find those angles in flash??
help me please..
How Do I Go Diagonal?
Hello!
I'm using Flash 4 to write a top-down driving game, all the tutorials i've found have enabled me to control the vehicle on the keyboard, but only one button at a time, so forward, then turn, then forward.
Is there anyway of turning the vehicle while keeping it moving forward?
I know the Flash 5 has it all sewn up, so what about Flash 4?
Many thanks in advance
Diagonal HitTest
hiya,
im building an interface which is essentially a ball bouncing around in a trapezoidish shape, all the angles are either 90 or 45. the normal hitTest wont work because it calculates on the rectange of space surrounding the graphic. i have seen this done with some kind of vectors, but i have no experience with those ...yet
ThX
li'l green dude
Diagonal HitTest (again)
hiya,
im building an interface which is essentially a ball bouncing around inside a trapezoidish shape,
........________
........|......|
........|......|
......./....../
....../______/
- more or less, all 90 or 45 degree angles. do you know how to make it so the ball can bounce off a diagonal wall? the problem i am having is that the hitTest works off the rectangle created by the farthest edges of the object, since the diagonal walls run at 45 degrees, would there be a way to calculate a triangular half and use that for the hitTest?
someone sent me this link, but it's too abstract for me to conceptualize how to get what i need out of it
-=help mi plz, i have ants coming out of my keyboard=-
thanks
G
ThX
li'l green dude
Diagonal Lines...I....Just....Can't....Do IT
Ok, this has been annoying me for a while and i'm coming to the point in my design process where i'm going to HAVE to get this done, but still have not figured it out.
It's how to get diagonal lines in graphics...in Flash...that are clean and not "jaggy".
I just can't figure it out in Flash and in Photoshop i've done everything from skewing a rectangle to using the grid to draw a perfect path & then highlighting the path and copying the image to a PNG file.
Regardless, the diagonals are "jaggy" or not perfectly straight...or both.
Here's an example I found of someone who IS able to do it:
http://www.flashkit.com/gallery/Inte...60/index.shtml
Can anyone here break my thick mental block on what seems to me, something that should be a simple procedure?
Diagonal Guides How The ......?
well that's it
i just don't know how to do it!
Can anyone pleeeeeease tell me how can i make the guides diagonal, or in any other position than vertical or horizontal?
10x
Diagonal Text Box
HI,
I have a text field I'd like to follow my design, so it would be some sort of trapeze (one side would be a diagonal). I can stretch the box the way I'd like it, usign arrow+command but it doesn't stay like that when I release the mouse.
Is there any way to do this?
Thanx
[MX] Diagonal Shooting
Does anyone know how to make shots fire towards the mouse?
Also, does anyone know how to make something turn towards the mouse as well?
I'm hoping to use it for a shooter game (top-down), but im not good with trigonometry and all that fancy stuff
Diagonal Txt Box Problems
I have just tried to use a txt(dynamic or static) box, then make it diagonal on the page - this stopped the text being shown when exported, when i changed it back to horizontal it worked fine, anyone know why this happens and or how to stop it.
Thanks, Phil
Diagonal Movment
I'm having a problem getting my wee man to move diagonal.
at the momet on the map MC I have the following code:
Code:
onClipEvent (load) {
sSpeed = 15;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x -= sSpeed;
} else if (Key.isDown(Key.UP)) {
this._y += sSpeed;
} else if (Key.isDown(Key.DOWN)) {
this._y -= sSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x += sSpeed;
}
}
Is simple to get it to move left, right, up or down, but how do I got it to move at an angle, say a player presses both left and down, or up and right, how do I reflect this?
Diagonal Animation With AS
I am having a hard time to get this shape to animate diagonal. I have a MC that is 30 wide by 500 high. I rotated that on the stage by 45 degrees. I now want that to become wider in my animation, so the side that is 30 wide, because way wider. I tried this, making both width and height 500, but it barely changes in size.
fOpenWork.push([{target:mask_0, _width:500, time:OpenTime1, delay:1, ease:"easeOutExpo"},
{target:mask_0, _height:500, time:OpenTime1, delay:1, ease:"easeOutExpo"}
]);
My registration point of the MC seems to be on the right side for what I think I am trying to do. How would I need to set his up to get it to work? Would I use a different shape?
Diagonal Scrolling?
Is it possible to modify this tutorial:
http://www.kirupa.com/developer/flash5/slidingmenu.htm
to enable the buttons to scroll to a mc if the clipgeneral mc was organized like this:
OO
OO
rather than like this:
OOOO
so instead of just scrolling sidways, it would be possible to scroll both vertical and diagonaly accordingly?
Thanks.
chop.
Diagonal Lines
Hello,
Why is it that a diaganal black line in flash actually looks greyish in the movie?
More importantly, is there a way to fix this?
thanx.
Diagonal Scroller
Well, I wouldnt have a clue where to start in developing a diagonal scroller from scratch. So I wondering if anybody knows of any that I can download?
I've had a good search, and by the looks of it, a scroller that diagonaly scrolls text or mc's doesnt seem possible.
Cheers
Hittest Diagonal
Hello guys,
I'm busy now with a game now. I'm having problems with the hittest. I found a nice tutorial on flashfocus.nl. Maybe the dutch people know the site...But anyway, I had to move my charachter on a perspective way as you can see i the code or fla:
var heroW = 10;
var heroH = 20;
//var velY = 0;
//var stepS = 8;
var stepX = 8;
var stepY = 4;
//var jumping = true;
var grondY = 380;
this.onEnterFrame = function() {
if (Key.isDown(Key.UP)) {
for (var i = 0; i<stepX; i++) {
hero._x--;
}
for (var j = 0; j<stepY; j++) {
hero._y--;
}
}
if (Key.isDown(Key.DOWN)) {
for (var i = 0; i<stepX; i++) {
hero._x++;
}
for (var j = 0; j<stepY; j++) {
hero._y++;
}
}
if (Key.isDown(Key.LEFT)) {
for (var i = 0; i<stepX; i++) {
hero._x--;
}
for (var j = 0; j<stepY; j++) {
hero._y++;
}
}
if (Key.isDown(Key.RIGHT)) {
for (var i = 0; i<stepX; i++) {
hero._x++;
}
for (var j = 0; j<stepY; j++) {
hero._y--;
}
}
};
And then i saw the hittest code for regular movements see below for the left:
if (Key.isDown(Key.LEFT)) {
for (var i = 0; i<stepX; i++) {
hero._x--;
for (var j = 0; j<=heroH; j++) {
if (ground.hitTest(hero._x-heroW, hero._y-j, true)) {
i = stepX;
j = heroH+1;
hero._x++;
}
}
}
}
But for somehow i cant fix the hittest in my code. Can someone help me?
Diagonal Scrolling?
Is it possible to modify this tutorial:
http://www.kirupa.com/developer/flash5/slidingmenu.htm
to enable the buttons to scroll to a mc if the clipgeneral mc was organized like this:
OO
OO
rather than like this:
OOOO
so instead of just scrolling sidways, it would be possible to scroll both vertical and diagonaly accordingly?
Thanks.
chop.
Diagonal Lines
Hello,
Why is it that a diaganal black line in flash actually looks greyish in the movie?
More importantly, is there a way to fix this?
thanx.
Diagonal 3d Carousel
hi there,
im quite new to this site and omg its awesome.
im wondering why i never noticed it.
since im into animation im not pretty new to flash, but im really new to this whole actionscript animation stuff.
at the company i work for now, im faced with the completion of some jobs which are quite new to me. so i got to figure this out.
im also not totally new to coding as its nothing new today. every package nearly comes with some scripting language and im pretty proud for an action script beginner to understand nearly the whole code of the '3d carousel' project cheers to me.
hey, i find it quite awesome for me .
thing which is buggin me is - how to get this carousel flow diagonally ? the more i think about it, the more i believe this would be a quite different application but i´m not really sure about this. i tried to mess around with the sin&cos but all i acomplished was to nearly crash my system
i mean not really cycling this complete thingie 27degrees or so - i mean letting them flow from the upper right corner to the lower left for instance. the pictures should remain horizontally(is there a word like this?)
i ordered the animation book lee mentioned on amazon today but this will take some while to arrive grrr. and for the beginning i bought the flash math creativity book from friendsofed which cost me over 40 euros but there is not a lot explained. mostle chunks of code to figure it out by yourselfe. i mean its a great book but i don´t want to copy anything for a great effect and im to busy to take the code and learn from it at the moment. <yeah spammers are welcome to flame me>
this 3d carousel would fit perfectly for a job im working on at the moment but only if i get it to spin diagonally.
sorry for my bad english ^^
would be awesom if you could help me out!
Diagonal Lines - Please Help
Hi.
I am using Fireworks MX and I am naving probs creating a
diaonal line that is easy on the eyes. THe lines are too
pixely and the blur and shadow effects only seem to make
it more messy. I want a fluid diagonal line that has no
hint of pixels when viewed online. Could somebody show
me how to skillfully do this, possibly by drawing a box with
diaonal heights (and shadows on the right side)? Here is a
lame-duck version of what i am trying to accomplish (the inside
lines are for formatting):
_____
/____/
/____/
/____/
/____/ <-- shadow on right
^
|
shadow below
I'd really appreciate some design guru direction here - i
am a programmer, not a designer.
Thanks!
Diagonal HitTest/bounce
hiya,
im building an interface which is essentially a ball bouncing around inside a trapezoidish shape,
.........________
.........|......|
......../....../
......./....../
......|______|
- more or less, all 90 or 45 degree angles. do you know how to make it so the ball can bounce off a diagonal wall? the problem i am having is that the hitTest works off the rectangle created by the farthest edges of the object, since the diagonal walls run at 45 degrees, would there be a way to calculate a triangular half and use that for the hitTest?
thanks
G
ThX
li'l green dude
Smooth Diagonal Scrolling
Ok, I got a movie clip that scrolls diagonally. Inside the movie i'm using the script:
setProperty (this, _x, getProperty(this, _x) - .3);
setProperty (this, _y, getProperty(this, _y) - .3);
it works, but it's really shaky. It looks like its climbing stairs.. it goes left then up then left then up, and i wont it to move diagonally instead of climb. Any ideas?
Thanks
Charlie
Diagonal Slider Flash Mx
How can I create a diagonal slider (line with draggable button on it)without creating a vertical or horizontal movie clip and rotating it? i need to get coordinates of the button and the rotation makes the math really complicated.
Any ideas? can i use a guide layer somehow to constrain a draggable button to a diagonal?
Thanks!
Diagonal Fade Transition Help
<!-- This element has the filter applied. -->
Hello,
I want to achieve diagonal fade transition between movie clips in flash. Something similar to what i want to do is in the following DHTML code. Any help of achieving this diagonal fade transition would be great.
Thank you
html file
<DIV ID="oTransContainer" STYLE="position:absolute; top: 0px; left: 0px; width: 300px;
height:300px; filterrogidXImageTransform.Microsoft.Strips(Du ration=5, Motion='leftdown') ">
<!-- This is the first content that is displayed. -->
<DIV ID="oDIV1" STYLE="position:absolute; top:50px; left:10px; width:240px; height:160px;
background:gold"> This is DIV #1 </DIV>
<!-- This content displays after the first content. -->
<DIV ID="oDIV2" STYLE="visibility:hidden; position:absolute; top:50px; left:10px;
width:240px; height:160px; background: yellowgreen; "> <BR> This is DIV #2
</DIV>
</DIV>
<BUTTON onclick="fnToggle()">Toggle Transition</BUTTON>
<SCRIPT>
var bTranState = 0;
function fnToggle() {
oTransContainer.filters[0].Apply();
if (bTranState=='0') {
bTranState = 1;
oDIV2.style.visibility="visible";
oDIV1.style.visibility="hidden";}
else {
bTranState = 0;
oDIV2.style.visibility="hidden";
oDIV1.style.visibility="visible";}
oTransContainer.filters[0].Play();}
</SCRIPT>
Diagonal Line Animation
I'm currently looking to create a diagonal line animation within Flash MX.
I've thrown together a really quick example (attached) using a JPEG with motion tween, but I'm really interested in creating this effect within Flash instead of having to import an existing image. Is this possible?
Many thanks,
Ricoz.
[cs3] Help With Diagonal Scrolling Text?
ok, this isn't making any sense to me...
check out this flash file, here
these are the exact same movie clips, only two different instances.
one is straight, the other set on a diagonal. as you can see, the diagonal doesn't work. it scrolls fine, but the text doesn't show up in the mc.
does anyone have any idea why this isn't working?
i'm stuck.
Diagonal Scrolling Text?
ok, this isn't making any sense to me...
check out this flash file, here
these are the exact same movie clips, only two different instances.
one is straight, the other set on a diagonal. as you can see, the diagonal doesn't work. it scrolls fine, but the text doesn't show up in the mc.
does anyone have any idea why this isn't working?
i'm stuck.
Diagonal Video Scrubber
Diagonal video scrubber
I have a video scrubber that controls an flv file. What I want to do is make it so the scrubber in on a diagonal line to simulate a 3d environment. Does anyone know of a good way to confine a movie clip on a diagonal path?
Thanks.
Diagonal SeekBar Component
I have placed a seekbar component and rotated it diagonally on the stage. The problem is that the seekbar handle no longer follows the bar when the FLV is playing. How can I script the seekbar's _y axis to follow the path of the seekbar? I have been searching for an answer for this question for a long time...any help would be greatly appreciated!
Here is an image of the situation: Image
Resizing A Diagonal Line
I have a line that is on an angle of 15.3 degs which i want to be the width of the stage - in case the stage/browser is resized.
I want the thickness and angle of the line to stay the same.
I have a stageListener to execute the onResize which works.
I have tried 3 methods within the function command, but they all have problems.
line._width = Stage.width;
- the angle changes depending on the size of the stage
line._width = Stage.width;
line._yscale = preloader._xscale;
- the line gets thicker as it gets longer
line._x = 0;
line._width = Stage.width * 1.05;
line._rotation = 15.3;
- with this method I start the line on the stage at 0degs which is then resized and rotated, however the thickness of the line still increases as the line gets longer.
Any ideas?
Cheers
Barton
Diagonal Text Swipes?
I am curious as to how people do text swipes in Flash? What I mean is, you know when the text swipes, say, from the top left to bottom right in a diagonal fashion? Do you have some sort of mask over the box or something and animate that quickly?
Thanks
Diagonal ScanLines - Da Mystery
Ever since I touched Flash I've always wondered. How is it that people create those diagonal scanlines so perfectly spaced out? I know it's possible in Photoshop and I also know it's possible in Flash! Take a look at diasin.com or 2advanced.com...how the hell is that done?:
HitTest With Diagonal Lines
i am creating a flash game and i can stop the caharacter from crossing lines but when i use diagonal lines, the character stops at the blue box seounding it.
i thought it would work but i need to know how to shrink the blue box that is created when you make a movie clip.
please help
----------CODE------------------------
onClipEvent (load) {
this._visible = false;
}
onClipEvent (enterFrame) {
if (this.hitTest(_root["stanD"])) {
_root["stanD"]._y -= _global.speed;
_root["stanD"]._x += _global.speed;
}
if (this.hitTest(_root["blob"])) {
_root["blob"]._y -= _global.moveSpeed2;
_root["blob"]._x += _global.moveSpeed2;
}
if (this.hitTest(_root["gEnemy"])) {
_root["genemy"]._y -= _global.gEnemySpeed;
_root["genemy"]._x += _global.gEnemySpeed;
}
}
Thick Diagonal Scanlines
hey,
what I am wanting to do it have the normal diagonal scanlines, but instead on the line being 1 px thinck, be say 100 px think, and i cant seem to get it, ne help?
thanks
Got The Straight Line Working = Need A Diagonal
Yeah the straight line is working great...Thanks for the assist...
Diagonal line is still a mystery.
But some ideas i had was attaching the clip to a motion guide layer ... drawing a path ...
Doesn't work though...
Why does it have to be so hard!!!!!
You would think that you could do this rather easily.
Custom Diagonal Scroll Bars HELP
I have been working on this all day, and I can't get it to work. I am trying to make a movie clip ( small button looking graphic) that when you click on it you can move it up and down a diagonal line. I am working with a 700 by 400 movie. The line starts at the bottom left corner (0,400) and has a slope of about 30 degrees( 2 units right, 1 unit up) As you move the small button looking guy, up the diagonal line it scrolls the diagonal movie clip that is sitting above it. At this point I can't even get the small button to work right. Does anybody have any suggestions?
Creating A Diagonal Line Preloader
Basically a 1px wide line wich starts at x=0 and y=0 and ends on x=500 and y=250.
Don't wat to use mask and tweening. Any idea on how to get started on this.
Preferably don't want the line to be dead straigth, there may be a slight offset from time to time.
I'm opening Flash now but really apreciate any help.
Bouncing Objects On A Diagonal Line
hi, i want to bounce a object on a diagonal line
i have already maged to bounce an object on a sreight line but i cant do it on a diagonal line.
|