Ask a Question related to Macromedia Director Lingo, Design and Development.
-
j1mmy webforumsuser@macromedia.com #1
using arrow keys 2 control a sprite???
i basically want to be able to control a sprite on the stage (in this case a car) by using the up, down, left and right keys!
ive created 4 different cast members for every direction the car can move (car facing down, car facing up, car facing left & car facing right) for e.g. if i pressed the right key on the keyboard, then the car moves to the right corresponding to the right cast member!
can anybody help me out plzzzzzzzzz on how to go about doing this task???
any scripting would be helpful!
thanks
j1mmy webforumsuser@macromedia.com Guest
-
Arrow keys out of control - Wierd
Hi, I'm Illustrator deficient and just beginning the learning process of Illustrator CS utilizing the Total Training tapes. In lesson 3 there... -
arrow keys fail
Hi Folks, I published the completed example of the 'magic trick' director example, but on my PC using the arrow keys (or mouse click) fails to... -
arrow keys datagrid
Hi All, Bought the Flash MX datagrid component from Macromedia. Standard it does not handle the arrowkeys but they made an example on how to do... -
Move sprite along path with arrow keys???
Hi. I have an idea for a project, but have no idea how to create it in director. I want to move a sprite along a path, by using the up down left... -
arrow keys in motif
I can't seem to get the arrow keys on the number keys to work in motif -- NetBSD 96key pc keyboard(with the ctrl key where god intended it) ... -
vij010 #2
Re:using arrow keys 2 control a sprite???
hi...
First, find the keycodes that correspond to the arrow (Cursor keys), which make your car move....Use a case statement within a keydown handler to check whether that keycode has been fired...if yes, move the sprite, if no then do nothing.....
--example only!
on keydown
case (the keycode) of
123 : sprite(4).loch=sprite(4).loch +1
123 : sprite(4).loch=sprite(4).loch -1
end case
Vj
vij010 Guest
-
JB #3
Re: using arrow keys 2 control a sprite???
For kicks, I made a little test script to monitor arrow key
combinations, seems that any 2 arrow keys at once can be trached OK.
Wonder if your if/then or case logic is not testing for the foward key
down after the right key down code has run.
Here's the little score script I made for test purposes
needs a field named "display", used a score script to keep iteration
rate down to frame rate.
on exitFrame me
testKeys
go to the frame
end
--- Arrows
-- 28 L
-- 30 U
-- 29 R
-- 31 D
on testKeys
status = "Arrrow key state"
if keyPressed(numToChar(28)) then put "L down" into line 2 of status
else put "L up" into line 2 of status
--
if keyPressed(numToChar(30)) then put "U down" into line 3 of status
else put "U up" into line 3 of status
--
if keyPressed(numToChar(29)) then put "R down" into line 4 of status
else put "R up" into line 4 of status
--
if keyPressed(numToChar(31)) then put "D down" into line 5 of status
else put "D up" into line 5 of status
put status into field "display"
end
JB Guest
-
Word of Mouth Productions #4
Re: using arrow keys 2 control a sprite???
If you name the cast members of the car the same as the keycode of the
respective arrows then you can just set the member of the car sprite to the
string of the keycode. It's not a big deal but it makes things more
effiicient.
sprite (me.spriteNum).member = member (string (the keyCode))
Then you can create a speed parameter than can be changed elsewhere. Then
manipulate the sign of the speed parameter to determine how to update the
location of the car.
This would go in an exitFrame script and should execute when a key is
pressed. This way the car will continue to move while the key is down.
if [124, 125, 126, 127].getOne (the keyCode) > 0 then
case (the keyCode) of
124:
newPoint = point (-pSpeed, 0)
125:
newPoint = point (pSpeed, 0)
126:
newPoint = point (0, pSpeed)
127:
newPoint = point (0, -pSpeed)
end case
sprite (me.spriteNum).loc = sprite (me.spriteNum).loc + newPoint
sprite (me.spriteNum).member = string (the keyCode)
end if
--
Craig Wollman
Word of Mouth Productions
phone 212 724 8302
fax 212 724 8151
[url]www.wordofmouthpros.com[/url]
"j1mmy" <webforumsuser@macromedia.com> wrote in message
news:bpjhqf$e01$1@forums.macromedia.com...a car) by using the up, down, left and right keys!> i basically want to be able to control a sprite on the stage (in this case(car facing down, car facing up, car facing left & car facing right) for> ive created 4 different cast members for every direction the car can move
e.g. if i pressed the right key on the keyboard, then the car moves to the
right corresponding to the right cast member!> can anybody help me out plzzzzzzzzz on how to go about doing this task???
> any scripting would be helpful!
> thanks
>
>
Word of Mouth Productions Guest
-
hairybobby webforumsuser@macromedia.com #5
Re:using arrow keys 2 control a sprite???
well you may get problems if people start to hit two keys at once. You will need to check on the keydown and keyup handlers for changes.
property move
on keydown
move=0
if keyPressed(126) then move=1
end
on keyup
move=0
if keyPressed(126) then move=1
end
on exitframe me
if move=1 then sprite(3).loch=sprite(3).loch+4
end
that should work for one key. sorry but forgotten which key does which so can't provide the whole script.
HAIRYBOBBY - why didn't I choose a really cool name like the vulcanpimp
[url]http://www.geocities.com/hairybobby2000[/url]
new vector shape behaviors here
[url]http://www.geocities.com/hairybobby2000/vertexhome.html[/url]
hairybobby webforumsuser@macromedia.com Guest



Reply With Quote

