?
Solved

RPG Scrolling Game

Posted on 2009-12-27
9
Medium Priority
?
580 Views
Last Modified: 2013-12-26
Hello I am in process of a game and I have current movement so far:
onClipEvent (load) {
      movespeed = 5;
      this.previous_state = "standing";
      this.current_state = "standing";
}
onClipEvent (enterFrame) {
      if (Key.isDown(Key.LEFT)) {
            this._x = this._x-3;
            current_state = "left";
    } else if (Key.isDown(Key.UP)){
        this._y -= 3;
      current_state = "up";
    } else if (Key.isDown(Key.DOWN)){
        this._y += 3;
      current_state = "down";
      } else if (Key.isDown(Key.RIGHT)) {
            this._x = this._x+3;
            current_state = "right";
      } else {
            current_state = "standing";
      }
      
      if (current_state == "standing") {
            gotoAndStop("standing_seq");
      } else if (current_state == "right") {
            if (previous_state == "right") {
                  nextFrame();
            } else {
                  gotoAndStop("right_seq");
            }
      } else if (current_state == "left") {
            if (previous_state == "left") {
                  nextFrame();
            } else {
                  gotoAndStop("left_seq");
            }
      } else if (current_state == "up") {
            if (previous_state == "up") {
                  nextFrame();
            } else {
                  gotoAndStop("up_seq");
            }
      } else if (current_state == "down") {
            if (previous_state == "down") {
                  nextFrame();
            } else {
                  gotoAndStop("down_seq");
            }
      }
      previous_state = current_state;
}

But I need a way for a scrolling camera to follow it, can anyone help?
I have tried vCam but I can't get it to work.
0
Comment
Question by:robjay
  • 5
  • 4
9 Comments
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26129570
I used vCam before and it works perfectly for me. How are you implementing it?

This code only shows the responding to keys and the the change of character's rotation or effect when character is moving left or right.
0
 

Author Comment

by:robjay
ID: 26129584
Hmm, I tried vCam and I just don't get how it works. I am using Actionscript 2 by the way TanLiHao.
0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26129596
Yes I know that, from your code I can see that you are using AS2. The way to use vCam is just place it there, and then the area the vCam stretches across is the area you can see. Thus in the code, you move the vCam and then your scrolling effect will be achieved. Alternatively, you can use a mask, which is the way I will recommend because it's way simpler and you do not need such advanced features provided by vCam.

However, depending on how your scrolling game is created, you may find vCam or the mask better.

For example, if your scrolling game do not need to be resized bigger, as in like the examples in vCam shown then using vCam is better. Otherwise, if you just need to move the area seen (scrolling), a mask or simply moving the _root will be good.

You can let me see the source file on how you are implementing it or simply explain to me.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:robjay
ID: 26129605
Ok, I put the vCam there and it turns everything grey, but it doesn't move with my character...
maingame.fla
0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26130404
It doesn't, you have to give the vCam an instance name like virtualCam.

Then in your code add the moving of the camera.

For example, for moving left

in your code it shows this

  this._x = this._x-3;
You can shorten it to this._x -= 3;

You should already do that because there is inconsistency in your code.

Then under this code this._x -=3;

You add a following line of code.

virtualCam._x -= 3;

Your new code should be like this:

onClipEvent (load) {
      movespeed = 5;
      this.previous_state = "standing";
      this.current_state = "standing";
}
onClipEvent (enterFrame) {
      if (Key.isDown(Key.LEFT)) {
            this._x  -= 3;
            virtualCam._x -= 3;
            current_state = "left";
    } else if (Key.isDown(Key.UP)){
        this._y -= 3;
        virtualCam._y -= 3;
      current_state = "up";
    } else if (Key.isDown(Key.DOWN)){
        this._y += 3;
        virtualCam._y += 3;
      current_state = "down";
      } else if (Key.isDown(Key.RIGHT)) {
            this._x += 3;
            virtualCam._x += 3;
            current_state = "right";
      } else {
            current_state = "standing";
      }
     
      if (current_state == "standing") {
            gotoAndStop("standing_seq");
      } else if (current_state == "right") {
            if (previous_state == "right") {
                  nextFrame();
            } else {
                  gotoAndStop("right_seq");
            }
      } else if (current_state == "left") {
            if (previous_state == "left") {
                  nextFrame();
            } else {
                  gotoAndStop("left_seq");
            }
      } else if (current_state == "up") {
            if (previous_state == "up") {
                  nextFrame();
            } else {
                  gotoAndStop("up_seq");
            }
      } else if (current_state == "down") {
            if (previous_state == "down") {
                  nextFrame();
            } else {
                  gotoAndStop("down_seq");
            }
      }
      previous_state = current_state;
}



I corrected some obvious errrors and actually this is not the best way of coding but since you are doing it this way, I'm leaving it as it is.


For the gray portion, remove the tint on the camera and that will do. I'm not sure why the original code have a tint but just remove the tint and it won't be gray anymore. Select color effect under properties of the vCam and change the style from tint to none.
0
 

Author Comment

by:robjay
ID: 26133350
I got it to work, but how do I make it where the vCam follows your player?
0
 
LVL 14

Accepted Solution

by:
TanLiHao earned 2000 total points
ID: 26135813
Did I just not show how you do it in the code?

Copy that code above and replace the code in your player.

Give your vCam an instance name of virtualCam.
0
 

Author Comment

by:robjay
ID: 26135829
Oh ok, I just got it to work, I did everything before it just didn't work, maybe I forgot something.
But now its working, thanks :D
0
 

Author Closing Comment

by:robjay
ID: 31670308
Thanks for helping me with game!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question