To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-12-2004, 09:38 PM   #1
JoeyDude
Junior Member
 
Join Date: Oct 2004
Posts: 14
Problem with my _x and _y properties...

Hi,
I'm trying to make an Arkanoid type of game in flash, and I'm having a problem.

When I make the instance of the bar (that you are controlling) and the instance of the ball, I put them both at x: 400, y: 400.

But they are not at the same point.

The ball is 50 pixels below the bar, but the y axie is correct.

I tried to make a trace of that, and flash tells me that both objects are at x:400, y:400.

I also attached a screenshot of what my code does, in this post (below).

Anyone knows what my problem could be?
Thanks a lot for your help guys

Code:
var initPalX:Number = 400;
var initPalY:Number = 400;

var initBallX:Number = 400;
var initBallY:Number = 400;

var ballSpeed:Number = 20;
var paletteSpeed:Number = 10;

var theball:Ball = new Ball(mc_passball, initBallX, initBallY, ballSpeed, initX, initY);
var thepalette:Palette = new Palette(mc_pal, initPalX, initPalY, paletteSpeed);


this.onEnterFrame = function()
{
	if (Key.isDown(39))
	{
		thepalette.moveRight();
		theball.followPalette(thepalette.getx(), thepalette.gety());
	}
	
	if (Key.isDown(37))
	{
		thepalette.moveLeft();
		theball.followPalette(thepalette.getx(), thepalette.gety());
	}
	
	if (Key.getCode() == 32)
	{
		theball.rebound(90);
	}
}
Here is my Ball class:

Code:
class Ball extends MovieClip
{
	var ball_mc:MovieClip;
	var x:Number;
	var y:Number;
	var speed:Number;
	var lx:Number;
	var ly:Number;
	
	public function Ball(pass_mc:MovieClip, pass_x:Number, pass_y:Number, pass_speed:Number, pass_lx:Number, pass_ly:Number)
	{
		ball_mc = pass_mc;
		ball_mc._x = pass_x;
		ball_mc._y = pass_y;
		speed = pass_speed;
		lx = pass_lx;
		ly = pass_ly;
	}
	
	public function getHitAngle()
	{
		var a:Number = Math.abs(lx - ball_mc._x);
		var b:Number = Math.abs(ly - ball_mc._y);
		var c:Number = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
		var angle:Number= Math.asin(a / c);
		
		return angle;
	}
	
	public function rebound(angle:Number)
	{
		var scale_x:Number = Math.cos(angle);
		var scale_y:Number = Math.sin(angle);
		
		var velocity_x:Number = (speed * scale_x);
		var velocity_y:Number = (speed * scale_y);
		
		ball_mc._x -= velocity_x;
		ball_mc._y -= velocity_y;
	}
	public function followPalette(pass_x:Number, pass_y:Number)
	{
		
		ball_mc._x = pass_x;
		ball_mc._y = pass_y;
		//trace(pass_obj._x);
	}
	
	public function setlx(pass_lx:Number)
	{
		lx = pass_lx;
	}
	
	public function setly(pass_ly:Number)
	{
		ly = pass_ly;
	}
	
	public function getx()
	{
		return ball_mc._x;
	}
	
	public function gety()
	{
		return ball_mc._y;
	}
	
}
Here is my bar class:

Code:
class Palette extends MovieClip
{
	var mc_palette:MovieClip;
	var speed:Number;
	
	public function Palette(pass_mc:MovieClip, pass_x:Number, pass_y:Number, pass_speed:Number)
	{
		mc_palette = pass_mc;
		mc_palette._x = pass_x;
		mc_palette._y = pass_y;
		speed = pass_speed;
	}
	
	public function moveLeft()
	{
		mc_palette._x -= speed;
	}

	public function moveRight()
	{
		mc_palette._x += speed;
	}
	
	public function getx()
	{
		return mc_palette._x;
	}
	
	public function gety()
	{
		return mc_palette._y;
	}
}
Attached Images
File Type: jpg arkanoid_screenshot.jpg (42.2 KB, 311 views)
JoeyDude is offline   Reply With Quote
Old 10-12-2004, 09:50 PM   #2
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
Are the graphics for your ball and paddle coming from symbols in the library? If so, edit those symbols and look at where the graphics are in relationship to the crosshairs.

When you set the _x and _y properties, you are setting where the crosshairs go. The rest of the graphics are going to have the same relationship to the crosshairs, so if your ball or your paddle is pretty far from the crosshairs, then they are also going to be pretty far from the _x and _y setting.
__________________
jbum is offline   Reply With Quote
Old 10-12-2004, 10:49 PM   #3
JoeyDude
Junior Member
 
Join Date: Oct 2004
Posts: 14
Great!

That solved my problem!

Thanks a lot, I really appreciate it

Thnaks again,
Joey
JoeyDude is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:52 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.