Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7831995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:58:49+00:00 2026-06-02T11:58:49+00:00

I am fairly new to coding. I am was wondering if there was a

  • 0

I am fairly new to coding. I am was wondering if there was a way so when I move my object with keys I can get the camera to keep on my object so I can move around a larger world than just my viewport.

I have tried to move the world around instead of my object but for what I am doing it makes my coding a lot more difficult

Here is the code I have.

stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown );

function keydown (event:KeyboardEvent):void{

  switch (event.keyCode){

    case Keyboard.LEFT :
    ball.x -= 10;
    break ;

    case Keyboard.RIGHT :
    ball.x += 10;
    break;

    case Keyboard.UP :
    ball.y -= 10;
    break;

    case Keyboard.DOWN :
    ball.y += 10;
    break;

    default :
    break;

  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:58:54+00:00Added an answer on June 2, 2026 at 11:58 am

    you could have the world and the character in a holding sprite/movieclip

    then as you move the character, you can set the position of the holder in the opposite direction.

    you can use global to local to get the position of the ball, and then can even apply some movement smoothing


    here’s some code that should work easy enough

    you need a movieclip called holder inside that is ball , the holder would also have your world and world assets. And as long as there’s no scaling you don’t need to use globalToLocal

    var middlePt:Point = new Point(stage.stageWidth/2, stage.stageHeight/2);
    var pt:Point = new Point(holder.ball.x, holder.ball.y);
    var destPoint:Point = new Point(-pt.x + middlePt.x,  -pt.y + middlePt.y);
    
    addEventListener(Event.ENTER_FRAME,enterFrame);
    function enterFrame(e:Event):void{
        holder.x = holder.x*0.5 + destPoint.x*0.5;
        holder.y = holder.y*0.5 + destPoint.y*0.5;
    }
    
    
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown );
    
    function keydown (event:KeyboardEvent):void{
      switch (event.keyCode){
    
        case Keyboard.LEFT :
        holder.ball.x -= 10;
        break ;
    
        case Keyboard.RIGHT :
        holder.ball.x += 10;
        break;
    
        case Keyboard.UP :
        holder.ball.y -= 10;
        break;
    
        case Keyboard.DOWN :
        holder.ball.y += 10;
        break;
    
        default :
        break;
    
      }
        middlePt = new Point(stage.stageWidth/2, stage.stageHeight/2);
        pt = new Point(holder.ball.x, holder.ball.y);
        destPoint = new Point(-pt.x + middlePt.x,  -pt.y + middlePt.y);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to C# coming from Java, and I'm wondering if there's
I'm fairly new to coding and just recently started working on integrating functions into
I'm new to C#, well, coding in general. I have done fairly well by
So I am still fairly new to all of this, that is coding, OS
I'm fairly new to coding in T-SQL and have run into an issue I
I'm fairly new to coding in general, learning to code in rails, and feel
I'm fairly new to coding with Objective-C/Xcode, so I'm just trying my luck with
Im fairly new to ASP.NET MVC 3, and to coding in general really. I
I am fairly new to coding in php and have come accross a bit
I am fairly new to web design and need some help coding a form.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.