Character Movement

In the game I'm doing, the character can move in six directions by pressing the individual individual arrow keys, or press two at a time for the intermidiate direction. When you're not pressing any keys, the character stays still, facing the direction that he was last traveling. At first I thought to have four booleans, one for each key, and to have an integer that represented the direction for when no keys are pressed. The problem with this is that when you release the keys, you usally don't release them exactly at the same time, so the character will face the direction of the key last pressed. Does anyone know of a better way to do this?

Okay. In the keyReleased(KeyEvent e) method I would have a variable that checked the time between releases, if they are within 50 mm of each other don't record the new direction. if you don't understand I will give a code snippet.

Similar Messages

  • Multiuser character movement synchronization

    hello
    am working on a multi player game in flash cs3 and FMS 3.5,
    user can register, select their characters (small movieclips
    i have only one at this time and that is Fairy) and then login to
    game.
    every person can see character of all online users at his/her
    screen with username popped up at the head of characters.
    user can move his/her character on screen using arrow keys of
    keyboard but their movement is not synchronized and visible to all
    users. i want to synchronize character movements at all screens
    simultaneously.
    any positive response or help will be highly appreciated..
    regards
    maani

    I think the best manner to accomplish something like this
    would be with a shared object. Put each user in their own slot in
    the shared object with an x,y for their position.
    A shared object should update relatively quickly, but you
    could always use a sharedobject.setDirty() if performance isn't
    real time enough for you.

  • Character movement according to map?

    hi guys
    in my game there is a player(Actor) and the player is standing on a horizontally mapped tile...
    my problem is i just want to move the player according to the tiles . the player is a set of frames using drawRegion i am drawing that player ..when i press right key he has to move right in a position wise manner
    any pls give me a solution
    ***********here is my code***************
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    public class ExampleGameCanvas extends GameCanvas implements Runnable
    private boolean isPlay; // Game Loop runs when isPlay is true
    private long delay=8; // To give thread consistency
    private int k;
    private int counter=0;
    private int xpos=50;
    private int ypos=60;
    private byte ROTATE_NONE = Sprite.TRANS_NONE;
    private byte ROTATE_90 = Sprite.TRANS_ROT90;
    private byte ROTATE_180= Sprite.TRANS_ROT180;
    private byte ROTATE_270= Sprite.TRANS_ROT270;
    private byte CURRENT_ROTATE=ROTATE_NONE;
    private Image clwalk;
    private Image tilesImg,bottomboard,clownIdle; //Image varibale declaration-kris
    private int clwalkXstart=0;
    private int clnX=0;
    private int tileXPos = 0;
    private int tileYPos = 150;
    private byte tileWidth = 21;
    private byte tileHeight = 21;
    private int tileStartXPosition = 0;
    private int tileStartYPosition = 0;
    private int numberOfRows = 12;
    private int numberOfColumns = 11;
    private int tileStartY = 39;
    private int sampleMap[][] = {
    //1, 2, 3, 4, 5, 6, 7, 8, 9,10,11
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, //11x12
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, //-1 for empty space
    {0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0} //0 for square tile
    private int current_Map[][] = new int[numberOfRows][numberOfColumns]; //this will store the current level
    // Constructor and initialization
    public ExampleGameCanvas()
    super(true);
    try
    tilesImg = Image.createImage("/tiles_240x320.png");
    bottomboard = Image.createImage("/bottomboard_240x320.png");
    clwalk = Image.createImage("/cl_walk_240x320.png");
    }catch(Exception ee){}
    // Automatically start thread for game loop
    public void start()
    isPlay = true;
    Thread t = new Thread(this);
    t.start();
    // Main Game Loop
    public void run()
    Graphics g = getGraphics();
    while (isPlay == true)
    input();
    drawMap(g);
    drawPlayer(g);
    try { Thread.sleep(delay); }
    catch (InterruptedException ie) {}
    // Method to Handle User Inputs
    private void input()
    int keyStates = getKeyStates();
    // Right
    if ((keyStates & RIGHT_PRESSED) !=0 )
    System.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbb");
    clnX=clnX+2;
    else if ((keyStates & LEFT_PRESSED) !=0 )
    System.out.println("1111111111111111111111111111111111");
    clnX=clnX-2;
    private void drawMap(Graphics g)
    System.out.println("jjjjjjjjjjjjjjjjjjjjjjj");
    System.out.println("oooooooooooooooooooo");
    g.setClip(0, 0, getWidth(), getHeight());
    g.drawImage(bottomboard, 0, getHeight()-bottomboard.getHeight(), 0);
    current_Map=sampleMap;
    for(byte row = 0; row < numberOfRows; row++)
    for(byte col =0; col < numberOfColumns; col++)
    switch(current_Map[row][col])
    case 0:
    g.drawRegion(tilesImg, tileStartXPosition, tileStartYPosition, tileWidth, tileHeight, ROTATE_NONE, tileXPos,220, Graphics.TOP|Graphics.LEFT);
    break;
    if(tileXPos < 215)
    tileXPos += tileWidth;
    else
    tileXPos = 5;
    if(row >= 11)
    tileYPos = tileStartY;
    else
    tileYPos += tileHeight;
    // repaint();
    // flushGraphics();
    private void drawPlayer(Graphics g)
    g.setColor(0xffffff);
    g.fillRect(0,0,getWidth(),155+clwalk.getHeight());
    g.drawRegion(clwalk,clwalkXstart, 0, 26, 41, ROTATE_NONE, clnX,180, Graphics.TOP|Graphics.LEFT);
    clwalkXstart=clwalkXstart+26;
    if(clwalkXstart==390)
    clwalkXstart=0;
    flushGraphics();
    repaint();
    thanks in advance

    So, do you want to make a walking character that is not allowed to run through walls, or do you want the character to move automatically, so that it chooses an empty space that is on the side at an arbitrary height ?
    If the first thing is what you mean, then this is how I do it: before I try and move a character, I first check if the position it should move into is free. If it is, that is, if no tile is in the way, the motion is granted/allowed.
    Pseudocode:
    If Key(LEFT)
         If (Character can move to left) { Move character to left }
         If (Character can move to right) { Move character to right }
    }As for gravity and jumping, I use this:
    Pseudocode:
    If (jump > 0)
        jump = jump - 1
        *Move character upwards, if allowed*
    Else
        If (*Character can move downwards*)
             *Move character downwards*
        ElseIf Key(SPACE)
              jump = 150
    }

  • Game character movement

    Hi,
    I've got a system were I have constants for each of the compose points, and using a switch on that direction:
    For example, if north - speed from y, is east + x, and so on.
    This seems to work well, but I've always wanted to use degrees for the direction, rather then constants.
    I've made a little image to show what I'm after, for some reason my browser was being redirected when trying to view it, so I've made a little html to display it and can be found here: http://acquiesce.awardspace.co.uk/temp/viewImg.html
    In actual fact, the example i have there would be the equivalent of north-east in my current system.
    I've also put what I've done so far, http://acquiesce.awardspace.co.uk/temp/MovementTester.java, the sheep.png is on the viewImg, just save as target.
    I had this idea of having an up vector (Line2D), this vector could then be rotated by the characters direction to get a new line, then, say speed was 10, 10 units up this line would be the new position for the character.
    Does that make sense to people?
    I guess the only thing left to do is get the new pos that's 10 (or whatever speed is) units up the direction line, but I have no idea, how to do this.
    Can anyone add any thoughts? I remember doing something like this before, so I'll see what I can think of.
    Thanks,
    Luke

    I do make my life needlessly complicated at times.
    All i needed to do was change the length of the up line, so what was all this talk about circles and points on a circumference? I don't know... Anyway, here;s what I've ended up with, the sprite (sheep) follows the mouse around when moved:
    import java.io.File;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    import javax.swing.JFrame;
    import javax.imageio.*;
    public class MovementTester extends JFrame implements
    MouseMotionListener,MouseWheelListener
         public static void main(String[] args) {new MovementTester();}
         // The point were the sheep is to be drawn
         private Point2D pos=null;
         // The sheep direction (in degrees)
         private double dir=45;
         // The speed the sheep is to move
         private double speed=10;
         // Face the direction
         private boolean faceDir=true;
         // The centre of the sheep
         private Point2D sheepCentre=null;
         // The sheep
         private BufferedImage sheep=null;
         // The up vector
         private Point2D up=null;
         // The centre of the frame
         private Point2D centre=null;
         public MovementTester()
              this.setSize(800,600);
              // Setup the sheep
              setupSheep();
              // Set the centre
              centre=new Point2D.Double(this.getWidth()/2,this.getHeight()/2);
              // Add the mouse thingys
              this.addMouseMotionListener(this);
              this.addMouseWheelListener(this);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.setVisible(true);
         private void setupSheep()
              try {
                   sheep=ImageIO.read(new File("tester\\Images\\sheep.png"));
              } catch (Exception ex) {ex.printStackTrace();}
              // Draw in the middle
              double x=(this.getWidth()/2)-(sheep.getWidth()/2);
              double y=(this.getHeight()/2)-(sheep.getHeight()/2);
              pos=new Point2D.Double(x,y);
         public void paint(Graphics g)
              //super.paint(g);
              // The buffer
              BufferedImage buff=new BufferedImage(this.getWidth(),this.getHeight(),
                        BufferedImage.TYPE_4BYTE_ABGR_PRE);
              // Get the buff g
              Graphics2D buffG=(Graphics2D)buff.getGraphics();
            if (isOpaque()) { //paint background
                 buffG.setColor(getBackground());
                 buffG.fillRect(0, 0, getWidth(), getHeight());
              // The up vector (sheep x and y - speed)
              up=new Point2D.Double(pos.getX(),pos.getY()-speed);
              // The up line from sheep to up
              Line2D upLine=new Line2D.Double(pos,up);
              // The direction line
              Line2D dirLine=null;
              // Draw the up line in blue
              buffG.setPaint(Color.blue);
              buffG.draw(upLine);
              // Roate the up line
              AffineTransform alf=AffineTransform.getRotateInstance(
                        Math.toRadians(dir),upLine.getX1(),upLine.getY1()
              // Get the transformed shaoe as a line
              dirLine=toLine(alf.createTransformedShape(upLine));
              // Draw the direction line in red
              buffG.setPaint(Color.red);
              buffG.draw(dirLine);
              // Move to end of the dir line
              pos=new Point2D.Double(dirLine.getX2(),dirLine.getY2());
              // The centre of the sheep
              sheepCentre=new Point2D.Double(pos.getX()+(sheep.getWidth()/2),
                        pos.getY()+(sheep.getHeight()/2));
              // If face dir
              if (faceDir)
                   // Rotate to dir
                   //sheep=rotate(sheep,dir,pos.getX(),pos.getY(),null);
    //           Draw the sheep
              buffG.drawImage(sheep,(int)pos.getX(),(int)pos.getY(),null);
              // Draw the buff
              g.drawImage(buff,0,0,null);
         public void mouseMoved(MouseEvent e)
              // Get the mouse x,y
              double mX=e.getPoint().getX();
              double mY=e.getPoint().getY();
              // Make a point at the top middle of the frame
              Point2D top=new Point2D.Double(centre.getX(),0);
              // The dist of top to centre (side a)
              double sideA=Point.distance(top.getX(),top.getY(),
                        centre.getX(),centre.getY());
              // The dist pf centre to mouse point (side b)
              double sideB=Point.distance(centre.getX(),centre.getY(),
                        mX,mY);
              // Between mouse and top (side c)
              double sideC=Point.distance(mX,mY,top.getX(),top.getY());
              // We wanna find the angle abound the centre
              // So the cos of angleCen
              double cosCen=((sideA*sideA)+(sideB*sideB)-(sideC*sideC))/(
                        2*(sideA*sideB));
              // Arc cos to get angle
              dir=Math.toDegrees(Math.acos(cosCen));
              // If mouse is on left side of centre
              if (mX<centre.getX())
                   // - from 360 to get the reverse angle
                   dir=360-dir;
              // Repaint
              repaint();
         public void mouseDragged(MouseEvent e) {}
         public void mouseWheelMoved(MouseWheelEvent e)
              // If up (away)
              if (e.getWheelRotation()<0)
                   // More speed
                   speed=speed+4;
              else {speed=speed-4;}
         public static BufferedImage rotate(BufferedImage in,double angle,
                   double x,double y,RenderingHints rh)
              AffineTransform aff = AffineTransform.getRotateInstance(angle,x,y);
              // The transform op
              AffineTransformOp op = new AffineTransformOp(aff,rh);
              // Return the rotated bufferedImage
              return op.filter(in,null);
         public static Line2D toLine(Shape s)
              return toLine(s.getPathIterator(null));
         public static Line2D toLine(PathIterator path)
              // The line
              Line2D line=null;
              // The start of the line
              Point2D start=null;
              // The end of the line
              Point2D end=null;
              // Two points (x1,y1,x2,y2)
              double[] points=new double[2];
              // Get the first segment, should be move to and the stat of the line
              path.currentSegment(points);
              // Make the start point
              start=new Point2D.Double(points[0],points[1]);
              // Move to the next segment
              path.next();
              // Get the next segment, line to and the end point
              path.currentSegment(points);
              // Make the end point
              end=new Point2D.Double(points[0],points[1]);
              // Make the line
              line=new Line2D.Double(start,end);
              // Return the line
              return line;
    }I thought it would be cool if the image rotated to face the direction it's moving in, but when I tried that using the AffineTransformOp I got a RasterFormatException.
    I've had problems with op's and image loaded using the ImageIO.read() before, but they work fine loaded from the JPEGDecoder ???
    Guess I'll have to make a PNGDecoder next :|
    Anyway, I'm happy for the time being watching my sheep dance about. :D
    Luke

  • Character movement needs fine tuning

    This the code to move my hero mc around the screen.
    However, when you click directly under or over the mc it doesn't move. When I say directly above I mean the angle not the distance. ie: I am well above the mc but it doesn't move.
    Little kids are going to play this and it needs to be more responsive or they get frustrated.
    var speed:Number=.99;
    public function onEnterFrame(event:Event):void {
    var xDistance:Number=clickPoint.x-this.hero.x;
    var yDistance:Number=clickPoint.y-this.hero.y;
    if (Math.abs(xDistance)>10) {
    var angle:Number=Math.atan2(yDistance,xDistance);
    this.hero.x+=v*Math.cos(angle);
    this.hero.y+=v*Math.sin(angle);
    } else {
    this.hero.gotoAndPlay("static");
    enemy1.x = speed*enemy1.x+(1-speed)*hero.x;
    enemy1.y = speed*enemy1.y+(1-speed)*hero.y;
    if (clickPoint.x>=hero.x) {
    this.hero.gotoAndPlay("right");
    //trace(Math.abs(xDistance));
    if (this.hero.x>=clickPoint.x) {
    this.hero.gotoAndPlay("left");
    //trace(Math.abs(xDistance));

    You're not moving because your x offset is less that your required 10 pixels.  So even though your y IS, you're not considering it.
    var xDistance:Number=clickPoint.x-this.hero.x;
    var yDistance:Number=clickPoint.y-this.hero.y;
    if (Math.abs(xDistance)>10) {
          var angle:Number=Math.atan2(yDistance,xDistance);
          this.hero.x+=v*Math.cos(angle);
          this.hero.y+=v*Math.sin(angle);
    } else...
    You need to caluculate the actual distance between the position of your character and the mouse click, not just on one axis.
    Try this:
    var distance:Number = Point.distance(new Point(clickPoint.x, clickPoint.y), new Point(this.hero.x, this.hero.y));
    if (Math.abs(distance) > 10) {
         var xDistance:Number=clickPoint.x-this.hero.x;
         var yDistance:Number=clickPoint.y-this.hero.y;
         var angle:Number=Math.atan2(yDistance,xDistance);
         this.hero.x+=v*Math.cos(angle);
         this.hero.y+=v*Math.sin(angle);
    } else {
         this.hero.gotoAndPlay("static");
    There's no need to calc the x and y distance if your total distance isn't enough to move your character, so just moved that into the conditional.
    Hope it helps.

  • Character Movement + Rotation

    Hello,
    I am currently working on a car racing game but I am new to
    designing the engine for my game such as the physics for my car.
    So, I took help from a tutorial but could'nt quite understand the
    trigonometry part, can you explain it.
    The part I did not understand was,
    x = Math.sin(_rotation*(Math.PI/180))*speed;
    y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
    if (!_root.hit.hitTest(_x+x, _y+y, true)) {
    _x += x;
    _y += y;
    } else {
    speed *= -.6;
    Hope you can help me out,
    Thanking You,
    Chinmaya
    P.S. I know how to convert degrees to radians and know a
    little about unit circles. The main part I dont understand is that
    why do we multiply the sin of angle(in radians) to the
    speed!

    I'm not sure if I understand. Do you just need to know why
    you are multiplying the speed or is there something that isn't
    working?
    The multiplication is easy. Basically you have some speed,
    let's say 5. Now if you are going perfectly to the right along the
    x axis then you have 5 in the x direction and you have 0 in the y
    direction.
    If you are going down the screen you have 5 in the y
    direction and 0 in the x direction. Easy.
    But what if you are going at some angle? That is when it gets
    a little more tricky. Well back to your lovely unit circle. If you
    speed was 1 we have the same issue for the x and y directions. But
    if you go off at an angle you've got your sin component in the x
    direction and your cos in the y direction. And there you go, cos(0)
    = 1 and sin(0) = 0 meaning at an angle of zero all your motion is
    in the x direction.
    So for a given angle cos shows the amount you've got in the x
    direction and sin shows the y direction. That way you can tell your
    object how many x and y to move and it looks like movement in at an
    angle. You multiply them because you aren't always using a unit
    circle.

  • Character movement with mouse click

    This will be for an MMO online game/ world. So it needs to be good.
    Hi guys. I'm really happy I got this to work as I'm a neebie to AS3 but getting to love its simplicity. My problem is not my AS3 but my maths.
    I click the mouse and the movieclip runs to the mouse's x position. However, it only goes in one direction ie: downwards and to the right.
    I need to it go in all directions depending on where I click. I suppose it has to do with comparing x and y positions of both mouse and mc - ie: if one is bigger than the other then you can tell where both are positioned and then put the code in. Am I right and does anybody hace a little code like this flying around for me?
    import flash.display.Stage;
    import flash.events.Event;
    stage.addEventListener(MouseEvent.CLICK, myClickReaction);
    function myClickReaction (e:MouseEvent):void{
        sunny.gotoAndPlay("runback")
        //sunny.x = root.stage.mouseX
        //sunny.y = root.stage.mouseY
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
    function onEnterFrame(event:Event):void {
                 var xDistance:Number
                 var yDistance:Number
                //mc increments by 5 until it reaches mouse - mc (ie the distance)
                sunny.x += 5;
                sunny.y += 5;
                xDistance = root.stage.mouseX - sunny.x
                trace (xDistance)
                if (xDistance <= 0 ) {
                trace("works")
                sunny.gotoAndPlay("static")
                removeEventListener(Event.ENTER_FRAME, onEnterFrame);

    Thanks for contacting but the code more or less works already apart from the comments below.
    The position I get comparing mousex position and movieclip position. BUT it goes loopy when I move the mouse around. ie: I need the coordinates when I click and not a variable that changes while I move mouse around.
    I will check it out now.
    import flash.display.Stage;
    import flash.events.Event;
    stage.addEventListener(MouseEvent.CLICK, myClickReaction);
    function myClickReaction (e:MouseEvent):void{
    //sunny.x = root.stage.mouseX
    //sunny.y = root.stage.mouseY
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
    function onEnterFrame(event:Event):void {
                 var xDistance:Number
        var yDistance:Number
       //mc increments by 5 until it reaches mouse - mc (ie the distance)
                // if you click to the right of sunny then mouse is > than sunny.x so x = 5
       if (root.stage.mouseX > sunny.x) {
        sunny.gotoAndPlay("walk right")
        sunny.x += 5;
        sunny.y += 0;
        xDistance = root.stage.mouseX - sunny.x
        //if (xDistance <= 0 ) {
        //sunny.gotoAndPlay("static")
        //removeEventListener(Event.ENTER_FRAME, onEnterFrame);

  • How to freeze background while main character continues to move?

    I'm not sure what the term is called, but I'm sure you know what I mean. Like in the Twix commercials, when it "pauses" lol. What plug in or how can I create that effect using FCP? Thanks!
    GC
    PS..what's the term?

    hm. B version works then only, if the main character moves a little. And this is very long work for you (many keyframes).
    1. move the v1 to the v2.
    2. select your frame, wich you want to freeze
    3. Shift+N (Make freeze frame) and drag the v1
    4. put this to the v2 (original) video:
    Choose Video Filters/Matte/Eight point Garbage Matte and reposition all the 8 points! (around the main character) Modify the feather if you need.
    5. If the main character moves a little, then you perhaps don't need modify the 8 points, but He/she moves more, then you must use keyframe in this filter.
    But I think the best (most beautiful) solution can earn with the bluebox.
    Message was edited by: miisii

  • Fast movement appears choppy in Dvd

    Hello,
    I have a project that I made in sony vegas and then rendered as an mpg, then imported into Encore.  This same project I had also created in adobe premiere, rendered as an m2v, then imported into Encore (but now I am unable to export it from premiere.. I just had to change computers to a computer that does not have premiere).
    When I view the project within Encore, it seems fine, but when I view the burned Dvd, the parts of the movie that involve fast character movements appear choppy (that is the best word to describe it.. it's like there is not good blending between the frames or something)
    I am not positive what the issue is here.  I previously had the m2v file exported from premiere, like i said, and when I burned that, it seemed fine.. but I was using a different dvd burner at that time.  Now I am using a different computer, different dvd burner, and an mpg file that I created with Sony Vegas instead.  However, both video files look the same when i view them in Encore.
    If this is an issue with my dvd burner, what do you suggest I do? My next plan of action is to create an iso image with encore and try to burn that with another software.  What do you think?
    Thanks for the help!

    The bit-rate out of Vegas needs to be higher. Not sure of how Vegas allows control of Exports, but I would increase the bit-rate for the Export.
    Test from En with DVD RW discs, so you do not burn "coasters."
    Good luck,
    Hunt

  • Export QuickTime Prob from Flash - Junk displayed in .mov

    Hi
    I'm trying to export a Flash movie as a .mov file. The animation is not that big but there are strange display issues. As the character moves across the screen, there are bits and pieces left on the screen from the previous movements. It's just not rendering correctly and looks terrible. I can't seem to fix it and have been playing with the Format settings etc. It doesn't help. There's always the junk left on the screen. Any ideas? I am using CS4 on Mac OS 10.6.7
    Thanks!

    Hi luvromntns,
    Here is a good link to check out for other tips on export http://kb2.adobe.com/cps/401/kb401520.html.
    Thanks,
    Quynh
    Flash Authoring, QA

  • Enquiry about character moving and rotating diagonally on tiled map....

    I have been able to make my character move up down the map and not going thru the wall. I also have able to move diagonally but it move faster than the up and down speed. Also i can't figure out how to rotate the character when it moved diagonally.....
    Any hints or help?

    rotate() should always be accompanied with appropriate translate().
    See:
    http://java.sun.com/docs/books/tutorial/2d/TOC.html
    http://www.adtmag.com/java/articleold.aspx?id=1241
    http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html
    And, never mix AWT components with Swing ones.
    Use JPanel instead of Canvas.
    Use also standard drawing/painting technique shown above URSs.

  • Movieclip.x movement using keyboard event

    Hi, im working on a game project and i have a question about movie clip movement using keyboard event.
    Basicly i have a character on screen and it can move on the x axis using the left and right buttons.
    Im making my charater move by changing the x value of the character movieclip but i find very it laggy and not smooth and if im going point by point
    then it's too slow.
    Whats the best way to make the character move so that the transition will be smooth.

    Ok obviously you've left out where you add your eventListener, i'll assume that's a KEY_DOWN event. When the user holds down a key, that key event is triggered once immediately and then after a pause it is triggered at regular intervals. Check this out by holding down the up/down arrow and watching this browser window scroll.
    That's not the movement you'd be looking for when moving a character in a game. Instead, you'd be setting a variable on KEY_DOWN to indicate the character direction - it could be an integer for example that you increase by 1 if the user pressed RIGHT or decrease by 1 if the user pressed LEFT.
    In addition to your KEY_DOWN eventListener, you could have an ENTER_FRAME and  KEY_UP eventListeners set up:
    The enterFrame event handler could move the character in the direction specified in your direction variable. This is where you might ensure your character doesn't go beyond its limits in both directions.
    In the keyUp event handler, you could do the converse of what you did in the keyDown handler(increase by 1 if the user released LEFT, decrease by 1 if the user released RIGHT).

  • Movements

    Basically im making an animation that allows the user to move
    a character, however when one of the four keys are pressed, the
    character movement changes, however so do does the animation (for
    example if I click the left key the character turns to the left and
    if i hold the left key the character moves to the left, as if the
    it looks like it is moving. i have the animation for this).
    Basically I can't seem to stop the character from walking,
    they just keep walk until another key is pressed. So can anyone
    help me make it go back into a stance? This is my code im using:
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)) {
    _x--;
    gotoAndStop(5);
    if (Key.isDown(Key.RIGHT)) {
    _x++;
    gotoAndStop(6);
    if (Key.isDown(Key.UP)) {
    _y--;
    gotoAndStop(4);
    if (Key.isDown(Key.DOWN)) {
    _y++;
    gotoAndStop(3);

    when each of those keydowns are detected, start a listener to
    check if (and when) that key is up. if it is, goto the stance
    frame.

  • Flash character animation

    I am creating a CBT for E-Learning. In the CBT we have used
    animated character, voice over, play and pause option.
    By default play button is selected, when user click on the
    pause button it will pause the character movement like (body
    movement, eye-popping and lips movement) and as well as voice over.
    Click on play button it start the all the movement from where he
    paused it.
    I have faced following problem while doing the same:
    1) For Play and Pause option, I have made the character
    animation in flash timeline, and it is very time consuming to do
    the lips movement in timeline. If I put the lips in a movieclip
    then, clicking on Pause button it will not Stop.
    Now I need the solution how to reduce the time to do the same
    character animation in flash timeline with Play and Pause button.
    Any idea.....! Pl revert...
    Regards
    Sonum

    If I understand you have done the animation already, in a
    separate movieClip
    but can't get it to pause... If that is the case just add the
    code to your
    pause button to affect more than one clip. Something like:
    pauseButton.onRelease = function(){
    mainCharacter.stop();
    mainCharacter.lips.stop();
    You can have your buttons affect as many clips as you need...
    you could even
    use an array to hold clip references and use that in both a
    play and pause
    button:
    var myChar = [mainCharacter, mainCharacter.lips,
    mainCharacter.eyes];
    function animateChar(thePlayState:Boolean){
    for(var i = 0; i < myChar.length; i++){
    if(thePlayState){
    myChar
    .play();
    }else{
    myChar.stop();
    playButton.onRelease = function(){
    animate(true);
    pauseButton.onRelease = function(){
    animate(false);
    HTH
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Unable to move object

    Hey there everyone, I'm new to flash and following a tutorial on how to make a small game. I've made some subtle changes, namely I imported .png's and made them into shapes and now am trying to move them. Here is the tutorial:
    http://asgamer.com/2009/as3-flash-games-for-beginners-character-movement-handling-multiple -keypresses
    Here is an example of my two classes, as far as I know the ActionScript checks out ok...
    package com.spacerace
        import flash.display.MovieClip;
        import flash.display.Stage;
        public class Engine extends MovieClip
            public function Engine()
                var spaceBackdrop : Space = new Space();
                var playerShip : PlayerShip = new PlayerShip();
                stage.addChild(spaceBackdrop);
                spaceBackdrop.x = stage.width / 2;
                spaceBackdrop.y = stage.height / 2;
                stage.addChild(playerShip);
                playerShip.x = 60;
                playerShip.y = 100;
    package com.spacerace
        import flash.display.MovieClip;
        import flash.display.Stage;
        import com.senocular.utils.KeyObject;
        import flash.ui.Keyboard;
        import flash.events.Event;
        public class PlayerShip extends MovieClip    {
            private var stageRef:Stage;
            private var key:KeyObject;
            public function PlayerShip(stageRef:Stage)
                this.stageRef = stageRef;
                key = new KeyObject(stageRef);
                addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
            public function loop(e:Event) : void
                y--;
    I'm completely at loss to what the problem could be, everything appears fine on screen, but the ship simply doesn't move.

    Ah yes, can't believe I missed that. However I'm getting another problem now. When I attempt to pass a reference of stage into the constructor the compiler throws an error:
    1136: Incorrect number of arguments.  Expected 0.
    I'm not sure why I'm getting this as the PlayerShip constructor is set up to accept a reference of Stage.

Maybe you are looking for

  • RWB and internet explorer 7

    Hi. Im having trouble getting internet explorer 7 and the RWB to work together. Errors popping up are like these: 'ur_txt' is undefined Object expected '_htmlbMessageBar' is undefined Is it possible at all to run RWB with IE7 or do I have to reinstal

  • Reg:Excise Base value

    Dear All, while doing imports PO My PO quantity is 1500 pc, I have done duty miro for 500pcs only now at the time of GRN after changinh the qty to 500 pcs the base value , BED,ECS & Secs r not updtd for the qty i have entered instead it is showing fo

  • Licensing templates to sell online

    hello. I recently become web designer. i Am trying to make a online shop on BC to sell web site templates of my own creation.I´ve seen on other template shops that it is necessary some type of license for the clients tp purchase our software.Were do

  • Difference in number of records in GROUP BY and PARTITION BY

    Hi Experts If I run the following query I got 997 records by using GROUP BY. SELECT c.ins_no, b.pd_date,a.project_id, a.tech_no FROM mis.tranche_balance a, FMSRPT.fund_reporting_period b, ods.proj_info_lookup c, ods.institution d WHERE a.su_date = b.

  • Adapter monitor namespaces

    Hi everyone, when viewing the Adapter-Monitor i get a list of namespaces for each host i am exploring. Now i was wondering where this list of namespaces is exactly gathered from. I understand that it is connected to the deployed adapters but where is