Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-18-2012, 07:13 PM   #1
Grimpo
Registered User
 
Join Date: May 2012
Posts: 6
Default [AS2] How can I change my characters coordinates?

Ok, so for my class I have decided to make a game in flash, but i'm not used to flash code.
This is what I have so far, but i'm trying to make it so once the character makes it to the opposite side of the screen, or once his x coordinate is more than 500, his x coordinate gets reset to 0, so he like warps back. I need help, Thanks.

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP))
{
_y -= 10;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN))
{
_y -= -10;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT))
{
_x -= 10;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT))
{
_x -= -10;
}
}

onClipEvent (enterFrame)
{
if (player._x >= 550)
{
player._x == 0;
}
}
Grimpo is offline   Reply With Quote
Old 05-18-2012, 07:23 PM   #2
Grimpo
Registered User
 
Join Date: May 2012
Posts: 6
Default How can I change my characters coordinates?

I need help so that once the player makes it to the side of the screen, he like warps back to the left... Thanks


onClipEvent (enterFrame) {
if (Key.isDown(Key.UP))
{
_y -= 10;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN))
{
_y -= -10;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT))
{
_x -= 10;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT))
{
_x -= -10;
}
}

onClipEvent (enterFrame)
{
if (player._x >= 550)
{
player._x == 0;
}
}
Grimpo is offline   Reply With Quote
Old 05-18-2012, 07:50 PM   #3
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

Single equal sign:

ActionScript Code:
player._x = 0;

= sets the right-side's value to the left-side variable
== checks if right-side is equals to left-side

and useful Flash tips, don't add a new onEnterFrame loop for each movement, have all the code under one single loop
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 05-18-2012, 07:51 PM   #4
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

Please refrain from double-posting, thanks
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 05-21-2012, 07:08 PM   #5
Grimpo
Registered User
 
Join Date: May 2012
Posts: 6
Default

Ok, it didn't work though, I was wondering if i could use the _moveTo script? how could i do that?
Grimpo is offline   Reply With Quote
Old 07-10-2012, 07:31 PM   #6
DRizzle
Registered User
 
Join Date: Jul 2012
Posts: 16
Default Screen Warp Thingy

I think that _moveTo is only for the drawing functions, such as drawing lines, shapes and whatnot. What I would do is:
ActionScript Code:
onClipEvent(enterFrame){      if(Key.isDown(Key.LEFT)){           this._x-=5;//or whatever your speed is      }      if(Key.isDown(Key.RIGHT)){           this._x+=5;//or whatever your speed is      }      if(Key.isDown(Key.UP)){           this._y-=5;//or whatever your speed is      }      if(Key.isDown(Key.DOWN)){           this._y+=5;//or whatever your speed is      }      if(this._x>=Stage.width+this._width){           this._x=0;      } }

I think that should work (I have flash on a different computer so I can't test it right now).
I hope that solved your problem.
DRizzle is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:39 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.