A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Moving MovieClip problem

Threaded View

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    14

    Moving MovieClip problem

    Hello,
    I'm creating a top down perspective shooter where you control a robot with wasd keys. All the graphics like, tiles, enemies and robot himself are placed into a container movieclip. Robot should always remain in the center of the screen when moving; I do that by moving it to the desired direction by some ammount of pixels, and then i move container MC to the opposite dirrection by the same ammount of pixels. The problem is, that whenever i move the robot, it shifts from the centre of the screen by approx .1 pixel, so if you walk long enough, robot from center of the screen, travels to the top of the screen. You can see that by putting the mouse at the tip of the robots gun, then walking for a bit without moving a mouse. The tip of the gun will no longer be pointing to mouse as it was before.
    Heres the code responsible for moving left (code for all other directions is almost the same):
    Code:
    else if(lA)  //left arrow pressed
    {
    	//this is responsible for playing walk animation, not important I suppose
    	if(getTimer() - player.lastStep >= player.animSpeed/player.walkAnim.length)
    	{
    		if(player.legs.currentFrameLabel == "last")
    		{
    			player.legs.gotoAndStop("stand");
    		}
    		else
    		{
    			player.legs.gotoAndStop(player.legs.currentFrame+1);
    		}
    	}
    	player.legs.rotation = 180;
    	playerDirection = "w";
    	
    	//collisions function returns true, if theres no unwalkable object in given coordinates, if true, then robot is moved
    	if(collisions(visTiles, player.x-(timeDiff/player.origAnimSpeed * player.walkSpeed), player.y))
    	{
    		//move player and container
    		player.x -= timeDiff/player.origAnimSpeed * player.walkSpeed;
    		container.x += timeDiff/player.origAnimSpeed * player.walkSpeed;
    	}
    }
    It appears as if player and container are moved by diffirent ammounts of pixels, but whenever i trace those ammounts are absolutely equal. I've tried to put
    Code:
    timeDiff/player.origAnimSpeed * player.walkSpeed
    into a variable and then use that variable to move container and robot, still, nothing changes. I also tried to round up
    Code:
    timeDiff/player.origAnimSpeed * player.walkSpeed
    from real nubmer, to integer and again, nothing changed. Any help on how to keep that guy in a center of the screen would be really appreaciated

    The game can be played here: http://ernyz.lhosting.info/TopDownShooter.html
    I can aswell upload game files, if the need arises.
    Last edited by Ernyz; 01-01-2013 at 10:38 AM.

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