PDA

View Full Version : Side scrolling artbased platform game


buzza_gts
04-09-2003, 02:34 AM
Hey guys,
Im currently making a side scrolling platform game and currently having troubles with the side scrolling. I am using this code,
if (Key.isDown(Key.LEFT)) {
_root.backGround._x += 1;
}
if (Key.isDown(Key.RIGHT)) {
_root.backGround._x -= 1;
}

to scroll the background. It works fine except for the fact that after you walk in one direction for about 2 seconds the charecter leaves the screen. I'v played around with all the differant speeds but to no aveil.
Any help\comments would be apprieciated.

CyanBlue
04-09-2003, 03:35 AM
Um... You should have some sort of if statement that checks the condition... Check my sample... ;)keyListener = new Object();
keyListener.onKeyDown = function()
{
if (Key.isDown(Key.LEFT))
{
if (_root.Background._x < 500)
{
_root.Ball._rotation -= 10;
_root.Background._x += 1;
}
}
if (Key.isDown(Key.RIGHT))
{
if (_root.Background._x > -200)
{
_root.Ball._rotation += 10;
_root.backGround._x -= 1;
}
}
};
Key.addListener(keyListener);

buzza_gts
04-09-2003, 05:05 AM
Would I be correct in saying that the 500 in:

if (_root.Background._x < 500)

relates to the size of the stage?

CyanBlue
04-09-2003, 05:20 AM
I think those numbers, 500 and -200, varies depending on the setup you have in your movie... ;)

buzza_gts
04-09-2003, 05:31 AM
Nup cant seem to get this darn thing to work, here is were im trying to slot in the code:
// Key pressed while CAPTAIN is walking
function KeyPressHorizontalWalk() {
// Next is the code to scroll the background.
keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.LEFT)) {
if (_root.backGround._x<20) {
_root.backGround._x += 1;
}
}
if (Key.isDown(Key.RIGHT)) {
if (_root.backGround._x>-20) {
_root.backGround._x -= 1;
}
}
};
Key.addListener(keyListener);
// Code which makes Captain America Walk.
if (Key.isDown(Key.LEFT)) {
move(-walkSpeed);
_xscale = -100;
distance = -4;
} else if (Key.isDown(Key.RIGHT)) {
move(walkSpeed);
_xscale = 100;
distance = 4;
}
}
// Keys pressed while CAPTAIN is jumping/falling
function KeyPressHorizontalJump() {
if (Key.isDown(Key.LEFT)) {
move(-jumpSpeed);
_xscale = -100;
distance = -4;
} else if (Key.isDown(Key.RIGHT)) {
move(jumpSpeed);
_xscale = 100;
distance = 4;
}
}
stop();


I just dont get it - any advice?

Thanks

CyanBlue
04-09-2003, 05:46 AM
Well... There is no way I could solve your problem with that much of information, but I could at least trim your code...
// Key pressed while CAPTAIN is walking
// This Key Listener needs to be defined only once...
keyListener = new Object();
keyListener.onKeyDown = function()
{
if (Key.isDown(Key.LEFT))
{
if (_root.backGround._x < 20)
{
_root.backGround._x += 1;
// You will need to specify
// the path for the following...
move(-walkSpeed);
_xscale = -100;
distance = -4;
}
}
if (Key.isDown(Key.RIGHT))
{
if (_root.backGround._x > -20)
{
_root.backGround._x -= 1;
// You will need to specify
// the path for the following...
move(walkSpeed);
_xscale = 100;
distance = 4;
}
}
};
Key.addListener(keyListener);
function KeyPressHorizontalWalk()
{
/*
I have moved your codes in if block
because that's where the code belongs...
You do not need this KeyPressHorizontalWalk()
function actually since this is being
calculated with the keyListener...
// Next is the code to scroll the background.
// Code which makes Captain America Walk.
if (Key.isDown(Key.LEFT))
{
}
else if (Key.isDown(Key.RIGHT))
{
}
*/
}
// Keys pressed while CAPTAIN is jumping/falling
function KeyPressHorizontalJump()
{
/*
You don't need this function either...
I don't understand why you need to
repeat the same code over and over...

What is the difference between
KeyPressHorizontalWalk() function and
KeyPressHorizontalJump() function???

if (Key.isDown(Key.LEFT))
{
move(-jumpSpeed);
_xscale = -100;
distance = -4;
}
else if (Key.isDown(Key.RIGHT))
{
move(jumpSpeed);
_xscale = 100;
distance = 4;
}
*/
}
stop();Check out the comments that I have made and answer those questions since you will need to clarify them for whoever helps you... I think you need to create a sample file and have it uploaded so that other people can take a look at it...

I am off to bed now, but I think somebody else will take a look at your question... ;)

Good luck...