Jump to content
  • Advertisement
Sign in to follow this  
Randall Perkins

AS3 Error

This topic is 2087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to get 2 movieclips to put there self above eachother when the other reachs the bottom of the stage

but it does not meet line to line, the stage width is 480 and height 800

and it gets faster and faster

import flash.events.Event;

stop();

function repeatBackground():void {
	
	if(gameBackground01.y + gameBackgroundY > 799) {
		gameBackground01.y = -800;
	}
	if(gameBackground02.y + gameBackgroundY > 799) {
		gameBackground02.y = -800;
	}
	if(gameBackgroundY > 799) {
		gameBackgroundY = 0;
	}
	
	gameBackgroundY++;
}

function gameLoop(e:Event):void {
	if(gamePause == 0) {
		repeatBackground();
		gameBackground01.y += gameBackgroundY;
		gameBackground02.y += gameBackgroundY;
	} else {
		
	}
}

gameBackground01.x = 0;
gameBackground01.y = -800;
gameBackground02.x = 0;
gameBackground02.y = 0;

addEventListener(Event.ENTER_FRAME, gameLoop);

 

 

Share this post


Link to post
Share on other sites
Advertisement

fixed it but it seems to lag in some spots

 

import flash.events.Event;

stop();

function repeatBackground():void {
	
	if(gameBackground01.y >= 800) {
		gameBackground01.y = -800;
	}
	if(gameBackground02.y >= 800) {
		gameBackground02.y = -800;
	}
	
	gameBackground01.y += 4;
	gameBackground02.y += 4;
}

function gameLoop(e:Event):void {
	if(gamePause == 0) {
		repeatBackground();
	} else {
		
	}
}

addEventListener(Event.ENTER_FRAME, gameLoop);

 

 

what if i wanted to add speed like setup a var speedVar:int = 2;

i tryed this but it wont work 

   gameBackground01.y += speedVar * 4;

   gameBackground02.y += speedVar * 4;

Share this post


Link to post
Share on other sites
<p>Try moving the addition to before the range correction. Otherwise I don't see anything that should be causing bugs.</p> Edited by Khatharr

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!