The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsHi 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?
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?
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;
}; 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 {
}
}
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;
}
}