Help with ocking the cursor to the bottom y axis of a sprite
Page 1 of 1
Rayne01




Posts: 39

PostPosted: Sun, 15th Mar 2015 18:17    Post subject: Help with ocking the cursor to the bottom y axis of a sprite
I've not long started games programming formally at my college; I've been using photoshop to create a 2D animation of a lightning bolt.

Generally I have two questions.

My first is, when I click on the game screen, the lightning bolt will render, but the sprite is locked to the centre of the animation. What I want is to, when the mouse is clicked, lock the bottom middle of the line (y-axis) of the image to the cursor click. This would, on screen, represent the simulation of the user clicking on the tail of the lightning bolt on the position of their cursor.

My first suspicious in code was: (assuming the sprite is 250 in width)

sprite.position.Y = mouse.Y / 2; (my assumption being this would essentially place the cursor at the bottom of the sprite in the middle by dividing the width; this would place the cursor at the bottom middle (radius) of the sprite?

I don't think this would work; I'm wondering if anyone else knows of a working solution to my problem.

After I've accomplished this, I'll be working on putting my sprite into a texture2D variable and wrapping a rectangle around it for collision detection.

Thanks in advance.
Back to top
bloodian




Posts: 1026

PostPosted: Sun, 15th Mar 2015 19:10    Post subject:
I'm guessing that you're working on such coordinate system:



........................-------------------
........................|....................|
........................|....................|
........................|....................|
........................-------------------
.................................c.............

The red square is your image, c is the cursor.

So the coords of your image will be: image.y = c.y + image.height;

image.x = c.x - image.width/2;

There's nothing to explain here. You just have to draw it on a piece of paper
Back to top
Rayne01




Posts: 39

PostPosted: Sun, 15th Mar 2015 19:22    Post subject:
I think I fully understand your solution.

This places the mouse cursors at the bottom of the image (y) axis.

Then, placing the image at the mouse x axis, dividing it by 2 which would be the radius and place it right in the bottom middle.

Correct?
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group