Flash

C++, C#, Java, PHP, ect...
Post Reply
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post 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! :D

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);
}
}
Image

Image
User avatar
Agent
Posts: 164
Joined: Tue Jul 14, 2009 5:22 am

Re: Flash

Post 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?
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post 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.
Image

Image
User avatar
Agent
Posts: 164
Joined: Tue Jul 14, 2009 5:22 am

Re: Flash

Post 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.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post 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
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post 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.
Image

Image
User avatar
neronix17
Posts: 317
Joined: Sat Aug 01, 2009 5:01 am

Re: Flash

Post 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 :lol:
This isnt just a gimp mask...This is an S&M gimp mask...
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post 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 :lol:

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!!
Image

Image
User avatar
neronix17
Posts: 317
Joined: Sat Aug 01, 2009 5:01 am

Re: Flash

Post 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);
}
This isnt just a gimp mask...This is an S&M gimp mask...
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post 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;
}
}
}
Image

Image
Post Reply

Return to “Coding”