PDA

View Full Version : [AS2] Platformer VCAM


paradox14
12-17-2008, 09:36 PM
Hey guys, I am making a side-scrolling shooter/platformer and have just put my VCAM into my .fla (AS 2.0)

The problem I'm having is that my character jumps onto a platform he falls through it. It's weird because the platform he starts on works fine, but when he jumps onto another he stands there for about half a second and falls through. All my platforms are in one MC (instance name is ground).
When I take out _y += (_root.Char._y-_y); from the vcam MC on the main stage, it works fine, but it won't track my character up or down.

Here are my codes:

For my VCAM MC on the main stage:
onClipEvent (enterFrame) {
_y += (_root.Char._y-_y);
_x += (_root.Char._x-_x);
}

The code inside the VCAM MC:

function camControl()
{
parentColor.setTransform(camColor.getTransform());
var _l4 = sX / this._width;
var _l3 = sY / this._height;
_parent._x = cX - this._x * _l4;
_parent._y = cY - this._y * _l3;
_parent._xscale = 100 * _l4;
_parent._yscale = 100 * _l3;
} // End of the function
function resetStage()
{
var _l2 = {ra: 100, rb: 0, ga: 100, gb: 0, ba: 100, bb: 0, aa: 100, ab: 0};
parentColor.setTransform(_l2);
_parent._xscale = 100;
_parent._yscale = 100;
_parent._x = 0;
_parent._y = 0;
} // End of the function
this._visible = false;
var oldMode = Stage.scaleMode;
Stage.scaleMode = "exactFit";
var cX = Stage.width / 2;
var cY = Stage.height / 2;
var sX = Stage.width;
var sY = Stage.height;
Stage.scaleMode = oldMode;
var camColor = new Color(this);
var parentColor = new Color(_parent);
this.onEnterFrame = camControl;
this.onUnload = resetStage;

//V-Cam Script

The Character MC's Code:

onClipEvent (load) {
gravity = 12;
scale = _xscale;
walkSpeed = 8;
maxjump = 0.1;
//you can edit the player by editing the codes xD

}
onClipEvent (enterFrame) {
if (air == true) {
_y += gravity;
state = 3;
}
if (Key.isDown(Key.LEFT) && !_root.leftbound.hitTest(_x, _y, true)) {
_x -= walkSpeed;
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT) && !_root.rightbound.hitTest(_x, _y, true)) {
_x += walkSpeed;
_xscale = scale;
}
if (_root.ground.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (Key.isDown(Key.UP) && jump == true) {
_y -= jumpSpeed;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 30;
}
if (Key.isDown(Key.UP)) {
jumpcount += 1;
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {
state = 1;
}
if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {
state = 2;
}
if (!Key.isDown(65)) {
gotoAndStop(state);
}
_root.statetxt = state;
}
onClipEvent (keyUp) {
if (Key.getCode() == 83) {
jump = false;
}
}

Can you guys help me out?

NickZA
12-18-2008, 09:18 PM
I am guessing most people don't know what VCAM is... and to be honest, it hasn#t much to do with what you're asking. I don't see how your view code could affect your game logic, unless you are mixing the two of them up like spaghetti. I suggest you rename the thread "hitTest platform collision detection" -- you'll get more responses.

I'm not clued up with hitTest, as I use other methods, so will leave that to someone else. But basically 2 things come to mind:

-Are you correctly setting your hitTest alpha threshold values? Could VCAM be wrecking this by somehow changing alphas (I don't know if it does such) to go below the threshold for hitTesting?

-Your issues appears to be related to timing, whether it be due to alpha tweening or whatever. This is one of the problems with running your game loop the onEnterFrame way: You are mixing up your view code with your control code, making things harder to debug.