Strike Force Heroes 2
The explosive sequel to the hit game Strike Force Heroes!
3.96 / 5.00 11,373 ViewsObsolescence
Defeat the enormous mechanical beasts--and become one of them.
4.03 / 5.00 49,851 ViewsTrying to get the scaling to work in a game I'm working on. The movement for it is here, and it'd be awesome if somebody could teach me how do it. What I'm looking for is described below; when you move to the bottom the sprite becomes larger and smaller as it moves upwards. Thanks in advance!
At 12/18/12 08:13 AM, neonpaint wrote: Trying to get the scaling to work in a game I'm working on. The movement for it is here, and it'd be awesome if somebody could teach me how do it. What I'm looking for is described below; when you move to the bottom the sprite becomes larger and smaller as it moves upwards. Thanks in advance!
Relate its y position to its _xscale and _yscale properties. To help you even more, remember that the y scale in Flash starts from 0 at the top and gets larger the more you go down.
Adding this to Sam's reply:
Learn AS3.
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
At 12/18/12 08:13 AM, neonpaint wrote: Trying to get the scaling to work in a game I'm working on. The movement for it is here, and it'd be awesome if somebody could teach me how do it. What I'm looking for is described below; when you move to the bottom the sprite becomes larger and smaller as it moves upwards. Thanks in advance!
emoGhost.scaleX = emoGhost.scaleY = emoGhost.y / Stage.stageHeight;
What you are looking for is getting camera perspective right? Well you can just use the scaleX and scaleY properties as Sam suggested but if you really want to create a true perspective view, would be better write down some maths.
For this trick you will have to use a classic theorem in mathematics called Thales's Theorem, have you ever heard of it? Well it is very simple, and useful for this case. To represent the triangle, you can check the following diagram I made.
First let's indtroduce what the variables are:
* Focal length: the respective relative distance between the camera screen to the human eye.
* Z position: the distance which the figure (sprite) is far from the screen camera.
* H and h: sprite and screen height respectively.
Let fl be the focal length, z be the z position, H and h the heights we have:
H / h = (fl + z) / fl
Since we are trying to discover the scale, h / H is our scale ratio, so basically we can define the scale variable as:
s = fl / (fl + z)
Now we can define these variables in our code. Since z is the respective distance between the camera screen to the sprite we have, 0 would be the minimum value, this means that our object would be exactly in front of the camera and for example 1000 would be a very long distance between the camera and the object.
I would recommend 300 - 500 of focal length to get a nice perspective. Having z as a value 0 <= z <= 1000 for example, the focal length would be terrible if less than 50 because 40 / (40 + 1000) results in a ratio of aproximately 0.038 and as the sprite approaches the camera, having a z position of 500 would result in 0.088 which still very low.
Writing down everything we defined:
function scaleObject(obj:MovieClip, z:Number, focalLength:Number):Void
{
var scale:Number = focalLength / (focalLength + z);
obj._xscale = obj._yscale = scale;
// note: Long time I don't work with AS2 so depending of the scale you get
// you can multiply it by 100.
}
If you would like to movement your object, just define a speed variable, for example zspeed = 10 and to approach the sprite to the camera subtract z from zspeed or if you want to zoom out, just sum z to zspeed.
Example usage:
var z:Number = 500;
var focalLength:Number = 400;
var zspeed:Number = 10;
function onEnterFrame():Void
{
scaleObject(sprite_mc, z, focalLength);
z -= zspeed;
}
Hope that helps.
You can find a lot of information and pseudocode on this website:
Lou's Pseudo 3d Page
It has a lot of examples and explanations about depth in a 2D/3D space.
At 12/18/12 10:46 AM, Spysociety wrote: What you are looking for is getting camera perspective right? Well you can just use the scaleX and scaleY properties as Sam suggested but if you really want to create a true perspective view, would be better write down some maths.
Hope that helps.
Although this is kinda hard to grasp, I can always use it for learning. Thanks!
There's a book called 'Foundation ActionScript Animation Making Things Move' that has a whole two chapters devoted to 3D, and it's very easy to read.
If you need a preloader, and don't know how to stop your movie from looping, come here :)