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 04-09-2003, 02:34 AM   #1
buzza_gts
Registered User
 
Join Date: Oct 2002
Location: Australia
Posts: 39
Default Side scrolling artbased platform game

Hey guys,
Im currently making a side scrolling platform game and currently having troubles with the side scrolling. I am using this code,
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.
buzza_gts is offline   Reply With Quote
Old 04-09-2003, 03:35 AM   #2
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Um... You should have some sort of if statement that checks the condition... Check my sample...
ActionScript Code:
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);
Attached Files
File Type: zip scrollbackground.zip (2.6 KB, 322 views)
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 04-09-2003, 05:05 AM   #3
buzza_gts
Registered User
 
Join Date: Oct 2002
Location: Australia
Posts: 39
Default

Would I be correct in saying that the 500 in:

if (_root.Background._x < 500)

relates to the size of the stage?
buzza_gts is offline   Reply With Quote
Old 04-09-2003, 05:20 AM   #4
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

I think those numbers, 500 and -200, varies depending on the setup you have in your movie...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 04-09-2003, 05:31 AM   #5
buzza_gts
Registered User
 
Join Date: Oct 2002
Location: Australia
Posts: 39
Default

Nup cant seem to get this darn thing to work, here is were im trying to slot in the code:
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
buzza_gts is offline   Reply With Quote
Old 04-09-2003, 05:46 AM   #6
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Well... There is no way I could solve your problem with that much of information, but I could at least trim your code...
ActionScript 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...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue 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 09:46 PM.

///
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.