PDA

View Full Version : get all x & y coordinate values


cmt9000
11-02-2010, 07:26 PM
I have created a triangle-shaped moving target graphic in Photoshop and added it as a movieClip.

Is there a way to get all x & y values that make up the movieClip?

thanks!

bluemagica
11-03-2010, 01:01 PM
You know, there are two types of images, one is vector graphics and involves co-ordinates and some simple math formulas to define a shape, and the second is pixel graphics which are made with tiny colored boxes and don't involve co-ordinates or math. The graphics you made in photoshop, belong to this second category, hence you can't access it's coordinates .Well, technically, you can get all of the co-ordinates for each pixel, but I don't think you want that.

If you can be a bit clear about your actual purpose, then I might be able to provide some actual help....as there is always multiple logical solutions for the same problem.

cmt9000
11-03-2010, 01:24 PM
Hi bluemagica, thanks for the reply.

My game has a gun that shoots a laser(using lineTo/moveTo). I created targets in Photoshop and imported as movieClips, that I move across the screen.

When I fire the laser gun, I need to see if the line "hits" the target.

But as you said, since my targets are movieClips, they don't have x & y coordinates.

Do you know of a way to see if my line hits the target without using coordinates?

Thanks!

bluemagica
11-03-2010, 01:47 PM
1) When shooting, make a new Sprite() and push it in an array.
2) Add this sprite to the screen, and draw your laser inside it.
3) Go through your enemy-array, and simply hitTest the enemy and the bullet/laser sprite.

cmt9000
11-03-2010, 02:20 PM
1) When shooting, make a new Sprite() and push it in an array.
2) Add this sprite to the screen, and draw your laser inside it.
3) Go through your enemy-array, and simply hitTest the enemy and the bullet/laser sprite.

Hi bluemagica,

I'm having some trouble understanding when you say "push it in an array" and "draw your laser inside it".

Do you mean add each x&y location of the Sprite to an array?

And when you say draw, do you mean using moveTo/lineTo like I did previously?

I'm not sure how I would draw inside the sprite...

Thanks!

bluemagica
11-03-2010, 02:35 PM
-_-


function shootLaser(e:WhateverEvent):void
{
var temp:Sprite = new Sprite();
bulletArray.push(temp);
addChild(temp);

temp.graphics.lineStyle(4,0xFF87DF);
temp.graphics.moveTo(myShip.x,myShip.y);
temp.graphics.lineTo(endPointX,endPointY);
}

..
....
..........

function checkCollisions(e:Event):void
{
for each(var spr:Sprite in bulletArray)
{
for each(var ene:* in enemyArray)
{
if(spr.hitTest(ene))
{
trace("yay, finally managed to hit something useful");
}
}
}
}

cmt9000
11-03-2010, 03:11 PM
Wow, thanks!

I understand the concept of the code, and I think I can work with it except I'm not sure what to do with "enemyArray". My moving target is actually a movieClip. Would I do the same with this, create a Sprite, then put the movieClip inside that Sprite?

Thanks again for you help

bluemagica
11-03-2010, 03:38 PM
well normally we have multiple enemies just as we have multiple bullet's instances (by the way, you do know the difference between base-object and instances, right?), so assuming that, we normally store enemy instances in an array similar to how I stored the bullet instances in an array.....

If you have a single instance, you have no need for a nested loop, you just have to hitTest straight away against that particular instance.

PS: Movieclip and Sprite is basically the same thing except a "sprite" has only one frame, unlike movieclip which has it's own timeline.

cmt9000
11-03-2010, 04:13 PM
An instance is like a clone of the base-object right? For example, I created a target graphic and put it on the stage. I'm assuming that's the base object. I then created a named instance of it. Am I on the right track here?

bluemagica
11-03-2010, 04:18 PM
Yep, you are right, except one thing, whatever you are putting on the stage is an instance, a temporary copy of the original object.......the original resides in the library.

cmt9000
11-03-2010, 04:19 PM
Oh ok...so is it the base-object that goes into the library?

bluemagica
11-03-2010, 04:34 PM
yep, and it is the base-object that you "export for actionscript".

cmt9000
11-03-2010, 04:52 PM
Thanks for the mini-tutorial!