Follow Another Sprite - AI (pac Man)
Help here .....an ai script...I'm wanting the enemy to follow the hero...on his _x and _y...problem being...it's seems to get confussed...as his _x and _y at the same time are changing..so he can't follow him he just gets stuck on the spot and goes crazy...
how do you read an _x and _y at the same time and effect them both...or am I way of the mark?
I want it to follow like pac man?
would be great if youse could help me out...
code below...
}
onClipEvent (enterFrame) {
if (hitTest(_root.hero)) {
_root.gotoAndPlay("die");
}
hero = _root.hero._x;
hero = _root.hero._y;
// move the hero MC in opposite direction to free him of collision
if (_root.back.hitTest(_x+10, _y, true)) {
_x -= 4;
} else if (_root.back.hitTest(_x-10, _y, true)) {
_x += 4;
} else if (_root.back.hitTest(_x, _y-10, true)) {
_y += 4;
} else if (_root.back.hitTest(_x, _y+10, true)) {
_y -= 4;
}
// works out which direction the hero is in and follows him
if (hero<_x) {
this.gotoAndStop("left");
_rotation = 270;
_x += walk;
} else if (hero>_x) {
this.gotoAndStop("right");
_rotation = 90;
_x -=walk;
}
if (hero>_y) {
this.gotoAndStop("up");
_rotation = 0;
_y += walk;
} else if (hero<_y) {
this.gotoAndStop("front");
_rotation = 180;
_y -= walk;
}
}
FlashKit > Flash Help > Flash ActionScript
Posted on: 05-10-2002, 07:23 AM
View Complete Forum Thread with Replies
Sponsored Links:
Make Several Sprite Instances Follow Same Oval Path
Hey
I have this little file I'm working on at the moment where a ball is rotating around an oval shape. This works and is looking good. What I want to do now is to create 3 more instances of the ball sprite and I've created and position them in the other 3 corners of the oval.
So it looks sort of like this to start off with:
----o
o ----- o
----o
(ignore the dashes, I just put them in there to I could illustrate the '4 corners')
I want all the balls to follow the same path and same speed etc. I'm assuming that there is some simple math formula I need to know but it's sort of going over my head at the moment.
Here's the code I'm working on:
Code:
package {
import flash.display.Sprite;
import flash.events.Event;
public class Oval extends Sprite {
private var ball:Ball;
private var ball2:Ball;
private var angle:Number = 0;
private var centerX:Number = 200;
private var centerY:Number = 200;
private var radiusX:Number = 200;
private var radiusY:Number = 100;
private var speed:Number = .1;
public function Oval() {
init();
}
private function init():void {
ball = new Ball();
addChild(ball);
ball.x = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
ball.x = centerX + Math.sin(angle) * radiusX;
ball.y = centerY + Math.cos(angle) * radiusY;
angle += speed;
}
}
}
I've included the files I've been working on so you can see.
Any help would be greatly appreciated.
Cheers!
View Replies !
View Related
Make Several Sprite Instances Follow Same Oval Path
Hey
I have this little file I'm working on at the moment where a ball is rotating around an oval shape. This works and is looking good. What I want to do now is to create 3 more instances of the ball sprite and I've created and position them in the other 3 corners of the oval.
So it looks sort of like this to start off with:
----o
o ----- o
----o
(ignore the dashes, I just put them in there to I could illustrate the '4 corners')
I want all the balls to follow the same path and same speed etc. I'm assuming that there is some simple math formula I need to know but it's sort of going over my head at the moment.
Here's the code I'm working on:
Code:
package {
import flash.display.Sprite;
import flash.events.Event;
public class Oval extends Sprite {
private var ball:Ball;
private var ball2:Ball;
private var angle:Number = 0;
private var centerX:Number = 200;
private var centerY:Number = 200;
private var radiusX:Number = 200;
private var radiusY:Number = 100;
private var speed:Number = .1;
public function Oval() {
init();
}
private function init():void {
ball = new Ball();
addChild(ball);
ball.x = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
ball.x = centerX + Math.sin(angle) * radiusX;
ball.y = centerY + Math.cos(angle) * radiusY;
angle += speed;
}
}
}
I've included the files I've been working on so you can see.
Any help would be greatly appreciated.
Cheers!
View Replies !
View Related
Loading Sprite Using Loader Need Access To Sprite Type
Hello,
I'm loading a Sprite via a Loader and once loaded I have access to that Sprite via the Loader class. I can manipulate the Sprites alpha, x and y coordinates ect. However, I have a custom function that fades in or out the passed param and it expects a Sprite. When I pass the loaded Sprite (loaded via the Loader class) I get an error:
1067: Implicit coercion of a value of type flash.display:Loader to an unrelated type flash.display:Sprite.
I know that the problem is that it expects a Sprite, but how do I access the Sprite type once the swf is loaded via the Loader?
My Code:
import FadeClip;
var ldrMovieCntr:Loader = new Loader();
addChild(ldrMovieCntr);
var fcLoadedMovie:FadeClip = new FadeClip(); //CUSTOM CLASS
fcLoadedMovie.setClipToFade(ldrMovieCntr); //PASSING IN A TYPE Loader - CLASS EXPECTS A Sprite
Thanks in advanced,
Vic
View Replies !
View Related
HELP: Sprite.addChild(NumericStepper) Resizes Sprite To 100x100
If anyone can help me with this, I would be extremely grateful. It's driving me insane.
If I run this code:
Quote:
var mySprite:Sprite = new Sprite();
trace("mySprite 1:", mySprite.width, mySprite.height);
numericStepper = new NumericStepper();
trace("numericStepper 2:", numericStepper.width, numericStepper.height);
mySprite.addChild(numericStepper);
trace("mySprite 3:", mySprite.width, mySprite.height);
I expect this output:
Quote:
mySprite 1: 0 0
numericStepper 2: 80 22
mySprite 3: 80 22
But I get this output:
Quote:
mySprite 1: 0 0
numericStepper 2: 80 22
mySprite 3: 100 100
If instead I do this:
Quote:
mySprite = new Sprite();
trace("mySprite 1:", mySprite.width, mySprite.height);
numericStepper = new NumericStepper();
trace("numericStepper 2:", numericStepper.width, numericStepper.height);
mySprite.addChild(numericStepper);
trace("mySprite 3:", mySprite.width, mySprite.height);
mySprite.width = 80;
mySprite.height = 22;
Then the numericStepper is drawn as if it is squished to 20% its normal height.
If I pre-set mySprite width and height before adding the numericstepper, the trace output is 0,0 after adding it and it is not displayed at all.
Is there some way I can make the sprite only adjust to correctly fit the numericStepper OR resize it afterwards without distorting the numericStepper component?
As I was typing this, I came across this post:
http://www.kirupa.com/forum/archive/.../t-263027.html
Can anyone help me modify that solution for a numeric stepper?
Thanks!
View Replies !
View Related
Dynamically Creating Sprite Inside Sprite
I'm having issues going from AS2 to AS3, mainly in this part , creating sprites/movieclips inside other sprites/movieclips, back in the days i could just create an emptymovieclip inside another, and easily locate it (fathermc.childmc), now the issue is i cant really locate the child, and from the research i have been doing i think i cannot have multiple child with the same name.
I need this because i usually work with textfields inside movieclips, and at any given time i will need to change the text on a specific movieclip's textfield, and i'm having some trouble with that for now.
Here is an example code
Code:
import flash.display.Sprite;
import flash.events.MouseEvent;
var circle1:Sprite = new Sprite();
circle1.graphics.beginFill(0xFFCC00);
circle1.graphics.drawCircle(0, 0, 40);
var circle3:Sprite = new Sprite();
circle3.graphics.beginFill(0xFF0000);
circle3.graphics.drawCircle(0, 0, 200);
circle3.alpha = 0.5;
function BuildInside(spr:Sprite) {
var circle2:Sprite = new Sprite();
circle2.graphics.beginFill(0xFFCCC0);
circle2.graphics.drawCircle(0, 0, 60);
circle2.alpha = 0.5;
spr.addChild(circle2);
}
addChild(circle1);
addChild(circle3);
BuildInside(circle1);
BuildInside(circle3);
circle1.x = 530;
circle3.x = 230;
//trace(circle1.x + " OK " + circle1.x);
stop();
i know that putting
Code:
var circle2:Sprite = new Sprite();
, inside a function , it will only be available in that function , but how can i make it available globally, do i need to define all of them in advance at the root ?
in this example i cant reach any of the circle2 inside the other circles, probly because of the var defining inside the function again.
thnx in advance for any help in this issue that has been holding back my AS2-AS3 upgrade
View Replies !
View Related
Why Does Sprite.filter Break Sprite.hitArea ?
Check this weird bug:
By adding the dropshadow to the circle, hit area no longer works. If you comment them out they work fine. WTHeck?
Code:
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(0, 0, 40);
var dShadow:DropShadowFilter = new DropShadowFilter();
circle.filters = [dShadow];
var square:Sprite = new Sprite();
square.graphics.beginFill(0xCCFF00);
square.graphics.drawRect(200, 0, 100, 100);
circle.hitArea = square;
square.mouseEnabled = false;
circle.addEventListener(MouseEvent.CLICK, clicked);
function clicked(event:MouseEvent):void{
trace(event.target == circle); // true
trace(event.target == square); // false
}
addChild(circle);
addChild(square);
View Replies !
View Related
Sprite And Child Sprite, Click Event On Both
Hello.
I have this menu item, which is a Sprite. The menu item then has several other items, also Sprite, as children. All items have a listener for click events. When I click the parent item, it's all ok, but when I click one of the children, both the child and the parent Sprite's event handler functions are triggered.
How can I stop the parent sprite from responding to the click on the child?
Thanks in advance.
Attach Code
var myParent:Sprite = new Sprite();
var myChild1:Sprite = new Sprite();
myParent.addChild(myChild1);
function click_parent ($event:MouseEvent) {
trace ("parent clicked");
}
function click_child ($event:MouseEvent) {
trace ("child clicked");
}
myParent.addEventListener(MouseEvent.CLICK, click_parent);
myChild.addEventListener(MouseEvent.CLICK, click_child);
//(Clicking myParent)
//parent clicked
//(Clicking myChild1)
//child clicked
//parent clicked
View Replies !
View Related
Add Listener When Sprite Hovers Over Sprite
Hi guys,
This is my first time looking for help on these forums so im giving it a go.
I have been trying to find the answer for this for a while with no luck
I have a grid with cells
When i hover over with a mouse it changes the color if the cell .... thats ok
What i want to do is hover over a cell with another object sprite and ofr it also to change color
Is their an event for this or does anyone have suggestions for another option
Thanks for any suggestions.
What i am thing is to substitute MouseEvent.ROLL_OVER for something else that will trigger when an object hovers over.
Some code:
Code:
public function createCell()
{
var temp_cell_object:Sprite = new Sprite();
........
.......
.......
the_cell_object.addEventListener(MouseEvent.ROLL_OVER,setCellBackgroundHighlightOn);
the_cell_object.addEventListener(MouseEvent.ROLL_OUT,setCellBackgroundHighlightOff);
the_cell_object.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
return temp_cell_object;
}
private function setCellBackgroundHighlightOn(evt:MouseEvent)
{
evt.target.transform.colorTransform = new ColorTransform(1, 1, .25, 1, 40, 0, 25, 0);
}
private function setCellBackgroundHighlightOff(evt:MouseEvent)
{
evt.target.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
}
View Replies !
View Related
[CS3] Sprite Collision/gravity Within Another Sprite
I'm doin an assignment based on flash but I jus learnt basic flash bt my assignment has forcen me to script higher than the level tat i had learnt.
This is roughly my idea:
correction: instead of e edge change color when the ball collide it, the ball will change color when it collide with the edges. I'm realli grateful to those who can teach & help me~ My assignment is due in 2 days time on thurs.. Thank you~
View Replies !
View Related
Sprite Collision/gravity Within Another Sprite
I'm doin an assignment based on flash but I jus learnt basic flash bt my assignment has forcen me to script higher than the level tat i had learnt.
This is roughly my idea:
correction: instead of e edge change color when the ball collide it, the ball will change color when it collide with the edges. I'm realli grateful to those who can teach & help me~ My assignment is due in 2 days time on thurs.. Thank you~
View Replies !
View Related
Cursor Follow, Click, Doesn't Follow
Before you read, I am not SOLVING said problem in topic, I WANT this "problem" to happen, but I'm not quite sure how to pull it off.
http://www.thesaladcaper.com/stuff/GameTest2.swf
These are two different MCs and of course just simple cursor actionscript. I want the glow/spiral to stop following when clicked. Also, if you could help out with how to make the tank rotate (or possibly even curve) to it's resting point, that'd be a lot of help, as well! Any and all help will be appreciated!
View Replies !
View Related
Cannot AddChilld(sprite) Into Another Sprite?
Hi,
First post woo,
Anyways, I'm quite new to AS3, I worked a bit with AS2 but not to a great extent, and I am now trying to teach myself AS3 (with a little help). I am creating a flash portfolio and so far have got images to import via XML and some other things, but I am stuck at one particular point:
I have an AS file called Statics.as that extends Sprite, it will contain all the code to draw the static elements of the portfolio, so far it draws a rounded rectange with gradient fine.
I then used URLRequest() and URLLoader() to load the XML, and then Loader to load the logo of the portfolio. I can add it to the Sprite now with:
Code:
addChild(logoLoader);
But I want to manipulate the x and y coords first. I initially failed as I tried to position it in the top right of the portfolio using:
Code:
logoLoader.x = 720-logoLoader.width -10
(720 being the width of the portfolio, and 10 being the padding from the right)
This did not work, after tracing logoLoader.width it seems that this property is not given and so tells me the width of the logo is 0. Therefore the x coord of the logo was mostly off the screen.
I then tried putting the logo into its own sprite to manipulate using:
Code:
var logoSprite:Sprite = new Sprite;
logoSprite.addChild(logoLoader);
logoSprite.addEventListener(Event.ADDED,logoComplete);
This didn't throw any errors, so I continued with:
Code:
public function logoComplete(evnt:Event)
{
evnt.target.x = 720-evnt.target.width -10;
trace(evnt.target.x);
}
This gave me an x coord value of 382 which is correct, this would position the logo in the top right hand corner in exactly the place I wanted.
But when I tried adding it as a child to the class, I got an error:
1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display: DisplayObject.
I believe the problem is that I am trying to add a Sprite as a child into a Sprite. As AS3 is quite new to me, I don't see why this should be a problem or a way around it, so my question is; Is what I am doing, the right way of manipulating the position of an external image before it being added to the stage?
Thankyou for your time,
Any reply is appreciated,
Blekk.
P.S.
A new instance of the AS file Statics.as is added to the stage via the DocumentClass.
Here is all the code relevant to the problem if needed:
Code:
package com.fusedDesign.userinterface
{
import flash.display.*;
import flash.geom.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
public class Statics extends MovieClip
{
public function Statics()
{
drawModule();
drawLogo();
}
public function drawLogo()
{
var urlRequest:URLRequest = new URLRequest("com/fusedDesign/folio/xml.xml");
var urlLoader:URLLoader = new URLLoader();
urlLoader.load(urlRequest);
urlLoader.addEventListener(Event.COMPLETE,xmlComplete);
}
public function xmlComplete(evnt:Event)
{
var imagesXML:XML = new XML(evnt.target.data);
loadImage(imagesXML);
}
public function loadImage(xml:XML)
{
var logoLoader:Loader = new Loader();
var logoRequest:URLRequest = new URLRequest(xml.logo.attribute("href")[0]);
logoLoader.load(logoRequest);
var logo:Sprite = new Sprite();
logo.addChild(logoLoader);
logo.addEventListener(Event.ADDED,logoLoaded);
}
public function logoLoaded(evnt:Event)
{
trace("added");
evnt.target.x = 720-evnt.target.width-10;
evnt.target.y = 10;
addChild(evnt.target);
}
}
}
I have removed the code that draws and adds the rounded rectangle.
View Replies !
View Related
Store A Sprite In A Sprite?
What is the best thing to do when storing a Sprite to call it later?
- save it to an array ("as Sprite") (I only need to store one value!)?
- save the name as String in a string variable then getChildByName?
- save it in a variable type Sprite?
three ways seam to work fine, really don't know if there is another one, neither which one is more correct.
any ideias?
thanks
View Replies !
View Related
What Is A Sprite?
I remember back in the day when the posts in the Newbie forum made sense to me... back when i could help people out by answering their questions. Looks like i've been out of the loop for too long what with all these easy scrolling task bars and sprites. Which brings me to my question... what in the heck is a sprite?
View Replies !
View Related
Sprite Isn't Just Pop
Ok, I am dumb. Hopefully someone can clear this up for me.
When people use *sprites* in thier files. (load sprites and whatnot)
what exactly is a sprite?
I know its like movement things, but...what the advantage? How do you use them?
Thanks for any help/clarification
View Replies !
View Related
Sprite Help
i want to animate a sprite (an already made .gif) walking from one side to another..
the problem is whenever i import it, by default it shows on the top left part of the screen. So, i move it frame by frame to wherever i want to put it and animate it but then it looks choppy and it isnt smooth at all.
i tried motion tweening it, but then it doesnt animate the .gif anymore.
View Replies !
View Related
Sprite Help Plz
How do you get rid of the white BG on the sprite sheets, im new at this and started 2 days ago, but i can make short 1 person films with them...now the white bg is interfering and i want to know how to get rid of it...PLZ help
View Replies !
View Related
New Sprite?
i know this is an easy answer but my head is stuck today.
i have a loop...i want it to generate 5 different sprites with 5 different names...
how do i do this and trace the sprites names?
i've been using
ActionScript Code:
spriteName:Sprite = new Sprite()
spriteName.name = "whatever" + num;
but i keep overwriting my sprites...i'm drawing circles in the sprites and when i roll over them they all have the same name!!!
View Replies !
View Related
New Sprite
Hi,
I want to create a lot of sprites (in future), for example with array elements:
var mmm:Array = new Array();
mmm[0] = "first";
var mmm[0]:Sprite = new Sprite(); // error
or
mmm[0]:Sprite = new Sprite(); // error
But this gives me an error.
Can somenone give me some advice for this exercise?
Thanks
View Replies !
View Related
Odd Sprite.y -=
ok, I'm stumped
I have something like this...
It works ok if d1.y >0 but as soon at it hits 0 it stops.
if I change speed to .1 instead of .01 it works the way it is suppose to
and allows d1 to go into -y. does anyone know what could be wrong here?
I just don't see any reason this should be happening.
Thanks!
Attach Code
var speed:Number = .01;
// d1 is a sprite
this.d1.y -= speed;
View Replies !
View Related
AS3.0, Sprite, FP9 .fla's And So On
Ok, let me get the suggestion out of the way. Are there any plans for a AS3.0 section to the forum? It would be really nice to start lumping all the AS3.0 stuff together. Just a suggestion.
Ok I have two questions:
#1. Anyone know how to instantiate a subclass of flash.display.Sprite WITHOUT implementing the iUIComponent interface in Flex 2?
From what I have seen with say senoc's AS3 tip o'the day and others, it seems you are extending the Sprite classes then using the addChild method. That doesn't seem to work in Flex 2 since the addChild's first parameter, even though a DisplayObject, is required to implement the iUIComponent interface. This may be unique to compiling in FB2 though.
#2. Can someone briefly explain to me how some of you are compiling flash player 9 swf's using a fla and AS3.0 classes?
I have been really stuck using the Flex 1.5 & 2 IDE's lately and am out of the loop on this topic. Doing this might just solve question #1.
Thanks folks.
View Replies !
View Related
Sprite Problem
I made a swi file with loads of sprites (50 or so), but when i exported the file into swf and then imported into flash i only see 1 frame and no moving movie. When i tried to copy the rectangle (what was in the sprite) to scene 1, and then exported the file and again imported into flash it works good. But the prob is, these rectangles aint on the same place when i paste them in scene 1 , so is there a way to delete all the sprites and the rectangles stay? (becoz flash 5.0 cant handle sprites)
View Replies !
View Related
How Do I Do A Flash Sprite?
Hi Gang,
I have a talking King Tut thumbnail SWF file.
How can I make it a Flash sprite which plays
over an HTML page?
I need to have the HTML page be visible everywhere
except where the Flash thumbnail is.
Thanks
Toby Mack
View Replies !
View Related
VG Sprite For Mac Problem
Hey everyone.... for starters... I am a serious newbie with a mac. (Yes, I know, bad choice, but what r u gonna do??) Anyway, I have become really interested in making Video Game Movies with flash. One problem though, how do u copy a picture from an emulator onto the clipboard for the mac. Then paste it as a gif or jpeg file??? Please, if anybody can help I would really appreciate it!!!!
View Replies !
View Related
Sprite Problems
Hi, I just got flash 5 for my computer, hoping to make little movies or games using video game sprites. Unfortunately, it seems when I copy and paste sprites onto flash, it does:
1. Makes the sprite upside-down(I know how to fix)
2. Makes it backwards (ditto)
3. When I make a flash action, it makes the picture VERY jpeggish.
4. The sprite becomes a little blurry
5. It leaves a little stupid white box around the sprite.
Can anyone help me out? I really want to fix #3 the most. It makes my high-quality sprites look like crap.
View Replies !
View Related
Button/sprite Help..
OK, i've done my searching, read the manual, looked at other help/faq sites and i still have a head scratchin' problem.
I need to make a few thumbnail images that will load larger images when the user clicks them. I have a basic knowledge of Swish (36 hours) but sprites/buttons seem to be eluding me.
How do i accomplish this?
Scott Russell
www.centricity.ca
View Replies !
View Related
Fading Sprite
Ok i have 10 buttons each one bringing up a different sprite. now the problem is say i click on button 1 and it brings up sprite 1 but when i click on button 2 how do i get sprite 1 to disappear? thanks for your help.
View Replies !
View Related
Sprite Movement
I'm making a RPG (i'm a NewB) game and i'm trying to inprove the movements of my characters. I have made sprites facing in 8 different directions, North - NE -East..... When i push the UP button the sprite should be walking and facing to the north. I've mannaged to let the sprite walk to North - E - S and W, but i can't figure out how to make it face in the other directions (NE, SE, SW, NW)
I,m using the following script (this is for the down button)
onClipEvent (enterFrame) {
a = 5;
if (_root._currentframe == 1) {
with (_root.sprite) {
//
// keyboard controls
if (Key.isDown(Key.DOWN)) {
_y += a;
// Facing Direction
this.gotoAndStop(5); <-- (5 is the south facing sprite)
}
}
}
}
What i'm trying to do is make te sprite look North-East by pressing the UP and Right at the same time.
If you know a better script or a site please sent it to me.
Tanx
View Replies !
View Related
Can We Add Sprite In Swish
hi,
respected sir,
I'm user of swish but very new to flash.so i want to know that can we add sprites in flash 5 if yes please tell me how is there any tutorial about this ?
can we add swf files as like we add in swish and .gifs ??
thanks
A-Ghani
View Replies !
View Related
Sprite Trouble
I want to add a sprite as the main character instead of that guy in this RPG template I found on the site.
http://www.flashkit.com/movies/Games...9072/index.php
The only problem is, whenever i add the sprite it comes out as really really small. The thing is, when i add the same sprite to a blank flash document its fine. Also, Manually making the all the walking sprites the exact same size so it doesnt look bad is a real chore (even if im using onion layers.) So, can someone please help?
By the way if you want to know what sprite I am trying to use it is the mario walking animation found here:
http://www.gsarchives.net/index2.php...evel1=playable
Thanks!
View Replies !
View Related
Scroll W/ Sprite
Ok so I want to have the window follow the spirit in the middle but i have no idea how to do it.
What i mean is how do i make a scrolling game that follows the character. so that the screen follows the sprite.
A good example of what I'd like is
http://mofunzone.com/online_games/sky_boarder_iii.shtml
In case you were wondering I'm using Flash MX
2004 pro.
View Replies !
View Related
Sprite Problems
I downloaded some pictures of link, Then used the pictures as sprites. But there is a white outline around him. Should I trace the bitmap?
(note:still working on drawing backrounds.)
deluxecentral.tripod.com/sitebuildercontent/sitebuilderfiles/linkremix.swf
is the site where it is located.
View Replies !
View Related
[f8] Sprite Actionscript
I can't quite get this sprite animation to work. Everything is fine except walking diagonally. Here is a link to the animation:
http://myfilestash.com/userfiles/pli...undSprites.swf
The following code is on the movie clip on the timeline. It takes the movie clip to a certain frame with another movie clip of him walking in a certain direction.
code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
gotoAndStop("down");
move(0,s);
} else if (Key.isDown(Key.UP)) {
gotoAndStop("up");
move(0,-s);
} else if (Key.isDown(Key.RIGHT)) {
gotoAndStop("right");
move(s,0);
} else if (Key.isDown(Key.LEFT)) {
gotoAndStop("left");
move(-s,0);
} if (Key.isDown(Key.DOWN) && Key.isDown(Key.LEFT)) {
gotoAndStop("downLeft");
move(-h,-v);
} if (Key.isDown(Key.UP) && Key.isDown(Key.RIGHT)){
gotoAndStop("upRight");
move(h,v);
} if (Key.isDown(Key.DOWN) && Key.isDown(Key.RIGHT)) {
gotoAndStop("downRight");
move(h,-v);
} if (Key.isDown(Key.UP) && Key.isDown(Key.LEFT)) {
gotoAndStop("upLeft");
move(-h,v);
}
}
And I put this code on the movie clips inside the main movie clip to make them stop playing:
code:
onClipEvent (enterFrame) {
if (Key.isDown(Key."key")) {
play();
} else {
stop();
}
}
Any help would be greatly appreciated.
View Replies !
View Related
Unrotating A Sprite
I crated a car game that when the car crashes into the wall it relocates back to the beginning of the track.
I am able to get it in the correct _x _y position, but, I can't get the car facing the correct way. It faces the direction that it had crashed into the wall.
The tough part is the car doesn't actually crash, after it hits into the wall it instantaneousely starts from the beginning (while playing a short crash sound)
So, I don't think I can do the visible = false because I won't be able to get it to play the crash sound
If there is anything you can do to help, or have any ideas I would really appreciate it. Thank you!
View Replies !
View Related
MX Need Sprite Shooting Help
ok, i need some help with making my sprite shoot a goddam bullet.
Here is my current code (taken from a tutorial here but ive added some stuff):
onClipEvent (load) {
gravity = 10;
scale = _xscale;
walkSpeed = 10;
maxjump = 2;
}
onClipEvent (enterFrame) {
if (air == true) {
_y += gravity;
state = 3;
}
if (Key.isDown(Key.LEFT) && !_root.leftbound.hitTest(_x, _y, true)) {
_x -= walkSpeed;
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT) && !_root.rightbound.hitTest(_x, _y, true)) {
_x += walkSpeed;
_xscale = scale;
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (Key.isDown(Key.SPACE) && jump == true) {
_y -= jumpSpeed;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (Key.isDown(Key.SPACE)) {
jumpcount += 1;
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {
state = 1;
}
if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {
state = 2;
}
if (!Key.isDown(65)) {
gotoAndStop(state);
}
_root.statetxt = state;
}
onClipEvent (keyUp) {
if (Key.getCode() == 83) {
jump = false;
}
}
can anybody help?!?!?!
View Replies !
View Related
Creating A Sprite
ok a brief description of what I am doing. I am trying to use a poser figure in flash. I have created a crane (bird) in poser and animated it to make its wings flap. I then rendered it by frame as pings images and imported them into flash. I built a movie so that each frame is played in sequence and now the bird flaps its wings in flash. How do I turn that movie into one animated sprite that I can then move into my flash scene and duplicate as many times as I want to make a flock of birds fly across my page?
I tried selecting all the frames, converting to symbol (movie) but the new symbol is locked on the first frame of the animation and the thing wont flap. do I do it as a graphic? please help.
View Replies !
View Related
Sprite Movie Help
Ok so i'm making a sprite movie in Flash. Everythings fine until i do test movie. I see that the sprites look blurred and non-pixelated. Is there a way i can make them look pixelated?
View Replies !
View Related
Button In A Sprite
Is it possible to create a button within a sprite?
The reason I am using a sprite is because it is being scrolled by the ScrollPane Component that is being housed within a movieclip.
For you visual people it goes like this:
Main Timeline > AboutMe_mc which holds the scrollPane that scrolls the MeTxt Sprite.
I have made it able to work fine when I don't use a sprite and code the frame with:
Code:
function onHere1BtnClicked(evt:MouseEvent):void {
MovieClip(parent).gotoAndPlay("Love");
}
Here1_btn.addEventListener(MouseEvent.CLICK,onHere1BtnClicked);
Overall the problem that I am running into is that I can't program the button because the sprite does not have a timeline, which is where I have to code the button to work.
Please enlighten me with your Flash knowledge.
- Thanks
View Replies !
View Related
Rotation Of A Sprite
I am a newbie to flash, and currently working on a game. I have managed to get my sprite to move using input from a keyboard however, the sprite is never facing the right direction. I believe this problem can be solved using trigonometry but im not entirely sure if im right and even if i was, i have no idea what code to use. Can anyone help? I'm using AS3.
Cheers,
Peaks,
View Replies !
View Related
Sprite Not Recognised?
Hi,
i've been trying very slower to build a site and got stumped on why the EventListener doesnt recognise my sprite called menuBox - the stage listeners work fine, but when the mouse moves over the menuBox it doesnt recognise it - anyone know why?
code: package {
//imports here//
public class Inquizard extends Sprite {
//var's here//
public function Inquizard() {
init();
}
private function init():void {
//sample code goes here
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
menuBox = new Sprite();
addChild(menuBox);
menuBox.graphics.lineStyle (.05, 0xffffff, .3);
menuBox.graphics.beginFill (0xff0000, 1);
menuBox.graphics.drawRect (-100,-10, 100, 10);
cornerShading = new Sprite();
addChild(cornerShading);
//cornershading//
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownStage);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpStage);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveStage);
menuBox.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownmenuBox);
menuBox.addEventListener(MouseEvent.MOUSE_UP, onMouseUpmenuBox);
menuBox.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMovemenuBox);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
menuBox.x = stage.stageWidth/2;
menuBox.y = stage.stageHeight/2 +140;
menuBox.width = 200;
menuBox.height = 40;
}
private function onMouseDownmenuBox (event:MouseEvent):void
{
trace ("mouse down - menuBox");
}
private function onMouseUpmenuBox (event:MouseEvent):void
{
trace ("mouse up - menuBox");
}
private function onMouseMovemenuBox (event:MouseEvent):void
{
trace ("mouse move - menuBox");
}
private function onMouseDownStage (event:MouseEvent):void
{
trace ("mouse down - stage");
}
private function onMouseUpStage (event:MouseEvent):void
{
trace ("mouse up - stage");
}
private function onMouseMoveStage (event:MouseEvent):void
{
trace ("mouse move - stage");
}
}
}
View Replies !
View Related
1 Sprite, 2 DisplayObjectContainers?
I'm not sure if this is possible, but I'd like to somehow put 1 Sprite into 2 displayObjectContainers. Here is an example:
Code:
var image:Sprite = new Image();
var containerA:Sprite = new Sprite();
containerA.x = stage.stageWidth / 2;
containerA.y = stage.stageHeight / 2;
addChild(containerA);
var containerB:Sprite = new Sprite();
containerB.x = stage.stageWidth/1.5;
containerB.y = stage.stageHeight/1.5;
addChild(containerB);
containerA.addChild(image);
containerB.addChild(image);
What i'd like is for the image instance to display twice, in both containers.
If I changed image.x, it'd change in both containerA, and containerB.
In this example, it only displays once (in containerB).
Is what I want possible? If so, how?
Cheers,
David
View Replies !
View Related
Extending Sprite?
So, I need to create an Actionscript 3 class that I can instantiate into a Flex app as a child. I have been mulling over how best to do this for like a week now, and I think I have an idea, but i'm lost as how to implement it.
What I need to do is create an Actionscript 3 class that I can send an imagepath to when it is instantiated. I then need the class to be able to be added to a Flex stage and displayed properly (I also need to be able to add listeners and such)
I tried extending the Sprite class, and embedding an image, it looked like this from a really basic testing perspective:
The Class:
Code:
package Classes
{
import flash.display.Sprite;
[Embed(source="../Thumbnails/Shea.jpg")]
[Bindable]
public class FreshMenuButton extends Sprite{
public function FreshMenuButton(){
super();
}
}
}
And the Script block in the Flex application :
Code:
import Classes.*;
private function init():void {
var testThumb1:FreshMenuButton = new FreshMenuButton();
this.addChild(testThumb);
}
I got this wierd error:
Quote:
Error: Error #2136: The SWF file file:///C:/Documents and Settings/dshackelford/My Documents/Flex Builder 3/FreshPhotography/bin-debug/FreshPhotography.swf contains invalid data.
(I got the error at the line that tries to instantiate the testThumb1, right before the addChild line)
Besides the error, I have to hardcode the embed asset in the class, which won't work in the long term anyway.
EVENTUALLY I need to be able to control the Y positions, and scales of all my instantiated classes through script (in case this changes someones awnser).
Any help would be most appreciated.
View Replies !
View Related
MC Sprite Shrinking
Hi
I am having troubles using sprites in my flash projects
When i import an image to the main stage it appears full size, but when i copy/import again the same image into a movieclip it becomes smaller and unusable
How do i stop this and make them copy the same size?
View Replies !
View Related
Problem With X Value Of Sprite
Hi,
I am assigning a value to the "x" property of a sprite. The value is a floating point with a fraction greater than .95.
For eg:
sprite.x = xVal;
//where xVal is say 161.9714285714286
when I directly read the "x" of sprite subsequently it always comes as 161.95000000000002. This problem comes with all the values having fraction greater than .95. Is there a bug in AS3 where in all the values having fractional component greater than .95 get their fractions hard-coded to
.95000000000002. This problem is causing few of my conditional checks to fail.
Please reply.
Thanks in advance.
View Replies !
View Related
|