Be a Supporter!

(help) AS2 BG scrolling stop

  • 369 Views
  • 4 Replies
New Topic Respond to this Topic
HypNosE777
HypNosE777
  • Member since: Mar. 5, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
(help) AS2 BG scrolling stop 2010-12-07 23:13:37 Reply

Hi I'm gonna make this simple (:
im a newbi at AS and i know only a tiny bit of AS2 but i learn quickly and redo the codes for new stuff
anyway to my question.

I wantå my background to stop moving when player hit wall ?
my code are on the background object. (:

MC list
that we will need

MCplayer
MCwall
MCbg

Here is my code
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this._x -= 5;
}
if(Key.isDown(Key.LEFT)){
this._x += 5;
}
}
onClipEvent (enterFrame) {
if (_root.player.hitTest(_root.wall)) {

---[what do i do here?!]---

}
}

so my question what do i need to do to finish this code?


BBS Signature
HypNosE777
HypNosE777
  • Member since: Mar. 5, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to (help) AS2 BG scrolling stop 2010-12-07 23:16:53 Reply

or i forgot to ask as well.

is there a way that the background can move when the plater do?

like when player _x +=2
the background would _x +=1

or something like that?


BBS Signature
Spysociety
Spysociety
  • Member since: Dec. 30, 2009
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to (help) AS2 BG scrolling stop 2010-12-08 10:03:25 Reply

Basically, apply it a boolean variable to check if your background will move or not. Let's start by:

var moveMyBg:Boolean = true;
// then while applying it....
if(moveMyBg == true)
{
     // function for your background move
};

So when you hit the wall you can set the variable to false, for example:

if(_root.wall.hitTest(this))
{
     _root.moveMyBg = false;
};
HypNosE777
HypNosE777
  • Member since: Mar. 5, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to (help) AS2 BG scrolling stop 2010-12-09 09:13:02 Reply

Okay so i sort a got i to work, the only thing is, when my player is not touching wall
it wont start moving again?

so here is what i boiled the code down to (:

onClipEvent (load) {
	var MoveMyBg:Boolean = true;
	var bgspeed:Number = 5;
}

onClipEvent (enterFrame) {
if(MoveMyBg == true)
{

  if(Key.isDown(Key.RIGHT))
  this._x +=bgspeed;
  
  if(Key.isDown(Key.LEFT))
  this._x -=bgspeed;

}
}

onClipEvent (enterFrame){
	if(_root.player.hitTest(_root.wall))
	MoveMyBg = false;
	
} 	else {
}
}

BBS Signature
HypNosE777
HypNosE777
  • Member since: Mar. 5, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to (help) AS2 BG scrolling stop 2010-12-09 13:11:34 Reply

Hi I would just say I figuret it out :D
what a great feeling when you're new at codeing! :D

onClipEvent (load) {
	var MoveMyBg:Boolean = true;
	var bgspeed:Number = 5;
}

onClipEvent (enterFrame) {
if(MoveMyBg == true)
{

  if(Key.isDown(Key.RIGHT))
  this._x +=bgspeed;
  
  if(Key.isDown(Key.LEFT))
  this._x -=bgspeed;

}
}

onClipEvent (enterFrame){
	if(_root.player.hitTest(_root.wall))
	MoveMyBg = false;
	
	else{
		MoveMyBg = true;
	}
}

BBS Signature