The web site for Flash ActionScript 3.0 game developers

 
         
   

ActionScript 3.0 Game Programming

Mouse pass through

I have a button on one layer of my stage, and I have a semi-transparent rectangle over top of the whole stage to simulate darkness at certain times.

The problem is that the rectangle receives the mouse clicks rather than passing them through to the button on the layer below.

Is there a way to tell the rectangle or layer that it should pass through all mouse events?

I have seen this called a "glass pane" in other languages.

Thanks!

Ken

XML Motion?

Hi,

How do I use XML motion from within ActionScript?

I want to draw some complex motion paths in Flash, and then export them to XML files, and then apply the motion path to an arbitrary movie or sprite.

I can't find anything in the book about this (I am not all the way through the book yet, but I can't see anything in the index on this topic).

Thanks,

Ken

The "this" keyword

Hi, I'm having trouble with the "this" keyword. I'm trying to make a similar animation as Animationtest.fla. However everytime I use the "this" keyword i get an compiler error:

1042 The this keyword can not be used in static methods. It can only be used in instance methods, function closures, and global code.

I use "this" inside a public function, in a public class similar as in AnimationObject.as but i can not figure out why I cant get it to work.

Please help!

visual allignment and keyboard control

hi Gary,

using the code from your book to control something on the stage with the keyboard.

wondering (in this case the MovieClip is an arrow) I'd like to get the arrow head
pointing in the direction of the arrow I push.

is that possible within the context of your existing code?

or do I have to rewrite it?

thank you!

~swearingen

--------HERE'S THE CODE---------

package {
import flash.display.*;
import flash.text.*;
import flash.events.*;

public class KB_Control extends MovieClip {
public function KB_Control() {

//from keyboard
// initialize arrow variables
var leftArrow:Boolean = false;
var rightArrow:Boolean = false;
var upArrow:Boolean = false;
var downArrow:Boolean = false;

// set event listeners
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedUp);
stage.addEventListener(Event.ENTER_FRAME, movePlayer);

// set arrow variables to true
function keyPressedDown(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = true;
} else if (event.keyCode == 39) {
rightArrow = true;
} else if (event.keyCode == 38) {
upArrow = true;
} else if (event.keyCode == 40) {
downArrow = true;
}
}

// set arrow variables to false
function keyPressedUp(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = false;
} else if (event.keyCode == 39) {
rightArrow = false;
} else if (event.keyCode == 38) {
upArrow = false;
} else if (event.keyCode == 40) {
downArrow = false;
}
}

// move every frame
function movePlayer(event:Event) {
var speed:Number = 5;

if (leftArrow) {
player.x -= speed;
}
if (rightArrow) {
player.x += speed;
}
if (upArrow) {
player.y -= speed;
}
if (downArrow) {
player.y += speed;
}
}

}
}

}

Chapter Five Page 159

If we were to specify the speed in pixels per microsecond instead of pixels per second, we can then dispense with the division by 1000. Then instead of the following code to update position:

this.x += speedX * timePassed / 1000;
this.y += speedY * timePassed / 1000;

it would become:

this.x += speedX * timePassed;
this.y += speedY * timePassed;

So we have shaved off two divisons by 1000. I know this would not make any noticeable performance improvement unless you happened to be processing thousands of objects, but I thought I would mention it anyway!

(OrangeSandwch is a novice Actionscripter/Game Programmer)

Edits in the Platform Game

Gary,

Inspired by several games I recently played online, specifically Knytt Stories, and the knowledge/ examples in your new great book, I've decided to develop a Flash-based platform game. Since I'm not entirely new to Actionscript coding, I'm sure I can do it.

Taking your demo game, I've been able to tighten up the physics a little and even add a double-jump to my hero.

I just have one question as I'm still working on learning AS3. In your demo, the character may jump up through the platforms then rest upon them when gravity has done its thing.

What would I have to change in the code if I want to make it so the wall/floor tiles are solid and the character can't jump through them.

Thanks for the hint.

www.UproarMultimedia.com
Greg Gunther

hitTest help...

Hello Folks,

I'm a jr. high teacher (not a programmer, so please understand my idiocy).

Working on a maze game...eventually for multiplication drills.

I have a bee that will go through a maze.

    So far:

  • I have the maze and the bee as their own MovieClips.
  • I have the bee controllable via the keyboard (with arrows).
  • I have collisions detected on the screen (when the bee touches the maze).

What I want is to immobilize the bee if it touches the maze.

But...I'm stuck.

Any help would be greatly appreciated!

Here is the code I have so far:


addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event) {
//from keyboard
// initialize arrow variables
var leftArrow:Boolean = false;
var rightArrow:Boolean = false;
var upArrow:Boolean = false;
var downArrow:Boolean = false;

// set event listeners
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedUp);
stage.addEventListener(Event.ENTER_FRAME, moveBee);

// set arrow variables to true
function keyPressedDown(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = true;
} else if (event.keyCode == 39) {
rightArrow = true;
} else if (event.keyCode == 38) {
upArrow = true;
} else if (event.keyCode == 40) {
downArrow = true;
}
}

// set arrow variables to false
function keyPressedUp(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = false;
} else if (event.keyCode == 39) {
rightArrow = false;
} else if (event.keyCode == 38) {
upArrow = false;
} else if (event.keyCode == 40) {
downArrow = false;
}
}

// move every frame
function moveBee(event:Event) {
var speed:Number = 1;

if (leftArrow) {
playerBee.x -= speed;
}
if (rightArrow) {
playerBee.x += speed;
}
if (upArrow) {
playerBee.y -= speed;
}
if (downArrow) {
playerBee.y += speed;
}
}

// test playerBee hit maze
if (playerBee.hitTestObject(maze)) {
messageText2.text = "hitTestObject: YES";
} else {
messageText2.text = "hitTestObject: NO";
}
}

Thank you so much for your time and help.

~la Swear.

I dont understand getTimer

Hi,

I dont understand why when code like this is ran:

private var speedX, speedY:Number;
private var lastTime:int;

public function TimeAni(x, y, dx, dy){

this.x = x;
this.y = y;
speedX = dx;
speedY = dy;
lastTime = getTimer();
addEventListener(Event.ENTER_FRAME, moveObject);

}// end construct

private function moveObject(event:Event):void{

var timePassed:int = getTimer() - lastTime;

lastTime += timePassed;

this.x += speedX*timePassed/1000;
this.y += speedY*timePassed/1000;

}

Why are the two getTimers displaying a diffrent time if get timer is the time since the flash player was insisalised then why do they show two diffrent times to produce a diffrence that then can be used for animation.

Thanks.

Scrolling Platform Game: Doesn't scroll in IE?

Hi guys.
I edited the scrolling platform game to make it completely different (but didnt edit the action script much).
It scrolls in flash player, but not in IE.. any help?
Thanks in advance.

vector vrs bitmaps

Hi Gary,

I was looking for some tutorial to help me to develop a top down car simulator and I found your site and the good news you have a book with an example very similar to my project. I was playing with your game demo and I wondered if you used vectors or bitmaps to do it, the background in Top-Down Driving Game. It is very likely I will buy the book but I would like to hear from you what approach you consider better: vectors or bitmaps

Thanks and good luck with your book

Antonio

Syndicate content

Copyright Gary Rosenzweig