all groups > flash actionscript > november 2006 >
You're in the

flash actionscript

group:

MC coordination


MC coordination mpwalker
11/4/2006 2:41:01 AM
flash actionscript:
I'm building a simple adventure game engine using the Flash Virtual Camera.
Basically, I need the camera MC to parallel the movement of the character MC so
that he is always centered in the camera as he moves around and the camera
stops moving in that direction when the character hits a wall. Here's the code
on the character:

[b]onClipEvent(load){
b = this.getBounds(this);
s = 5;

function move(x,y){
if(!_parent.map.hitTest(_x+b.xMin+x, _y+b.yMin+y, true) &&
!_parent.map.hitTest(_x+b.xMax+x-s, _y+b.yMin+y, true) &&
!_parent.map.hitTest(_x+b.xMin+x, _y+b.yMax+y, true) &&
!_parent.map.hitTest(_x+b.xMax+x-s, _y+b.yMax+y, true)
){
_x += x;
_y += y;
}
}
}

onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
move(0,-s);
}
else if(Key.isDown(Key.DOWN)){
move(0,s);
}
if(Key.isDown(Key.LEFT)){
move(-s,0);
}
else if(Key.isDown(Key.RIGHT)){
move(s,0);
}
}[/b]

I tried simply aligning the objects and saying on the camera MC:

[b]this._x = _root.hero._x;
this._y = _root.hero._y;[/b]

So simple it might work, I thought. Which it wort of did but was really
glitchy and the character would end up getting stuck in walls and such. Very
confused noob.

Thanks for any feedback!
Re: MC coordination mpwalker
11/4/2006 5:38:52 PM
Re: MC coordination kglad
11/4/2006 9:23:59 PM
Re: MC coordination mpwalker
11/4/2006 9:30:07 PM
Re: MC coordination kglad
11/4/2006 9:53:42 PM
if characterMC is your independent movieclip and cameraMC is your dependent you
can use:



moveI=setInterval(moveF,50);
function moveF(){
cameraMC._x=characterMC._x;
cameraMC._y=characterMC._y;
updateAfterEvent();
}
Re: MC coordination mpwalker
11/4/2006 10:53:11 PM
I'm sorry, I still don't really understand the code. I put it into frame one and filled in the respective identifiers...bupkiss. What am I doing wrong?

Re: MC coordination kglad
11/5/2006 1:12:31 AM
AddThis Social Bookmark Button