-
Help Centring
Hey cn u plz help mei am making a game and i cnt seen to centre the guy so he wont go off the screen and is allways in the middle heres the code:
PHP Code:
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1.1;
friction = 0.9;
fly.onEnterFrame = function() {
while (ground.hitTest(fly._x, fly._y, true)) {
fly._y--;
}
while (ground.hitTest(fly._x-25, fly._y-25, true)) {
fly._x++;
xspeed = 0;
}
while (ground.hitTest(fly._x+25, fly._y-25, true)) {
fly._x--;
xspeed = 0;
}
while (ground.hitTest(fly._x, fly._y-fly._width, true)) {
fly._y++;
yspeed = 0;
}
if ((_root.ground.hitTest(fly._x, fly._y+1, true))) {
yspeed = 0;
}
xspeed *= friction;
this._x += xspeed;
rotationspeed *= friction;
this._rotation = 0+rotationspeed/2;
this._y += yspeed;
if (Key.isDown(37)) {
xspeed -= power;
rotationspeed += power*xspeed/2;
} else if (Key.isDown(39)) {
xspeed += power;
rotationspeed += power*xspeed/2;
}
if (Key.isDown(38)) {
yspeed -= power;
fly._y -= 0.2;
}
if (yspeed<0) {
yspeed *= friction;
}
yspeed += gravity;
};
Note: The in things name is "fly" and the level platforms are called
"platform" Help will be gratly appreciated
Cheers, Corey
-
Developer
Why have you made a new thread for this?
But anyway I think all you need to do is make the stage move in the opposite way to the player - this way the player will stay in the same position on the screen. That should help
-
So How Do I Do That
Um sorry but im new to flash actionscripting so cldu plz help me
Cheers, Corey
-
my x booty it is that BIG
Originally Posted by dVyper
Why have you made a new thread for this?
But anyway I think all you need to do is make the stage move in the opposite way to the player - this way the player will stay in the same position on the screen. That should help
going off on what he said have you tried
Code:
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1.1;
friction = 0.9;
fly.onEnterFrame = function() {
while (ground.hitTest(fly._x, fly._y, true)) {
fly._y--;
ground._y++;
}
while (ground.hitTest(fly._x-25, fly._y-25, true)) {
fly._x++;
ground._x--;
xspeed = 0;
}
while (ground.hitTest(fly._x+25, fly._y-25, true)) {
fly._x--;
ground._x++;
xspeed = 0;
}
while (ground.hitTest(fly._x, fly._y-fly._width, true)) {
fly._y++;
ground._y--;
yspeed = 0;
}
if ((_root.ground.hitTest(fly._x, fly._y+1, true))) {
yspeed = 0;
}
xspeed *= friction;
this._x += xspeed;
rotationspeed *= friction;
this._rotation = 0+rotationspeed/2;
this._y += yspeed;
if (Key.isDown(37)) {
xspeed -= power;
rotationspeed += power*xspeed/2;
} else if (Key.isDown(39)) {
xspeed += power;
rotationspeed += power*xspeed/2;
}
if (Key.isDown(38)) {
yspeed -= power;
fly._y -= 0.2;
}
if (yspeed<0) {
yspeed *= friction;
}
yspeed += gravity;
};
Project||[GAME]-on hold for now
------------------
[Hero]-80%
[Enemies]-1%
[Weapons]-90%
[Items]-0%
[Levels]-10%
-
Now tell me whos watchin......
hes gonna ask what ground._x does....
-
Pumpkin Carving 2008
Originally Posted by samvillian
hes gonna ask what ground._x does....
Random flaming is one thing Sam, but if you haven't got anything constructive to add to the thread, consider resisting to post flames.
OP, have you thought about trying VCam2?
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
So What Do I Do
So What Exactly Do I Do To Do The Cetre Thing?
-
dont give the MC you want "centered" any speed, it is not going to have a
._y or ._x speed, everything else has the opposite added or subtracted to their speed.
if you want him to move around a little bit but not go off screen,
put this in the move function so he will only move within a given set of perameters.
if (mc._x<=#){
mc._x += myspeed
}
myspeed would be whatever variable you have for speed. and do that for all directions so he will move in an invisible square in the screen and when he hits the edge, then everything will move in the opposite direction savvy?
-
K so do i delete all the other code?
-
I decided to stay TF away from scrolling games until I made a few games, but thats just me.
just delete the part of the code that actually moves the MC
-
So I Put The oving Code On The Bg?
Ok so i move the code tomove from the guy to the bg?
-
yes your not actually moving the guy, your moving everything else in the opposite direction.
-
-
Ive tried it but now when the guyhits the walls he goes ight through them any ideas anyway heres the code:
PHP Code:
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1.1;
friction = 0.9;
ground.onEnterFrame = function() {
while (fly.hitTest(ground._x, ground._y, true)) {
fly._y--;
}
while (fly.hitTest(ground._x-25, ground._y-25, true)) {
ground._x++;
xspeed = 0;
}
while (fly.hitTest(ground._x+25, ground._y-25, true)) {
ground._x--;
xspeed = 0;
}
while (fly.hitTest(ground._x, ground._y-ground._width, true)) {
ground._y++;
yspeed = 0;
}
if ((_root.fly.hitTest(ground._x, ground._y+1, true))) {
yspeed = 0;
}
xspeed *= friction;
this._x += xspeed;
rotationspeed *= friction;
this._rotation = 0+rotationspeed/2;
this._y += yspeed;
if (Key.isDown(37)) {
xspeed -= power;
rotationspeed += power*xspeed/2;
} else if (Key.isDown(39)) {
xspeed += power;
rotationspeed += power*xspeed/2;
}
if (Key.isDown(38)) {
yspeed -= power;
ground._y -= 0.2;
}
if (yspeed<0) {
yspeed *= friction;
}
yspeed += gravity;
};
Sue It Scrolls But The Guy Gos Straight Through The Walls.
-
the cheesy child
yea he showed me, doesn't work right...
but hey, Corey, you should try to solve the prob with what he gave u.
anyway try everything the opposite way because basically whats happening is the gravity is making u go up, not down. so switch the moving parts around!
-
I still havent figured out walls yet! LOL the only way I can do wills
is if I make 1 wall for each direction and put them togeather to make 1 wall.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|