A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: move left and right

  1. #1
    Senior Member
    Join Date
    Jun 2000
    Posts
    108

    Smile

    Hello

    Although this may sound stupid to ask, but I don't know why I just can't make it so that when I press a key then the character would move left, and same for right... should I use actionscripts such as setproperty? or something to do with telltarget? because I tried set property and it only works once after pressing the key, afterward no matter how many times I press it, it still doesn't work...


  2. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    323
    Well most likely you want to use actionscript with SetProperty... Ya know it would be easier for us to help if you posted your movement code here

  3. #3
    Junior Member
    Join Date
    Jul 2000
    Posts
    17
    What kind of game are you making?

  4. #4
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,092
    put a button in your movie clip
    then right click on the button and choose properties
    the put

    On (Key: <Up>)
    Set Property ("", Y Position) = GetProperty ( "/player",_y )-10
    End On
    On (Key: <Down>)
    Set Property ("", Y Position) = GetProperty ( "/player",_y )+10
    End On
    On (Key: <Left>)
    Set Property ("", X Position) = GetProperty ( "/player",_x)-10
    End On
    On (Key: <Right>)
    Set Property ("", X Position) = GetProperty ( "/player",_x)+10
    End On


    "player" is the instance name of the movie clip
    in thia example

    This actionscript will move the mc "player" up, down , left or right with the arrow keys.




  5. #5
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Or_ simplified:

    On (Key: <Up>
    Set Property ("", Y Position) = _y-10
    End On
    On (Key: <Down>
    Set Property ("", Y Position) = _y+10
    End On
    On (Key: <Left>
    Set Property ("", X Position) = _x-10
    End On
    On (Key: <Right>
    Set Property ("", X Position) = _x)+10
    End On

  6. #6
    Senior Member
    Join Date
    Jun 2000
    Posts
    435
    Hi all.

    ---WARNING ---
    Using the Keyboard repeat rate as an animation timer will result in game inconsistency! Keyboard-repeat rate is not a constant, as the users can change the settings in their control panel, and there is no standard or default.
    ---WARNING ---

    All games require a timer of some sort. Flash has a frame rate already, that would more then likely not line up with the keyboards rate.

    The work around is quite simple:

    1. Your Keyboard or UI (User Interface) sets variables that represent the Keys status.
    2. A flash MC (Move Clip) would be set up to process the data thus keeping consistency in gamy play.

    The Process MC would look at a Variable if (Var = Key Down) then call animation, and set Var back to default. Loop this in a “frame loop” for the best results experiment with different time delays and UI.

    I hope this makes sense, because it will save you from lots of headaches down the rode.

  7. #7
    Is there a way to tell if a key is currently down or if it's been released? For example, is there an onKeyUp event?
    I'm pretty sure the answer is no, but I just gotta make sure.

  8. #8
    Senior Member
    Join Date
    Jul 2000
    Posts
    323
    No, but I think there's a tutorial on this site with a workaround... Basically involves setting a timer to trigger a keyup if a keydown hasn't been received in the last 10 frames... Too dependent on the keyboard repeat rate...

    Hopefully flash 5 will solve all our problems with keyboard controls

  9. #9
    Senior Member
    Join Date
    Jul 2000
    Location
    Toronto
    Posts
    119
    What's the name of the tutorial for the refresh rate? This is something I've been trying to do for a while.

  10. #10
    Junior Member
    Join Date
    Jul 2000
    Posts
    2

    The address you were looking for


  11. #11
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Howdy 4eyes, In fact I dont put AS in a button just a matter of style rather I pass variables to the mc time line like Key_up=1 to trigger events. after the event the variable goes back to 0. Key_up=0. So there are 2 ways of moving your guy.

    1. moves till the button is down and stops when release.
    2. moves all the time you give em the direction only.

    which one you choose?
    Mad_sci

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center