Sign in to follow this  

issue with image placement in respect of another image

This topic is 2040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using XNA 4.0 and c#

how can I get an image to set its position according to the end of another image?

this is what I have so far

[code]

rocketPosition = players.Position;
rocketPosition.X += players.Position.X +40;
rocketPosition.Y -= players.Position.Y -370 ;
rocketAngle = players.Angle;
Vector2 up = new Vector2(0, -1);
Matrix rotMatrix = Matrix.CreateRotationZ(rocketAngle);
rocketDirection = Vector2.Transform(up, rotMatrix);
rocketDirection *= players.Power / 50.0f;
[/code]

the rocket goes in the right direction but its starting position is wrong if I move the cannon

the code that moves the cannon
[code]

if (keybState.IsKeyDown(Keys.Left))
{
if(players.Angle > MathHelper.PiOver4-.3)
players.Angle -= 0.01f;
}
if (keybState.IsKeyDown(Keys.Right))
{
if (players.Angle < MathHelper.PiOver2)
players.Angle += 0.01f;
}
[/code]

Share this post


Link to post
Share on other sites
I accomplished this using something like this:

[CODE]
public Vector2 WeaponFireLoc
{
get
{
return Location + (WeaponDir * <X Offset at neutral angle, I used 5 but have small sprites>);
}
}
public Vector2 WeaponDir
{
get
{
Vector2 v = new Vector2(-1, 0);
v = Vector2.Transform(v, Matrix.CreateRotationZ(WeaponAngle));
if (v != Vector2.Zero)
{
v.Normalize();
}
return v;
}
}
[/CODE]

The WeaponDir gets a normalized V2 (-1 -> 1) that points in the direction the weapon is aiming.
WeaponFireLoc returns a V2 that is N pixels down that direction from Location, where N is <X Offset at neutral angle, I used 5 but have small sprites>.

Hope that helps. I suspect it's not the only solution, and perhaps not the best, but it's worked for me. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites

This topic is 2040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this