|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Need help starting out in Flash CS3
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#11 (permalink) | |||||||||||||
|
PC Gamer
|
Click on the frame symbol on the timeline to be able to write the code. Don't select the box.
__________________
[CS:S Gun Game (ADMIN)] [My CPU-Z] [FAQ - How to make a portable USB charger] [OCN Wallpapers] [OCN Wallpapers 2] [OCN Wallpapers 3]
|
|||||||||||||
|
|
|
|
#12 (permalink) | |||||||||||||
|
Commodore 64
|
So if I have a Movie Clip symbol "Ball" with instance "Ballstance" for example, how would I control movement of "Ball" with the arrow keys?
I would guess using a command to draw "ball" at coordinates "x,y", when Key.LEFT is pressed X=X-1 (not sure how to format it for AS3?), Key.Right is pressed than X=X+1, and so on (Up+Down edit Y) Code:
//(Taken from an online tutorial)
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)){
_x-=3;
}
if (Key.isDown(Key.RIGHT)){
_x+=3;
}
}
__________________
|
|||||||||||||
|
|
|
|
#13 (permalink) | |||||||||
|
Chiefly Ignorant
|
Quote:
Code:
var keyMap:Object = new Object();
var PIXELS_PER_SECOND:int = 200;
var PIXELS_PER_FRAME:Number = PIXELS_PER_SECOND / stage.frameRate;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyWasPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyWasReleased);
stage.addEventListener(Event.ENTER_FRAME, frameWasEntered);
function keyWasPressed(evt:KeyboardEvent): void
{
keyMap[evt.keyCode] = true;
}
function keyWasReleased(evt:KeyboardEvent): void
{
keyMap[evt.keyCode] = false;
}
function frameWasEntered(evt:Event): void
{
if(keyMap[Keyboard.LEFT])
Ballstance.x -= PIXELS_PER_FRAME;
if(keyMap[Keyboard.RIGHT])
Ballstance.x += PIXELS_PER_FRAME;
if(keyMap[Keyboard.UP])
Ballstance.y -= PIXELS_PER_FRAME;
if(keyMap[Keyboard.DOWN])
Ballstance.y += PIXELS_PER_FRAME;
}
For consistency, I suggest you name your Library symbols "LikeThisHere" and your instances "likeThisHere", so you can tell them apart at a glance.
__________________
|
|||||||||
|
|
|
|
#14 (permalink) | |||||||||||||
|
Commodore 64
|
Code:
var keyMap:Object = new Object(); var PIXELS_PER_SECOND:int = 200; var PIXELS_PER_FRAME:Number = PIXELS_PER_SECOND / stage.frameRate; Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyWasPressed); stage.addEventListener(KeyboardEvent.KEY_UP, keyWasReleased); stage.addEventListener(Event.ENTER_FRAME, frameWasEntered); ![]() Code:
function keyWasPressed(evt:KeyboardEvent): void
{
keyMap[evt.keyCode] = true;
}
function keyWasReleased(evt:KeyboardEvent): void
{
keyMap[evt.keyCode] = false;
}
Code:
function frameWasEntered(evt:Event): void
{
if(keyMap[Keyboard.LEFT])
INSTANCE.x -= PIXELS_PER_FRAME;
if(keyMap[Keyboard.RIGHT])
INSTANCE.x += PIXELS_PER_FRAME;
if(keyMap[Keyboard.UP])
INSTANCE.y -= PIXELS_PER_FRAME;
if(keyMap[Keyboard.DOWN])
INSTANCE.y += PIXELS_PER_FRAME;
}
so... the Instance (x or y) is (decreasing/increasing) at speed of PIXELS_PER_FRAME so if I wanted to move "cube" up 5, I would go: if argument is true blahblahblah cube.y += 5 correct?
__________________
|
|||||||||||||
|
|
|
|
#15 (permalink) | ||||||||||||
|
Chiefly Ignorant
|
Quote:
Quote:
AS2 has a function for querying whether or not a specific key is down, but this was removed in AS3 in favor of a more strict event model. Quote:
Quote:
The other way around. 0,0 is the upper left hand corner. So X increases to the right, and Y increases to the bottom. Subtract 5 to go up.
__________________
|
||||||||||||
|
|
|
|
#16 (permalink) | ||||||||||||||
|
Commodore 64
|
Quote:
repeat K=34 //repeats until K=34 getKey>K //stores value returned by getKey as variable K End //end of loop, returns to beginning of loop if K =/= 34 I was just saying INSTANCE because it didn't have to be a specific instance, it could be my tank instance or ball or whatever. oh yeah, I forgot that computers started at the top right ![]()
__________________
|
||||||||||||||
|
|
|
|
#17 (permalink) | ||||||||||
|
Chiefly Ignorant
|
Quote:
Quote:
Code:
var playerMC:MovieClip;
var playerSpeed:Number;
function setPlayer(clip:MovieClip, speed:Number): void
{
playerMC = clip;
playerSpeed = speed / stage.frameRate;
}
You mean upper left. There's nothing to say a graphical framework couldn't use a different corner as 0,0, or swap direction of the axes. The orientation of the Cartesian system is pretty arbitrary, but yeah, upper left is common. I suppose it's because we write that way in western languages.
__________________
|
||||||||||
|
|
|
|
#18 (permalink) | ||||||||||||
|
Intel Overclocker
|
Always check the webmonkey. (beginner flash tutorial)
|
||||||||||||
|
|
|
|
#19 (permalink) | |||||||||||||
|
Commodore 64
|
double
, I meant upper leftthanks diagnosis, I'll check that out
__________________
|
|||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|