View Full Version : Recreating Super Smash Bros Camera Effect
four4swords
December 31st, 2007, 04:22 PM
Hi,
Yeah.. lol I know this has talked about a few times.. but there was never a straight answer! lol
So, I want to ask.. How would i go about re-creating the camera script like in Super Smash Bros where it constantly keeps both players on the screen(zooms out) if they move apart and Zooms in if they move closer..
I managed to achieve this effect with the aid of "v-cam" BUT.. it screws up my "attachMovieclip()" co-ordinates..
So, Does anyone know how to recreate this camera effect without v-cam?
Thanks!
-Z-
January 1st, 2008, 07:22 AM
Wouldn't you just make everything smaller when they are farther apart?
But I wouldn't use movieclips anyways,
four4swords
January 1st, 2008, 11:47 PM
Yeah it would.. But.. for example.. I managed to get this effect but it screwed up my attachMovieclip() functions..
I would attach a movieclip to my player's _x and _y co-ordinates.. but it would place it somewhere else!!
Do you know of one that doesn't mess with the attachMovieclip() functions?
hatu
January 2nd, 2008, 04:17 AM
If you just scale everything down, your attachMovieclips should still work because the registration point of your player mc doesn't change.
What do you mean with v-cam? I've never heard of that
-Z-
January 2nd, 2008, 08:43 AM
If you have 2 units, they are 50 pixels apart(the width of lets say 1 unit), and then you scale them down, to 1/50th the size, they will still be 50 pixels apart, however now the distance relevant to them is 50 units apart...
ArmoredSandwich
January 2nd, 2008, 10:08 AM
cant u just render everything to a bitmap and change the rectangle in order to scale?
ill work it out to see if it works xD
edit, its more difficult than i thought. Youll need matrixes and stuff. Currently im trying to zoom into a spot rather than into the middle of the picture xD
ArmoredSandwich
January 2nd, 2008, 11:52 AM
hmm, okay im done. I was expecting source and destination rectangles, but flash only has source rectangles.. that made it quite a lot more difficult.
Anyways, here is it, wasd to move camera, <- & -> to zoom in and out. http://www.wonima.demon.nl/other/zoomFunction.zip
As you can see it still need alot of work and I wonder if you can actually use it for your game. There is some documentation inside the .fla.
Remember tho, I used draw. This is very cpu intensive. There has to be a way to use copypixels with destination rectangles, that would be much easier to program, faster and just overall better.
Even if you cant use this, it might give u a push in the right direction.
gl hf
four4swords
January 2nd, 2008, 07:18 PM
:thumb: :thumb: Thanks for the feedback guys!
I managed to do the camera thing.. BUT I now realised that the problem was something to do with my "localtoGlobal()" function and it not liking my camera script!!
Here's a link to my Flash swf.. (http://img84.imageshack.us/my.php?image=localprobzl3.swf)
Use the arrow keys to move around.. and you can see the camera script do it's thing .. scaling everything down when your far from the other player..
NOW.. the problem is.. when you press "A" or "S".. You go to the SHOOTing animation..
I've made 2 shooting animations.. press A will give you the shooting animation with the localtoGlobal() function doing it's thing.. and as you can see.. it's suppose to attachMovieClip at the Red X that appears when shooting.. but.. if your far from your opponent.. it get's messed up and places it somewhere else!
the code i'm using for that is..
this.coords = new Object();
this.coords.x = this.DS._x;
this.coords.y = this.DS._y;
localToGlobal(coords);
i = random(999);
_root.attachMovie("Bullet", "Bullet"+i, i);
_root["Bullet"+i]._x = this.coords.x;
_root["Bullet"+i]._y = this.coords.y;
Which.. in the presence of the Camera script.. messes up it's attach-point..
the other script WITHOUT localtoGlobal is
_root.attachMovie("Bullet", "Bullet"+i, i);
_root["Bullet"+i]._x = _root.P1._x+((_root.P1._xscale/1.4));
_root["Bullet"+i]._y = _root.P1._y-30;
Which works with or without the camera script..
however.. I want the localtoGlobal() script to work properly WITH the camera script!
Anyone think they can tackle this?
If you need anything else please ask..
oh yeah.. the camera script is just this..
onClipEvent (load) {
_root.OxCamera = _root.Camera._width;
_root.OyCamera = _root.Camera._height;
}
onClipEvent (enterFrame) {
if (!_root.shake) {
_root.P1and2Dis = _root.P2._x-_root.P1._x;
_root.Camera._x = (_root.P1._x+_root.P2._x)/2;
_root.Camera._y = (_root.P1._y+_root.P2._y)/3.5;
_root.CamScale = (Math.sqrt(_root.P1and2Dis*_root.P1and2Dis))+200;
if (_root.CamScale>700) {
_root.Camera._width = _root.CamScale;
_root.Camera._height = _root.Camera._width/2;
} else if (_root.CamScale<700) {
_root.Camera._width = 700;
_root.Camera._height = 350;
}
}
}
that makes the camera always keep Players ONE and TWO on the screen!
The actual camera script is V-Cam (http://www.oreillynet.com/pub/a/javascript/2004/08/17/flashhacks.html?page=2)
Thanks!
ArmoredSandwich
January 2nd, 2008, 07:34 PM
I dont really understand why anyone would use localtoglobal. I checked it on the internet and it need a point in the parameters. Ur using just an object, im not sure if it matter but might be worth changing....
but ah.. never used local to global stuff thingy..
four4swords
January 2nd, 2008, 07:57 PM
localtoGlobal does the job when the camera script isn't there..
I use localtoGlobal so my bullet shot ALWAYS attaches itself on the root but in the position of JUST after the gun .. This way.. i don't have to change the code and it'll still work when i add more animations in.. e.g when i crouch down and shoot... the bullet's _y will be lowered..
But if i didnt use localtoGlobal it'll STILL fire from the same spot as if it were standing up..
Maybe there's something else to this localtoGlobal that i'm missing?
ArmoredSandwich
January 2nd, 2008, 08:34 PM
cant u just use the same coordinates for attach as you do with localToGlobal.
_root.attachMovie("Bullet", "Bullet"+i, i);
_root["Bullet"+i]._x = this.DC._x;
_root["Bullet"+i]._y = this.DC._y;
whats with the difference? :S
four4swords
January 2nd, 2008, 09:13 PM
cause "DC" is inside a bunch of movieclips.. So the movieclip's registration point changes "DC"'s _X and_Y positions.. and it wouldn't be the same if it were to be attached onto the maintimeline..
e.g. DC has a _x value of 15.. IN the movieclip.. so.. if i were to use your code.. it would attach the "Bullet" mc onto the stage at _x = 15 also!
So if my character would to move around.. and fire.. it would keep attaching at _x = 15..
ArmoredSandwich
January 2nd, 2008, 10:02 PM
I c, you could always.. you know get it on another way, but i guess local to global comes in handy here...
its 3 am now, ill try and help tomorrow, maybe someone else can help you instead. Vcam changes something about the scale and probably the location. I think thats where its going wrong somewhere... I didnt really looked at how vcam works.. more news tomorrow im sorry..
four4swords
January 2nd, 2008, 10:44 PM
lol Hey! It's all good! lol It's the exact opposite here! lol it's 3PM here :hugegrin:
ArmoredSandwich
January 3rd, 2008, 07:35 AM
does localtoglobal work if you use the camera, but dont rescale or reposition? I think it will :P
four4swords
January 3rd, 2008, 05:40 PM
:cyborg: lol Yep.. it works without the re-scaling and stuff..
So the problem is there?.. arrh.. lol how would i recode the scaling without it messing up my localtoGlobal?
ArmoredSandwich
January 3rd, 2008, 07:13 PM
is the problem in the rescaling, the repositioning or both?
four4swords
January 5th, 2008, 12:34 AM
Both..
I tested them both out.. and it seems to be an issue in both tests!
ArmoredSandwich
January 5th, 2008, 08:28 AM
Both..
I tested them both out.. and it seems to be an issue in both tests!
Im no expert in _roots and _parents.
Im guessing that you can also change the code of the vcam from _parent to _root. But im not sure :P Itll probably give another effect to the whole thing..
Always worth trying out. Otherwise you should apply the same transformations to the coordinates of your bullets when you attach em as you did with the vcam.
four4swords
January 6th, 2008, 10:02 PM
changing the "_parent"'s to "_root" doesn't change the effect of it at all.. it's just the same as WITH the _parents..
How would i go about applying the transformations to the coordinates of my bullets?
ArmoredSandwich
January 7th, 2008, 09:01 AM
changing the "_parent"'s to "_root" doesn't change the effect of it at all.. it's just the same as WITH the _parents..
How would i go about applying the transformations to the coordinates of my bullets?
but arent the movieclips attached at the correct place when changing it into the _root?
I think it would be something like
bullet._x = (attach.X + vcam._x)*vcam._xscale...
something like that, i dunno, just try something :P
four4swords
January 7th, 2008, 06:47 PM
arhh!! LOL! This doesn't seem to be working! lol Do you want my fla to mess around?
Does anyone know an alternative to localtoGlobal()?
ArmoredSandwich
January 8th, 2008, 10:04 AM
arhh!! LOL! This doesn't seem to be working! lol Do you want my fla to mess around?
Does anyone know an alternative to localtoGlobal()?
yes please :P
four4swords
January 8th, 2008, 06:59 PM
lol Ok here!
http://four4swords.110mb.com/OUT/TRIAL02.fla
The V-Cam is on the Camera layer.. lol
But yeah.. lol See what you can do.. Thanks again!
ArmoredSandwich
January 9th, 2008, 11:23 AM
lol Ok here!
http://four4swords.110mb.com/OUT/TRIAL02.fla
The V-Cam is on the Camera layer.. lol
But yeah.. lol See what you can do.. Thanks again!
okay im trying, but you gotta understand that I also have other things to do xD Besides that, ur codes a mess :P
four4swords
January 9th, 2008, 05:12 PM
okay im trying, but you gotta understand that I also have other things to do xD Besides that, ur codes a mess :P
lol All good! Spend as much time as you need to kick localtoGlobal()!!
lol It's not.. THAT messy.. lol
Thanks!
ArmoredSandwich
January 9th, 2008, 06:06 PM
lol All good! Spend as much time as you need to kick localtoGlobal()!!
lol It's not.. THAT messy.. lol
Thanks!
i think ill have it done the day after tommorrow (ill have no time tommorrow :( ).
and ur code is everywhere, on a lot of different movieclips. You gotta understand that I first coded everything on frame and then stepped over to OOP. Both are so much better if u dont want to forget where u put ur code. Besides that, its always tricky to see whats really going on when u look into someone's code.
oh well ;)
gregmax
January 9th, 2008, 07:16 PM
Is this what you are trying to accomplish?
http://whereatreebends.com/code/super-smash-camera-effect
I have done this script a couple months back, and never got around to posting it. I was too lazing and I got busy with client work... so I kind of lost track.
four4swords
January 9th, 2008, 10:24 PM
Is this what you are trying to accomplish?
http://whereatreebends.com/code/super-smash-camera-effect
I have done this script a couple months back, and never got around to posting it. I was too lazing and I got busy with client work... so I kind of lost track.
when it's saying that they put camControl() into their v-cam.. are they REplacing the one already there? Or is it something more?
I can't seem to get this going..
gregmax
January 11th, 2008, 01:26 PM
yes, I replace what as in there before. But I do keep the same variables as before just altered a bit to make it work
four4swords
January 13th, 2008, 07:09 PM
err.. here's my code..
function camControl(obj1, obj2):Void {
// fix x/width
var dist_x = (obj1._x-obj2._x);
if (dist_x<0) {
dist_x *= -1;
}
// fix y/height
var dist_y = (obj1._y-obj2._y);
if (dist_y<0) {
dist_y *= -1;
}
// not too pretty, but works great for me! ;P :D
if (dist_x>camW and disy_y<camH and dist_x<1000) {
this._height = sX/sY*dist_x;
// first, the height
this._width = (sX/sY*this._height);
} else if (dist_x<camW and dist_y>camH and dist_y<1000) {
this._height = sX/sY*dist_y;
this._width = (sX/sY*this._height);
} else if (dist_x>camW or dist_y>camH) {
if (dist_x<1500) {
// don't go out too far
if (dist_y<1500) {
//same rul applys here
this._height = sX/sY*(dist_y>dist_x ? dist_y : dist_x);
this._width = (sX/sY*this._height);
}
}
}
var scaleX:Number = sX/this._width;
var scaleY:Number = sY/this._height;
_parent._x = cX-(this._x*scaleX);
_parent._y = cY-(this._y*scaleY);
_parent._xscale = 100*scaleX;
_parent._yscale = 100*scaleY;
}
function resetStage() {
var _loc1 = _parent;
var _loc2 = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
parentColor.setTransform(_loc2);
_loc1._xscale = 100;
_loc1._yscale = 100;
_loc1._x = 0;
_loc1._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);
camControl();
this.onUnload = resetStage;
this.onEnterFrame = function() {
camControl("_root.P1", "_root.P2");
};
and err. it doesn't work..for me..
gregmax
January 13th, 2008, 09:20 PM
this.onEnterFrame = function() {
camControl("_root.P1", "_root.P2");
};
take away the quotes... you are passing them in as strings like that, that is a no no
four4swords
January 13th, 2008, 10:59 PM
ok..
function camControl(obj1, obj2):Void {
// fix x/width
var dist_x = (obj1._x-obj2._x);
if (dist_x<0) {
dist_x *= -1;
}
// fix y/height
var dist_y = (obj1._y-obj2._y);
if (dist_y<0) {
dist_y *= -1;
}
// not too pretty, but works great for me! ;P :D
if (dist_x>camW and disy_y<camH and dist_x<1000) {
this._height = sX/sY*dist_x;
// first, the height
this._width = (sX/sY*this._height);
} else if (dist_x<camW and dist_y>camH and dist_y<1000) {
this._height = sX/sY*dist_y;
this._width = (sX/sY*this._height);
} else if (dist_x>camW or dist_y>camH) {
if (dist_x<1500) {
// don't go out too far
if (dist_y<1500) {
//same rul applys here
this._height = sX/sY*(dist_y>dist_x ? dist_y : dist_x);
this._width = (sX/sY*this._height);
}
}
}
var scaleX:Number = sX/this._width;
var scaleY:Number = sY/this._height;
_parent._x = cX-(this._x*scaleX);
_parent._y = cY-(this._y*scaleY);
_parent._xscale = 100*scaleX;
_parent._yscale = 100*scaleY;
}
function resetStage() {
var _loc1 = _parent;
var _loc2 = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
parentColor.setTransform(_loc2);
_loc1._xscale = 100;
_loc1._yscale = 100;
_loc1._x = 0;
_loc1._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);
camControl();
this.onUnload = resetStage;
this.onEnterFrame = function() {
camControl(_root.P1, _root.P2);
};
That is the code now.. still doesn't work..
Is that ALL i'm suppose to do? Or did i miss something?
gregmax
January 13th, 2008, 11:33 PM
This is all I have on my vCam MC
function camControl(obj1, obj2):Void {
// fix x/width
var dist_x = (obj1._x - obj2._x);
if(dist_x < 0) { dist_x *= -1; }
// fix y/height
var dist_y = (obj1._y - obj2._y);
if(dist_y < 0) { dist_y *= -1; }
// not too pretty, but works great for me! ;P :D
if(dist_x > camW and disy_y < camH and dist_x < 1000) {
this._height = sX/sY * dist_x; // first, the height
this._width = (sX/sY * this._height);
} else if(dist_x < camW and dist_y > camH and dist_y < 1000) {
this._height = sX/sY * dist_y;
this._width = (sX/sY * this._height);
} else if(dist_x > camW or dist_y > camH) {
if(dist_x < 1500) { // don't go out too far
if(dist_y < 1500) { //same rul applys here
this._height = sX/sY * (dist_y > dist_x ? dist_y : dist_x);
this._width = (sX/sY * this._height);
}
}
}
var scaleX:Number = sX/this._width;
var scaleY:Number = sY/this._height;
_parent._x = cX-(this._x*scaleX);
_parent._y = cY-(this._y*scaleY);
_parent._xscale = 100*scaleX;
_parent._yscale = 100*scaleY;
}
// make frame invisible
//this._visible = false;
// Capture stage parameters
var oldMode:String = Stage.scaleMode;
Stage.scaleMode = "exactFit";
var cX:Number = Stage.width/2;
var cY:Number = Stage.height/2;
var sX:Number = Stage.width;
var sY:Number = Stage.height;
var camW:Number = this._width;
var camH:Number = this._height;
Stage.scaleMode = oldMode;
my onEnterFrame function is being called from the main timeline
four4swords
January 14th, 2008, 02:17 AM
ahh.. lol Ok I got it working! Thanks!..
Wow.. It's pretty much the same thing as mine.. lol I was hoping that yours would not affect localtoGlobal().. but it seems to affect it also!
Is there an alternative of instead of localtoGlobal()?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.