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;
}
}
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
holderinside that isball, the holder would also have your world and world assets. And as long as there’s no scaling you don’t need to useglobalToLocal