AS3 change stage size - virtual camera - actionscript-3

Edit: Is there any way to adjust the stage size and position from inside flash?
Hey Im making a flashgame right now, its a 2D game with 2charakters. You can move them right now trought the level as you want to, but my problem is, its only one fourth of the whole level displayed, so I thought about making a camera that moves along with the player.
Ussualy I would put all the level content into a container and move the container, but my problem is, that I have 2charakters which can move and the camera has to focus on both of them otherwise the second player cant see what he is doing. So I thought about scaling the background and the characters up at the same time to create a zoom in zoom out effect depending on the distance between the players, but scaling the charakters up is pretty complicated because the charakter does not only consists out of one movieclip.

Put the level content along with the players in a container. Continue doing all the usual logic needed for the game, but instead of moving the level content; move the characters.
Then for each frame, adjust the scale and position of the new outer container based on the position of the two players.

Related

AS3 Can you make a sidescroller camera?

I've seen in flash sidescrollers they mostly use sidescroller by making the background move.
But if I had a background and I wanted the player to move and the camera to follow, how would I do it?
There are several ways to accomplish this. The first is to put all of the background objects into a container MovieClip and move that instead of the player. This also makes other aspects of having a camera, such as zoom and rotation, relatively simple, since you can just scale and rotate the container MovieClip.
Another method is putting all background objects into an array. Every time there is movement, you loop through the array and move the objects. This requires more math and separate x/ y variables for each object, so it's not as convenient.
One thing to note is that if you're going to rotate the camera, you might experience vibration issues as your camera gets further away from the origin. To prevent this, you'll have to shift all of the objects in your container MovieClip closer to the origin when they get too far away.
If you want the camera to ease towards the player's position, you just move 1/10 (or some other fraction) of the distance to the camera's target position each frame.

AS3: having problems implementing correct rotation with atan2

I have the following scenario: player is in the middle of the screen and never moves from those coordinates. If I click with the mouse on the far right of the screen, the A* script kicks in and moves the background the player is on according with its own walkable/not walkable criteria, so for example if there is an obstacle in between the center of the screen where the player always is in the far right of the screen, the background correctly moves in the opposite direction And when needed moves around the obstacle, so you have the illusion of player walking, but instead only the background moves.
my problem is that I don't know how to rotate my player to simulate that he is following the path that the actual background is making. For example, in the beginning, the player is facing down. If I click on the right side of the screen, the player should face right. When an obstacle is present, the player should face the direction of the path around the obstacle and so on
but again technically my player never moves, so I don't know what coordinates should I have the atan2 use. In my mind I thought that the player should rotate toward the center of the next best hop in the array of best path created during the A* script, but for some reason I can't figure out the correct coordinates y and x for the atan2 command
I bet this is a simple thing I overlooked, but apparently my mind is in shutdown mode, so I can use a new fresh perspective :-)
thanks!
First, do not code in brain shutdown mode, this can save you lots of brainhurt time.
You don't need atan2() in this scenario, since your player is technically on a grid instead of on the screen. Give the player internal coordinates on the grid that will be updated as the player walks around the world, and use them in your A* script. The A* script generates a sequence of tiles the player should walk, thus you derive player's facing from current and next tile, for example, if the next tile to walk is adjacent upwards, you make the player face up and continue moving.

Creating a stage bigger then the screen view

I'm trying to create a stage which has an image of the background, called lvl1.jpg. This image is 1920x6000 pixels. I want to start the game by creating the stage and adding the player on top. I'm placing a few stationary enemies on the level which the player should avoid.
I want to achieve this by letting the stage (or background image) and the enemies moving up a few pixels with each update. The size of the game file screen is 1000 by 600 pixels. So my gameclass is larger then my screen size will be. Is this possible? If so, how can I achieve this?
Yes, it is possible, but you should not directly use such a big bitmap anywhere, it's killing performance. And yes, it is possible for the game class to be bigger than stage size, look at Epic War 2 game for an example - it has a big battle scene that scrolls left-right on demand of the player.
In order for you to make such a game class, you should limit the actual screen presence to only the visible parts of your level. For this, research blitting techniques, which have a core concept of one visible Bitmap object with the size of a stage, whose BitmapData is redrawn each frame to display background, objects, player, monsters, etc.
As a first approach, you can have your Game class contain all the objects, including player, and change game.y so that the player is always within the stage boundaries.

'Runner' Game, loop sliding background, remove children when outside

I've just started using actionscript 3 and I am currently trying to make a scrolling runner game in Flash CS5, similar to the Flood Runner games from Tremor games. The difference is, however, that my game is not an endless runner game and the character has a destination that she must reach before time runs out. Alot of the tutorials I've read on the subject use the player character's x and y positions to scroll, but in my game the background scrolls independent of the character. The tutorials I've read about this do not address my problems specifically.
TL;DR: I do not want to loop my background but have a series of multiple background images.
I am trying to figure out the best way to patch together multiple background images seamlessly. Currently, I have one background movie clip object at the maximum pixel width. The background object scrolls to the left independently of the position of the player character, who can only jump.
What I am thinking about doing is this:
Every time a point at the far right edge of one background image reaches the far right stage boundary, I have my actionscript call an addChild command for the next background object and instantiate it at the far right stage boundary. It will scroll at the same speed as the preceding background object.
I also need to figure out how to remove the background objects once they have completely exited the stage for memory purposes.
So, what would be the best way to tackle this?
Your basic concept will work, and to remove you just need to evaluate when the background image is off the screen :
if (backgroundImage.x < -backgroundImage.width)
{
// image is no longer on the screen.
removeChild(backgroundImage);
}

Does the player move or the tiles in a tile-based game?

I'm not sure if this question fits properly, but I'm wondering in tile-based games, does the tiles 'shift' when the player is moving (and the player stays in the same place) or does the player move instead (and instead the tiles stay in the same place)?
Visually or in the model?
Visually, there’s usually some code that keeps the player fixed in the middle of the screen while the tiles scroll under him, with the tiles stopping and the player moving to the edge of the screen when the end of the map is reached. Typically this implies some sort of camera that knows how to follow the player, and perhaps changes its behavior depending on which direction the player is facing, and can also be locked for special effects and cutscenes.
In the model, it makes no sense to update the positions of all the tiles and every single object relative to the player, when you could instead just move the player.
Well, the specifics of how you want to draw it are up to you. Some tile-based games show the player fixed in the center of the screen -- in that case, your function to draw the character sprite always centers the character, while the function to draw the background would take an offset.
Others might give the player a pixel offset as well, either to show movement or to give "edges" to a map, not allowing the player to see what lies beyond.
How you implement it in your game is really up to you -- there's no "right" way to draw your sprites.
The tiles do. Unless there's no more to scroll in a certain direction, then the character moves. It's better to have as much as possible that's static cached together rather than move all the tiles individually.
The player moves, and the camera moves. The tiles are drawn shifted by the camera's position so that the world appears to scroll while the player stays roughly centered on screen. The camera follows the player, but usually a little loosely. (For example, you'll notice that you can walk a bit towards the edge of the screen before it starts scrolling in Super Mario Brothers.)