Forum Topic: Is As3 Faster Than As2? No! Rofl!

(349 views • 21 replies)

This topic is 1 page long.

<< < > >>
Elated

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 08:06 AM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

Really. It might work faster, but AS2 saves like 3 hours per piece of code to type. I wrote a code in AS2, can ANYONE translate this code to AS3, with the exact same effect, without using more than 100 lines?
I was looking for key movement in AS3 on google, and it was really hard to find. The codes I saw didn't work at all and where like 150 lines.
So, my 20 lines of code (copy and paste into a empty AS2 document, framerate 60 fps):

var player:MovieClip=_root.createEmptyMovieC lip("player",_root.getNextHighestDepth()
); player._x=Stage.width/2;player._y=Stage.
height/2;
player.lineStyle(3,0x000000,100);
player.beginFill(0x0066FF,100);
player.moveTo(15,0);
for (var radian:Number=0;radian<=360;radian++) {player.lineTo(15*Math.cos(radian/57.2),
15*Math.sin(radian/57.2));}
player.endFill();
var virtualx:Number=Stage.width/2;
var virtualy:Number=Stage.height/2;
player.onEnterFrame = function () {
player._x+=(virtualx-player._x)/20;
player._y+=(virtualy-player._y)/20;
if (Key.isDown (Key.RIGHT)) {virtualx += 5;}
if (Key.isDown (Key.LEFT)) {virtualx -= 5;}
if (Key.isDown (Key.DOWN)) {virtualy += 5;}
if (Key.isDown (Key.UP)) {virtualy -= 5;}
if (player._x>Stage.width-(player._width/2)
) {player._x--;virtualx=player._x;}
if (player._x<player._width/2) {player._x++;virtualx=player._x;}
if (player._y>Stage.height-(player._height/
2)) {player._y--;virtualy=player._y;}
if (player._y<player._height/2) {player._y++;virtualy=player._y;}
};

Is As3 Faster Than As2? No! Rofl!

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 08:08 AM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

Allright, if you press the auto-format button, you get 44 lines. but still, this is less than 150.

var player:MovieClip = _root.createEmptyMovieClip ("player", _root.getNextHighestDepth ());
player._x = Stage.width / 2;
player._y = Stage.height / 2;
player.lineStyle (3,0x000000,100);
player.beginFill (0x0066FF,100);
player.moveTo (15,0);
for (var radian:Number = 0; radian <= 360; radian++) {
player.lineTo (15 * Math.cos (radian / 57.2),15 * Math.sin (radian / 57.2));
}
player.endFill ();
var virtualx:Number = Stage.width / 2;
var virtualy:Number = Stage.height / 2;
player.onEnterFrame = function () {
player._x += (virtualx - player._x) / 20;
player._y += (virtualy - player._y) / 20;
if (Key.isDown (Key.RIGHT)) {
virtualx += 5;
}
if (Key.isDown (Key.LEFT)) {
virtualx -= 5;
}
if (Key.isDown (Key.DOWN)) {
virtualy += 5;
}
if (Key.isDown (Key.UP)) {
virtualy -= 5;
}
if (player._x > Stage.width - (player._width / 2)) {
player._x--;
virtualx = player._x;
}
if (player._x < player._width / 2) {
player._x++;
virtualx = player._x;
}
if (player._y > Stage.height - (player._height / 2)) {
player._y--;
virtualy = player._y;
}
if (player._y < player._height / 2) {
player._y++;
virtualy = player._y;
}
};

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

Doomsday-One

Reply To Post Reply & Quote

Posted at: 7/12/09 08:22 AM

Doomsday-One EVIL LEVEL 10

Sign-Up: 10/28/05

Posts: 1,373

At 7/12/09 08:06 AM, Vexagon wrote: Really. It might work faster, but AS2 saves like 3 hours per piece of code to type.

It only saves this much time if you don't know how to code in AS3. Once you get the hang of it, AS3 doesn't take much longer to write, and may even save you time since it is better organised.
Also, with the best of games usually being so intense, and since not everyone has an 8GB hyper-computer, code which executes quickly is pretty damn important.

P.S. Your code needs work. You could shorten the number of lines by a fair amount, as well as creating code which runs faster (contrary to popular belief, these are usually unrelated in Actionscript). Also, if you hold up and left, you move more than 7 pixels per frame, meaning he travels faster; a poor design choice.

Doomsday-One, working on stuff better than preloaders.

By the way, I made the 'Create an Animated Sprite' preloader for Sprite TV 3!


None

UnknownFury

Reply To Post Reply & Quote

Posted at: 7/12/09 08:42 AM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,027

150? Where the hell are you getting that figure from? You can do this in about 50 directly porting your code over, then further reductions could be made to that...

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 08:58 AM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

P.S. Your code needs work. You could shorten the number of lines by a fair amount, as well as creating code which runs faster (contrary to popular belief, these are usually unrelated in Actionscript). Also, if you hold up and left, you move more than 7 pixels per frame, meaning he travels faster; a poor design choice.

Tell me, how can I make it run faster?
And how can I make it even shorter?
I already saw I made a mistake, I could have used "else" 4 times, wich already makes it faster and 4 lines shorter.

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 09:02 AM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

At 7/12/09 08:42 AM, UnknownFury wrote: 150? Where the hell are you getting that figure from? You can do this in about 50 directly porting your code over, then further reductions could be made to that...

Okay I found a much shorter code, but it doesn't draw a movieclip and the movement is strict. Also, it doesn't work. Can you tell me why? The code (and no I dont think this is better organized):

package com.asgamer.basics1{

import flash.display.MovieClip;
import flash.display.Stage;
import com.senocular.utils.KeyObject;
import flash.ui.Keyboard;
import flash.events.Event;

public class Ship extends MovieClip {

private var stageRef:Stage;
private var key:KeyObject;

public function Ship(stageRef:Stage)
{
this.stageRef = stageRef;
key = new KeyObject(stageRef);

addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}

public function loop(e:Event) : void
{
if (key.isDown(Keyboard.LEFT))
x -= 2;
else if (key.isDown(Keyboard.RIGHT))
x += 2;

if (key.isDown(Keyboard.UP))
y -= 2;
else if (key.isDown(Keyboard.DOWN))
y += 2;
}

}

}

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

Paranoia

Reply To Post Reply & Quote

Posted at: 7/12/09 09:43 AM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

At 7/12/09 08:58 AM, Vexagon wrote: P.S. Your code needs work. You could shorten the number of lines by a fair amount, as well as creating code which runs faster (contrary to popular belief, these are usually unrelated in Actionscript).

What, of course having shorter code is related to having faster code. Of course some commands take more processing than others, but in general having a lot of commands is going to be faster than having a smaller number of commands.

BBS Signature

None

Doomsday-One

Reply To Post Reply & Quote

Posted at: 7/12/09 10:22 AM

Doomsday-One EVIL LEVEL 10

Sign-Up: 10/28/05

Posts: 1,373

At 7/12/09 09:02 AM, Vexagon wrote: The code (and no I dont think this is better organized):

It gets better organised as you work with more complicated stuff, as well as as your code gets larger and larger.
You can make your AS2 code about as organised, but then you might as well switch to AS3 for the speed.

Oh, and to decrease lines:
virtualx += (Key.isDown(Key.RIGHT)-Key.isDown(Key.LE FT))*5
That cuts 6 lines into 1. I think that is slightly slower though, as Flash doesn't like turning true/false into 1/0.

Also, 'function onEnterFrame()' is declared faster than 'onEnterFrame = function()'. And you're better off saying 'with(player)', plus you should stop using '_root.' when you don't need to.
When you do the same calculations multiple times, that is inefficient. Do it once and save the result in a variable (eg. Stage.width - player._width/2).

There are several more things to do, too. It isn't too crucial unless you're making an intensive game, but I thought I'd bring them up considering that you were acting a tad overconfident in your coding abilities.

At 7/12/09 09:43 AM, Paranoia wrote: What, of course having shorter code is related to having faster code. Of course some commands take more processing than others, but in general having a lot of commands is going to be faster than having a smaller number of commands.

Since Flash compiles the code when it creates the .swf, no it doesn't.
I have the example above about it converting true and false values, and I talked about processing values only once. These aren't the best examples; they're rather cheap rebuttals in fact.
Either way, explaining it would just be me repeating what Glaiel said here.

Doomsday-One, working on stuff better than preloaders.

By the way, I made the 'Create an Animated Sprite' preloader for Sprite TV 3!


None

Wurmy

Reply To Post Reply & Quote

Posted at: 7/12/09 10:34 AM

Wurmy LIGHT LEVEL 28

Sign-Up: 06/20/06

Posts: 2,307

How long it takes to write code != How fast the code runs.
You're just saying that AS3 is slower than AS2 because you don't know how to write in AS3.

var UP:Boolean = false;
var DOWN:Boolean = false;
var LEFT:Boolean = false;
var RIGHT:Boolean = false;

var Player:Sprite = new Sprite();
Player.graphics.lineStyle(3, 0x000000, 1);
Player.graphics.beginFill(0x0066FF, 1);
Player.graphics.moveTo(15, 0);
for (var Rad:int = 0; Rad < 360; Rad++) Player.graphics.lineTo(15 * Math.cos(Rad / 57.2), 15 * Math.sin(Rad / 57.2));
Player.graphics.endFill();
addChild(Player);

Player.x = 275;
Player.y = 200;

var SpeedX:Number = 0;
var SpeedY:Number = 0;

const MaxSpeed:Number = 10;

addEventListener(Event.ENTER_FRAME, Tick, false, 0, true);
function Tick(e:Event):void {
	
	if (UP) SpeedY = EaseTo(SpeedY, -MaxSpeed);
	else if (DOWN) SpeedY = EaseTo(SpeedY, MaxSpeed);
	else SpeedY = EaseTo(SpeedY, 0);
	if (LEFT) SpeedX = EaseTo(SpeedX, -MaxSpeed);
	else if (RIGHT) SpeedX = EaseTo(SpeedX, MaxSpeed);
	else SpeedX = EaseTo(SpeedX, 0);
	
	if (Player.x < 0) SpeedX = 5;
	if (Player.x > 550) SpeedX = -5;
	if (Player.y < 0) SpeedY = 5;
	if (Player.y > 400) SpeedY = -5;
	
	Player.x += SpeedX;
	Player.y += SpeedY;
	
}

function EaseTo(From:Number, To:Number):Number {
	if (Math.abs(From - To) < 0.5) return To;
	
	var Speed:Number = From + (To - From) / 10;
	return Speed;
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyUp, false, 0, true);


function KeyDown(e:KeyboardEvent):void {
	switch (e.keyCode) {
		case 38: UP = true; break;
		case 40: DOWN = true; break;
		case 37: LEFT = true; break;
		case 39: RIGHT = true; break;
	}
}
function KeyUp(e:KeyboardEvent):void {
	switch (e.keyCode) {
		case 38: UP = false; break;
		case 40: DOWN = false; break;
		case 37: LEFT = false; break;
		case 39: RIGHT = false; break;
	}
}

There's one way to do it in AS3. A total of 69 lines (54 if you remove all the white space). I like to think that although this is more lines (bohoo) it is more flexible than your code.

BBS Signature

Elated

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 11:25 AM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

Okay, but it's "bouncing" when you're trying to go out the stage. Also, if you remove the spaces and press the auto-format button, you got 90 lines. But still, very good!

And I think I'm going to learn AS3. At first it seems a lot more complicated, becouse there is a lot more linkage in the codes. But, if it really works faster, I have no choice becouse my shooter game is running slow with the shotgun ]=

I'm sorry, becouse yes, I did think i was a good programmer. But eventually, I still have improve on a lot of things. Though I have the time, I'm only 14 yet [=

Thanks for all your help, I'm going to pick up AS3!

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

Doomsday-One

Reply To Post Reply & Quote

Posted at: 7/12/09 11:34 AM

Doomsday-One EVIL LEVEL 10

Sign-Up: 10/28/05

Posts: 1,373

At 7/12/09 11:25 AM, Vexagon wrote: I have no choice becouse my shooter game is running slow with the shotgun ]=

Look up 'cacheAsBitmap'. Too many calculations can slow down games, but graphics contribute so much more.
This may be a solution to your problem.

Doomsday-One, working on stuff better than preloaders.

By the way, I made the 'Create an Animated Sprite' preloader for Sprite TV 3!


None

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 11:58 AM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

At 7/12/09 11:34 AM, Doomsday-One wrote:
At 7/12/09 11:25 AM, Vexagon wrote: I have no choice becouse my shooter game is running slow with the shotgun ]=
Look up 'cacheAsBitmap'. Too many calculations can slow down games, but graphics contribute so much more.
This may be a solution to your problem.

Thanks! It runs smoothly now! Is it faster (in as2) to code everything on the main timeline than coding in movieclips and on the main timeline?

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

Doomsday-One

Reply To Post Reply & Quote

Posted at: 7/12/09 12:22 PM

Doomsday-One EVIL LEVEL 10

Sign-Up: 10/28/05

Posts: 1,373

At 7/12/09 11:58 AM, Vexagon wrote: Thanks! It runs smoothly now! Is it faster (in as2) to code everything on the main timeline than coding in movieclips and on the main timeline?

No, but the first option is preferred. It keeps everything in one place, so you don't have to go running about looking for it.
Also, it prepares you for AS3 and other languages, in which that is the only option.

Doomsday-One, working on stuff better than preloaders.

By the way, I made the 'Create an Animated Sprite' preloader for Sprite TV 3!


None

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 12:37 PM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

Ok, good to know. I also found out that it is faster to convert the lines to fills.
Are there other things I need to know?

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

Beaten

zuperxtreme

Reply To Post Reply & Quote

Posted at: 7/12/09 12:41 PM

zuperxtreme NEUTRAL LEVEL 08

Sign-Up: 01/02/05

Posts: 1,626

Thankfully modern PC's have more than 10KB of RAM.


None

Rustygames

Reply To Post Reply & Quote

Posted at: 7/12/09 01:57 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,661

We don't all just use AS3 to code some shitty maze game, if you actualy starting building a large project you'll very quickly see that you're writing less lines in AS3 than you would be in AS2, not that it matters either way, it's the maintainability, reusability and of course speed of execution that are the most important factors.

- Matt, Rustyarcade.com


None

Calipe

Reply To Post Reply & Quote

Posted at: 7/12/09 05:44 PM

Calipe LIGHT LEVEL 30

Sign-Up: 02/28/04

Posts: 448

At 7/12/09 01:57 PM, Rustygames wrote: We don't all just use AS3 to code some shitty maze game, if you actualy starting building a large project you'll very quickly see that you're writing less lines in AS3 than you would be in AS2, not that it matters either way, it's the maintainability, reusability and of course speed of execution that are the most important factors.

In summary, ActionScript 3.0 is all about Object Oriented Programming. Like Rustygames said, maintainability is where OOP languages shine on, not to mention that most modern programming languages are designed with OOP in mind.
If you learn AS3, you will open the doors to other languages such as Java and C++..


Elated

Vexagon

Reply To Post Reply & Quote

Posted at: 7/12/09 07:23 PM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

At 7/12/09 10:34 AM, Wurmy wrote: How long it takes to write code != How fast the code runs.
You're just saying that AS3 is slower than AS2 because you don't know how to write in AS3.

var UP:Boolean = false;
var DOWN:Boolean = false;
var LEFT:Boolean = false;
var RIGHT:Boolean = false;

var Player:Sprite = new Sprite();
Player.graphics.lineStyle(3, 0x000000, 1);
Player.graphics.beginFill(0x0066FF, 1);
Player.graphics.moveTo(15, 0);
for (var Rad:int = 0; Rad < 360; Rad++) Player.graphics.lineTo(15 * Math.cos(Rad / 57.2), 15 * Math.sin(Rad / 57.2));
Player.graphics.endFill();
addChild(Player);

Player.x = 275;
Player.y = 200;

var SpeedX:Number = 0;
var SpeedY:Number = 0;

const MaxSpeed:Number = 10;

addEventListener(Event.ENTER_FRAME, Tick, false, 0, true);
function Tick(e:Event):void {

if (UP) SpeedY = EaseTo(SpeedY, -MaxSpeed);
else if (DOWN) SpeedY = EaseTo(SpeedY, MaxSpeed);
else SpeedY = EaseTo(SpeedY, 0);
if (LEFT) SpeedX = EaseTo(SpeedX, -MaxSpeed);
else if (RIGHT) SpeedX = EaseTo(SpeedX, MaxSpeed);
else SpeedX = EaseTo(SpeedX, 0);

if (Player.x < 0) SpeedX = 5;
if (Player.x > 550) SpeedX = -5;
if (Player.y < 0) SpeedY = 5;
if (Player.y > 400) SpeedY = -5;

Player.x += SpeedX;
Player.y += SpeedY;

}

function EaseTo(From:Number, To:Number):Number {
if (Math.abs(From - To) < 0.5) return To;

var Speed:Number = From + (To - From) / 10;
return Speed;
}

stage.addEventListener(KeyboardEvent.KEY _DOWN, KeyDown, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY _UP, KeyUp, false, 0, true);


function KeyDown(e:KeyboardEvent):void {
switch (e.keyCode) {
case 38: UP = true; break;
case 40: DOWN = true; break;
case 37: LEFT = true; break;
case 39: RIGHT = true; break;
}
}
function KeyUp(e:KeyboardEvent):void {
switch (e.keyCode) {
case 38: UP = false; break;
case 40: DOWN = false; break;
case 37: LEFT = false; break;
case 39: RIGHT = false; break;
}
}

There's one way to do it in AS3. A total of 69 lines (54 if you remove all the white space). I like to think that although this is more lines (bohoo) it is more flexible than your code.

I'm sorry to say this, but I just wrote my VERY VERY first AS3 code EVER, and its 68 lines.
Thats 22 lines less than yours (you didn't press the auto-format button yet). And you can even use the mouse to move! I'm just glad I'm picking up AS3 so fast, I mean, I found out how about the mousemove all by myself in 3 minuites. Can I be proud of my first code?

var Vexagon:Sprite=new Sprite();
Vexagon.graphics.lineStyle (3,0x000000,100);
Vexagon.graphics.beginFill (0x0066FF,100);
Vexagon.graphics.moveTo (10,0);
for (var gr:int=0; gr<=360; gr+=60) {
Vexagon.graphics.lineTo (10*Math.cos(gr/57.2),10*Math.sin(gr/57.
2));
}
addChild (Vexagon);
Vexagon.x=500;
Vexagon.y=250;
var VirtualX:Number=Vexagon.x;
var VirtualY:Number=Vexagon.y;
var MovingLeft:Boolean=false;
var MovingRight:Boolean=false;
var MovingUp:Boolean=false;
var MovingDown:Boolean=false;
addEventListener (Event.ENTER_FRAME,herhaal,false,0,true)
;
stage.addEventListener (KeyboardEvent.KEY_DOWN,IsMoving,false,0 ,true);
stage.addEventListener (KeyboardEvent.KEY_UP,IsNotMoving,false,
0,true);
stage.addEventListener (MouseEvent.MOUSE_MOVE,FollowMouse,false ,0,true);
function herhaal (e:Event):void {
Vexagon.x += (VirtualX-Vexagon.x)/20;
Vexagon.y += (VirtualY-Vexagon.y)/20;
if (MovingLeft==true) {
VirtualX-=5;
} else if (MovingRight==true) {
VirtualX+=5;
}
if (MovingUp==true) {
VirtualY-=5;
} else if (MovingDown==true) {
VirtualY+=5;
}
}
function IsMoving (e:KeyboardEvent):void {
switch (e.keyCode) {
case 65 :
MovingLeft=true;
break;
case 68 :
MovingRight=true;
break;
case 87 :
MovingUp=true;
break;
case 83 :
MovingDown=true;
}
}
function IsNotMoving (e:KeyboardEvent):void {
switch (e.keyCode) {
case 65 :
MovingLeft=false;
break;
case 68 :
MovingRight=false;
break;
case 87 :
MovingUp=false;
break;
case 83 :
MovingDown=false;
}
}
function FollowMouse (e:MouseEvent):void {
VirtualX=mouseX;
VirtualY=mouseY;
}

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

knugen

Reply To Post Reply & Quote

Posted at: 7/12/09 07:33 PM

knugen LIGHT LEVEL 35

Sign-Up: 02/07/05

Posts: 4,686

You basically copied his code, but made it less dynamic. Stop being so obsessed with line count, read the two posts above your last one.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/12/09 07:56 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,541

At 7/12/09 07:23 PM, Vexagon wrote: stuff

I could easily cut that down to 30 lines, it doesn't mean shit. It just means you're spending time trying to make the code shorter, for no point.


Mad as Hell

Vexagon

Reply To Post Reply & Quote

Posted at: 7/13/09 05:56 AM

Vexagon LIGHT LEVEL 11

Sign-Up: 02/11/09

Posts: 241

At 7/12/09 07:33 PM, knugen wrote: You basically copied his code, but made it less dynamic. Stop being so obsessed with line count, read the two posts above your last one.

Yeah I know it doesn't run faster, I just prefer my codes to be as compact as possible. !keep the script scrollbar as big as possible!
Anyway, What the f*ck makes you think I copied his code? 1. Would I learn to use AS3.0 by copying codes? 2. My structure is different, I made it look like my own old code. 3. And I found out how you can make something follow your mouse, I could never have discovered how if I really copied that code.

if (script == "ActionScript 3.0") {
return happyFace;
}

BBS Signature

None

knugen

Reply To Post Reply & Quote

Posted at: 7/13/09 06:20 AM

knugen LIGHT LEVEL 35

Sign-Up: 02/07/05

Posts: 4,686

At 7/13/09 05:56 AM, Vexagon wrote:
At 7/12/09 07:33 PM, knugen wrote: You basically copied his code, but made it less dynamic. Stop being so obsessed with line count, read the two posts above your last one.
Yeah I know it doesn't run faster, I just prefer my codes to be as compact as possible. !keep the script scrollbar as big as possible!

Less lines with little or none impact on efficiency is always preferred, but making it your primary goal to produce code with as few lines as possible will you do you more harm than good.

Anyway, What the f*ck makes you think I copied his code?

Let's see..

var Player:Sprite = new Sprite();
Player.graphics.lineStyle(3, 0x000000, 1);
Player.graphics.beginFill(0x0066FF, 1);
Player.graphics.moveTo(15, 0);
for (var Rad:int = 0; Rad < 360; Rad++) Player.graphics.lineTo(15 * Math.cos(Rad / 57.2), 15 * Math.sin(Rad / 57.2));
Player.graphics.endFill();
addChild(Player);

Player.x = 275;
Player.y = 200;

Became:

var Vexagon:Sprite=new Sprite();
Vexagon.graphics.lineStyle (3,0x000000,100);
Vexagon.graphics.beginFill (0x0066FF,100);
Vexagon.graphics.moveTo (10,0);
for (var gr:int=0; gr<=360; gr+=60) {
Vexagon.graphics.lineTo (10*Math.cos(gr/57.2),10*Math.sin(gr/57.2));
}
addChild (Vexagon);
Vexagon.x=500;
Vexagon.y=250;

---

var UP:Boolean = false;
var DOWN:Boolean = false;
var LEFT:Boolean = false;
var RIGHT:Boolean = false;

Became:

var MovingLeft:Boolean=false;
var MovingRight:Boolean=false;
var MovingUp:Boolean=false;
var MovingDown:Boolean=false;

---

function KeyDown(e:KeyboardEvent):void {
switch (e.keyCode) {
case 38: UP = true; break;
case 40: DOWN = true; break;
case 37: LEFT = true; break;
case 39: RIGHT = true; break;
}
}
function KeyUp(e:KeyboardEvent):void {
switch (e.keyCode) {
case 38: UP = false; break;
case 40: DOWN = false; break;
case 37: LEFT = false; break;
case 39: RIGHT = false; break;
}
}

Became:

function IsMoving (e:KeyboardEvent):void {
switch (e.keyCode) {
case 65 :
MovingLeft=true;
break;
case 68 :
MovingRight=true;
break;
case 87 :
MovingUp=true;
break;
case 83 :
MovingDown=true;
}
}
function IsNotMoving (e:KeyboardEvent):void {
switch (e.keyCode) {
case 65 :
MovingLeft=false;
break;
case 68 :
MovingRight=false;
break;
case 87 :
MovingUp=false;
break;
case 83 :
MovingDown=false;
}
}

With your line count obsession you can probably calculate how much of "your" code is pretty much exactly like the one given to you above, my guess would be 60-70%. Case closed?

1. Would I learn to use AS3.0 by copying codes?

Probably not?

2. My structure is different, I made it look like my own old code.

The structure is basically the same, only slightly n00bified.

3. And I found out how you can make something follow your mouse, I could never have discovered how if I really copied that code.

I said that you basically copied it, that's pretty much fact (see above). You added a few lines of your own code and changed a couple of names for functions and variables, that does still fall under the "basically copied" description, don't you think? Also note that I never said you can't code for yourself, I only point out the obvious.


All times are Eastern Standard Time (GMT -5) | Current Time: 05:53 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!