Page 7 of 13
Re: Flash
Posted: Tue Aug 04, 2009 4:29 am
by SpiritWebb
Agent wrote:SpiritWebb wrote:
You could get your positions last known position in a few ways i guess - but a smart - less process active way could be that on pressing the logout or save button / whatever - the engine executes a command to get the ships position and translate that over to a php variable which THEN externally saves out to a database. Then the same process back - when the play logs in the flash file searches for the locally stored player variable .php file and automatically asks for the x and y pos of the ship (when last saved) then translates that over. So something like this could be used-
getXPos = this._x;
getYPos = this._y;
where then for example -
$playerXPos = getXPos;
$playerYPos = getYPos;
and to set the ships position back on login -
this._x = $playerXPos; // or getXPos
this._y = $playerYPos; // or getYPos
See how you go with that...
Is this the correct way? Sorry if I sound annoying on this, I just want to make sure I get it right!
Code: Select all
///PHP Code///
<?
$playerXPos = getXPos;
$playerYPos = getYPos;
echo "myfirst=$playerXPos&mysecond=$playerYPos;
exit;
?>
///Flash Actionscript:///
var lvSend = new LoadVars();
var lvReceive = new LoadVars();
lvSend.SendAndLoad("localhost/game/save.php",lvReceive,"POST");
lvReceive.onLoad = function(bSuccess) {
if(bSuccess == true) {
trace(this.myfirst);
trace(this.mysecond);
}
}
Re: Flash
Posted: Tue Aug 04, 2009 6:43 am
by Agent
Well it looks good, although i don't exactly understand it considering i don't know what variables your moving around there. But i think you are on the right track.
So as long as the actionscript / php scripts execute every time you load and save / exit to send out / obtain player position info as well as all other stats and variables it should be fine.
Does it work? have you tried?
Re: Flash
Posted: Tue Aug 04, 2009 6:46 am
by SpiritWebb
No, I haven't tried, I found that script online, and plugged in the information you provided. As I do not know how to set this all up...that I am still trying to figure out. I was at work when I posted that code. Im at home now.
Re: Flash
Posted: Tue Aug 04, 2009 6:50 am
by Agent
Okay no problem - just remember that you have constantly be interchanging the variables from your php / database into the flash file - with xp updates etc. So you really need to design a solid server - client system.
Let me know how things go. I will be curious to see.
Re: Flash
Posted: Tue Aug 04, 2009 7:00 am
by SpiritWebb
neronix17 wrote:SpiritWebb wrote:neronix:
SpiritWebb wrote:lol...its cool.
I got it all to show, but now my map is all over the place...it places the map down on the far left, not centered...
what size should the map be? The map is centered to the ship, on its right border.
EDIT: When I press the down key and left or right, it quits moving...only up seems to work. I aim down, the map scrolls right. Aim right, map goes up, aim up, map goes left, aim left map goes down.
Any ideas on how i can fix this?
If whats happened is what i think has then first when you make the map make sure its at 2000x2000, thats what my ones set to. The second problem i think would be the direction your ship is facing when you made the symbol, make sure it is facing towards the left and that should make it move properly, the problem with reversing is that my one didnt have that so Il go see if i can get it to do that for you just now
I tried re-doing it, and when it I face North, it acts as if I'm going W. I am attaching my file that I am working on. Maybe you can see what I'm doing wrong? Though the reverse worked, thanks for that. Now if I can only get the rest too work...lol
You might have to right click > save target as:
Ship_Problem.fla <--this is the file
Re: Flash
Posted: Tue Aug 04, 2009 7:01 am
by SpiritWebb
Agent wrote:Okay no problem - just remember that you have constantly be interchanging the variables from your php / database into the flash file - with xp updates etc. So you really need to design a solid server - client system.
Let me know how things go. I will be curious to see.
Thats the thing, its going to be ALL browser based...so I dont understand the server/client part. I hear server/client - server runs game, client connects showing the game.
Re: Flash
Posted: Tue Aug 04, 2009 7:39 am
by neronix17
SpiritWebb wrote:
I tried re-doing it, and when it I face North, it acts as if I'm going W. I am attaching my file that I am working on. Maybe you can see what I'm doing wrong? Though the reverse worked, thanks for that. Now if I can only get the rest too work...lol
You might have to right click > save target as:
Ship_Problem.fla <--this is the file
Ive had a look and I honestly see nothing wrong with it, Il have a look and see if I can fix it though, could take a minute, I might have to go install Flash MX 2004 and make it for you

Re: Flash
Posted: Tue Aug 04, 2009 7:44 am
by SpiritWebb
neronix17 wrote:SpiritWebb wrote:
I tried re-doing it, and when it I face North, it acts as if I'm going W. I am attaching my file that I am working on. Maybe you can see what I'm doing wrong? Though the reverse worked, thanks for that. Now if I can only get the rest too work...lol
You might have to right click > save target as:
Ship_Problem.fla <--this is the file
Ive had a look and I honestly see nothing wrong with it, Il have a look and see if I can fix it though, could take a minute, I might have to go install Flash MX 2004 and make it for you

Thats cool, I really appreciate it...in the meantime though, I did figure out how to use the mouse. Click and ship moves. Now if only the background moved with the mouse click rather then the keyboard, then I would have to go to the bathroom, haha!!
Re: Flash
Posted: Tue Aug 04, 2009 7:54 am
by neronix17
lol, well, i still havent figured out the problem but i seem to have fixed it, just delete the code you had and copy and paste this into it
Code: Select all
/*Setup*/
var maxspeed:Number = 4;
var startAngle:Number = 0;
var steeringFriction:Number = .50;
var groundFriction:Number = .98;
var speed:Number = 0;
var steering:Number = 0;
var moveX:Number = 0;
var moveY:Number = 0;
var radiance:Number = ((startAngle-90)/180)*Math.PI;
//
/* Create Map */
var map_mc:MovieClip = this.attachMovie("map_mc","map_mc",this.getNextHighestDepth());
map_mc._x = 0
map_mc._y = 0
//
/* Create Player */
var player_ship_mc:MovieClip = this.attachMovie("player_ship_mc","player_ship_mc",this.getNextHighestDepth());
player_ship_mc._x = Stage.width/2;
player_ship_mc._y = Stage.height/2;
//
/* Main Game Loop */
player_ship_mc.onEnterFrame = function() {
run();
};
function run():Void {
if (speed<0) {
speed = 0;
}
// left
if (Key.isDown(Key.LEFT)) {
steering -= 0.2;
}
// right
if (Key.isDown(Key.RIGHT)) {
steering += 0.2;
}
// maxsteering
if (steering > 1.5){
steering = 1.5;
}
if (steering < -1.5){
steering = -1.5;
}
// accelerate
if (Key.isDown(Key.UP) && speed<maxspeed) {
speed += 0.5;
}
// brake
if (Key.isDown(Key.DOWN)) {
speed += -1.75;
}
// friction
speed *= groundFriction;
// ideal changes
var idealXMovement = speed*Math.cos(radiance);
var idealYMovement = speed*Math.sin(radiance);
// real change
moveX += ((idealXMovement-moveX)*steeringFriction);
moveY += ((idealYMovement-moveY)*steeringFriction);
// update
//trace("moveX "+moveX);
//trace("moveY "+moveY);
map_mc._x += moveX;
map_mc._y += moveY;
// rotate
radiance += (steering*speed)*.025;
player_ship_mc._rotation = radiance*180/Math.PI;
steering -= (steering*0.1);
}
Re: Flash
Posted: Tue Aug 04, 2009 7:57 am
by SpiritWebb
Whatever you did, it fixed it!! Thank you.
Now, with that code, what code can be replaced with below, for the mouse click movement?
Code: Select all
onClipEvent (load) {
rad = 0.0174532925199433;
speed = 5;
moving = false;
}
onClipEvent (mouseDown) {
moving = true;
m = {x:_parent._xmouse, y:_parent._ymouse};
}
onClipEvent (enterFrame) {
if (moving) {
mcx = _x-m.x;
mcy = _y-m.y;
_rotation = -Math.atan2(mcx, mcy)/rad;
mr = _rotation*rad;
if (Math.sqrt((mcx*mcx)+((mcy)*(mcy)))>speed) {
_y -= speed*Math.cos(mr);
_x -= -(speed*Math.sin(mr));
} else {
_x = m.x;
_y = m.y;
moving = false;
}
}
}