Scrollable Terrain W/ Objects

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?

Anyone? Help?

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

char.hitTest(terrainMC.block)

understand ?

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?

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

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

Ah ok, heres the link:

http://spamtheweb.com/ul/upload/170508/42393_kindemo.fla

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.

okey i looked at this.
this is the worst kind of progamming :slight_smile: 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?

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

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?

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

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.

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

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

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

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 :slight_smile:

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?

[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?

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 :slight_smile:

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

Switch:
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’ .

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

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.