# Scrollable Terrain W/ Objects

**URL:** <https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309>\
**Category:** flash\
**Created:** [May 14, 2008, 11:32am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309 "2008-05-14T11:32:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 14, 2008, 11:32am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/1 "2008-05-14T11:32:11Z")

</div>

Ok, so I’m making a overhead game and I want to make the terrain movable. But the only problem, I have objects which the player hitTest on it. So how do I make everything scrollable?

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 15, 2008, 10:04am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/2 "2008-05-15T10:04:21Z")

</div>

Anyone? Help?

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 15, 2008, 12:00pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/3 "2008-05-15T12:00:08Z")

</div>

have everything in 1 mc, like terrainMC.  
and then do hitttests from there,  
ex;

char.hitTest(terrainMC.block)

understand ?

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 16, 2008, 2:44pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/4 "2008-05-16T14:44:41Z")

</div>

Aw, curses I was afraid you would say that. Ok, so I just put everything under one MC. So now I just do,

if(Key.isDown(Key.RIGHT/LEFT)) {  
\_root.terrain\_mc.\_x -= speed  
}

So what if the player moves to the edge of the map?

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 16, 2008, 3:07pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/5 "2008-05-16T15:07:41Z")

</div>

depends on how you built it / reg points, etc…

attach your fla and i will tell you on how to make it

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 17, 2008, 1:48am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/6 "2008-05-17T01:48:33Z")

</div>

Ah ok, heres the link:

[http://spamtheweb.com/ul/upload/170508/42393\_kindemo.fla](http://spamtheweb.com/ul/upload/170508/42393_kindemo.fla)

---

<div class="post-metadata">

**Author:** ![cooldude88](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@cooldude88](https://forum.kirupa.com/u/cooldude88)\
**Post date:** [May 17, 2008, 5:15am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/7 "2008-05-17T05:15:29Z")

</div>

doesnt combining the mc’s into one movie clip always make the hitTest equal true for all it does is wrap a rectangle around the mc and check if the rectangle and the object are touching. correct me if im wrong but i had a problem when i made a game because i put the 4 walls into one mc and the hitTest always was true.

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 17, 2008, 1:42pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/8 "2008-05-17T13:42:24Z")

</div>

okey i looked at this.  
this is the worst kind of progamming 🙂 were you have all code in the movieclips…

i could never navigate thru this…

What you need to do is:

[AS]  
//EX block the char from walking left ( becouse the map ends there):

if(char.\_x\<0){  
//cannot walk this way  
}  
//EX block the char from walking right( becouse the map ends there):

if(char.\_x \> Stage.width){  
//cannot walk this way  
}  
//EX block the char from walking up( becouse the map ends there):

if(char.\_y \<0){  
//cannot walkthis way  
}  
//EX block the char from walking down( becouse the map ends there):

if(char.\_y \> Stage.width){  
//cannot walk this way  
}

[/AS]

As you se you cannot use the code straight ahead… you need to have these each respective movement statements, LIKE

if(){}else{ here you change the X and Y )

GOt it?

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 17, 2008, 1:55pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/9 "2008-05-17T13:55:55Z")

</div>

um…kinda heres my current code: (I placed everything under one mc called “terrain”)

```auto
onClipEvent (load) {

movespeed = 5;

}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
    _root.terrain._x -= movespeed
play();
_rotation = 90;
_x += movespeed;
}
if (Key.isDown(Key.LEFT)) {
    _root.terrain._x += movespeed
play();
_rotation = 270;
_x -= movespeed;
}
if (Key.isDown(Key.UP)) {
    
_root.terrain._y += movespeed
play();
_rotation = 0;
_y -= movespeed;
}
if (Key.isDown(Key.DOWN)) {
_root.terrain._y -= movespeed
play();
_rotation = 180;
_y += movespeed;
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
_rotation = 45;
}
if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
_rotation = 315;
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
_rotation = 135;
}
if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
_rotation = 225;
}
}

```

Now, I have no idea how to stop the terrain mc from moving onces it hits a certain x/y point of the stage. I tried if(\_root.terrain.\_x \< 0)) { the terrain moves, but it still doesn’t work. Also, when the player is being blocked by a wall and cannot move, the background keeps moving because the key is still down. How do I change that?

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 17, 2008, 2:46pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/10 "2008-05-17T14:46:08Z")

</div>

is that under terrain mc and not under player mc?  
have you uploaded an older verison?

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 18, 2008, 1:26am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/11 "2008-05-18T01:26:53Z")

</div>

Don’t mind the .fla file I haven’t update that yet. I put that code on “player” mc. If I put it on terrain mc, once it hits the edge, the player will be unable to move.

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 18, 2008, 7:26am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/12 "2008-05-18T07:26:53Z")

</div>

wait wait wait… no im confused.  
becouse i came to think about some stuff that you need to add…  
have you made it working?

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 18, 2008, 11:17am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/13 "2008-05-18T11:17:31Z")

</div>

yes the terrain is scrolling now, but my problem is, I don’t know how to set boundaries for the terrain. And also, when my player is being blocked by a wall, the terrain keeps moving while my player doens’t move. Heres the swf file:

\*\*[http://spamtheweb.com/ul/upload/180508/69378\_kindemo.php](http://spamtheweb.com/ul/upload/180508/69378_kindemo.php)

\*\*As you can see, if you try to go through the guard, the player doesn’t move but the terrain background keeps on moving because the key is still down.

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 18, 2008, 5:50pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/14 "2008-05-18T17:50:15Z")

</div>

im sorry. but this project has so much stuff i cant deal with…

rewrite the code to Frame 1, and place all objects with AS.

use listerners instead with Switch for moving, instead of OnEnterFrame with If…

Then i will help you 🙂

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 19, 2008, 1:38am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/15 "2008-05-19T01:38:42Z")

</div>

wish I can, I’m off to a messy start am I? I don’t know how to code listeners yet, heard of them though. And you mean to put the code that moves the player/terrain on the frame? Can you give me any good links to tutorials for listeners?

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 20, 2008, 1:26am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/16 "2008-05-20T01:26:55Z")

</div>

[quote=Macsy;2327805]im sorry. but this project has so much stuff i cant deal with…

rewrite the code to Frame 1, and place all objects with AS.

use listerners instead with Switch for moving, instead of OnEnterFrame with If…

Then i will help you :)[/quote]

Sigh, I still have no idea what you are talking about. I don’t know how to dynamically place the objects on screen, I have don’t know what are listeners and “Switch”, and what you mean by rewrite all the code to Frame 1? Can anyone explain?

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 20, 2008, 6:14am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/17 "2008-05-20T06:14:49Z")

</div>

with rewrite, i mean to rewrite all the code so you can use it from frame1 instead of having it everywhere.  
i useally charge 100usd / hour doing this 🙂

but i will come up with some guids for you. hold on!

---

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [May 20, 2008, 8:38am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/18 "2008-05-20T08:38:04Z")

</div>

Switch:  
[http://www.kirupa.com/developer/acti...switchcase.htm](http://www.kirupa.com/developer/acti...switchcase.htm)

Key listner:  
Check F1-help for Key.getCode and the example they have will bring up listner.

allso check AttachMovie() in F1-help for attaching MCs to the stage. Be sure to read everything becouse there is a part about linkage.

Without this you cant chance ‘map’ or ‘level’ .

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [May 21, 2008, 8:54am UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/19 "2008-05-21T08:54:19Z")

</div>

Ok Thanks, I’ll check them out. Meanwhile, if anyone has a solution to my problem, please post. 😜

---

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [June 5, 2008, 12:39pm UTC](https://forum.kirupa.com/t/scrollable-terrain-w-objects/260309/20 "2008-06-05T12:39:07Z")

</div>

Ok, I don’t mean to bump a old thread, but I really need to know how to stop a scolling terrain from moving. If you look at my other posts, you’ll see the .fla and the codings. Any help would be appreciated.
