Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 09-15-2009, 07:02 PM   #1
Ciubhran
Member
 
Join Date: Feb 2009
Posts: 83
Default [AS3] Game Design Question

I am trying to design a game where the Hero is always positioned in the middle of the screen.

If he walks right, the world moves to the left instead of the character stepping to the right.

Now my question is... What is the best way to implement this?

I have a World object, a Hero object, and several Enemy objects.

What would you attach to what, and how would your "movement" functions look?

The only part of the Hero that "moves" is its rotation. It's placement on the screen should always remain in the center.
Ciubhran is offline   Reply With Quote
Old 09-15-2009, 07:46 PM   #2
Noct
Toys in the Attic...
 
Noct's Avatar
 
Join Date: Oct 2006
Location: NY
Posts: 3,017
Default

Check out tonyPA's tile based tutorials. I believe they are all in As2, but the concepts are the same regardless.

He may not specifically deal with games where the character stays centered, but it shouldn't really matter. Either way the background is scrolling, you just don't need the evaluation of the player position.

http://www.tonypa.pri.ee/tbw/
__________________
http://rwithers.com
Noct is offline   Reply With Quote
Old 09-19-2009, 03:16 PM   #3
bloodsample
myParents.addChild(me);
 
Join Date: Sep 2009
Location: Canada
Posts: 28
Default

The way I did this in my game was to put the whole game in an object container (mc_world) and then move that container in the opposite direction of the hero (while making sure you shift it relative to the "screen"). Just make sure that everything in your game is in this container (including your hero). I made a seperate CameraController class because I had other functions in there. But basically this is the function I used to center the "camera" around an object:

ActionScript Code:
// Change these to match your screen size: public const SCREEN_WIDTH = 550; public const SCREEN_HEIGHT = 400; // Call this function every frame.  mc_object is the object you want to center on. // mc_world is the container of the entire game. public function lookAt(mc_object,mc_world):void{   mc_world.x = SCREEN_WIDTH/2.0 - mc_object.x;   mc_world.y = SCREEN_HEIGHT/2.0 - mc_object.y; } // Sample main loop: function mainLoop(e:Event):void{   // ...     lookAt(myHero,myWorld);   // ... }

NOTE: I had to change the lookAt function to simplify it for this case (because I used Box2D in my game). So I'm not sure if it works 100% now that I changed it. But it did work in my game.

You then don't have to worry about individual entities (enemies, etc). You move your hero like you normally would. Since the hero is in mc_world, he will move relative to that world. But lookAt moves the entire world so that the hero is centered (or any other object you pass it).

Hope that helps. Good luck.

PS. I'm not sure if this is the best or most efficient way of doing things. This is just the way I did it and it worked fine for me.

Last edited by bloodsample; 09-19-2009 at 03:24 PM.
bloodsample is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:17 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.