Moving bitmaps and images with the mouse
Hello gamers,
I''m creating a map editor. The user will be able to select what structures(trees,houses,walls,etc) he wants to place on the screen from the toolbar. When the user makes the selection the bitmap or image will be placed on the screen. My question is once the bitmap or image is placed on the screen how do I move it around the screen so that I can place it where I want using the mouse?
Next question:
I want to create a wall in the the map editor window. I want to be able to click the mouse in two points and fill
the space between the two points with a wall, how would I go about doing this? The wall will be probably be a defined size just like all of my other structures.
Thanks Gamers,
casper
...for over a thousand years the Jedi Knights have been the guardians of peace and justice..before the dark times..before the EmpireCasper..
assuming you're speaking of 2d:
the easiest and most straight forward way would be to maintain a an xy position and z-order for all of your images. this way, you know what order in which to draw them. (groundplane = 0, etc.)
the simplest way of determining which images is at the mouse position is to brute force it (pseudocode):
for (each image in the array imgarray[]) {
if (
(mouse.x > imgarray[index].x) &&
(mouse.x < (imgarray[index].x + imgarray[index].width)) &&
(mouse.y > imgarray[index].y) &&
(mouse.y < (imgarray[index].y + imgarray[index].height))
)
{
//we have a winner!
int selectedimg = index;
break;
}
}
you can optimize the above (which doesn't take z into account btw) brute force pseudocode by ordering your images by location, and arbitrarily building a list of nearby images to the mouse cursor. along the same lines, you might maintain a list of images that are visible (since you only draw those, right?) and check against that.
Edited by - revolver on 3/18/00 1:52:38 PM
the easiest and most straight forward way would be to maintain a an xy position and z-order for all of your images. this way, you know what order in which to draw them. (groundplane = 0, etc.)
the simplest way of determining which images is at the mouse position is to brute force it (pseudocode):
for (each image in the array imgarray[]) {
if (
(mouse.x > imgarray[index].x) &&
(mouse.x < (imgarray[index].x + imgarray[index].width)) &&
(mouse.y > imgarray[index].y) &&
(mouse.y < (imgarray[index].y + imgarray[index].height))
)
{
//we have a winner!
int selectedimg = index;
break;
}
}
you can optimize the above (which doesn't take z into account btw) brute force pseudocode by ordering your images by location, and arbitrarily building a list of nearby images to the mouse cursor. along the same lines, you might maintain a list of images that are visible (since you only draw those, right?) and check against that.
Edited by - revolver on 3/18/00 1:52:38 PM
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
Would this pseudo code apply for bitmap images too?
...for over a thousand years the Jedi Knights have been the guardians of peace and justice..before the dark times..before the EmpireCasper..
quote:
Original post by revolver
assuming you''re speaking of 2d:
the easiest and most straight forward way would be to maintain a an xy position and z-order for all of your images. this way, you know what order in which to draw them. (groundplane = 0, etc.)
the simplest way of determining which images is at the mouse position is to brute force it (pseudocode):
for (each image in the array imgarray[]) {
if (
(mouse.x > imgarray[index].x) &&
(mouse.x < (imgarray[index].x + imgarray[index].width)) &&
(mouse.y > imgarray[index].y) &&
(mouse.y < (imgarray[index].y + imgarray[index].height))
)
{
//we have a winner!
int selectedimg = index;
break;
}
}
you can optimize the above (which doesn''t take z into account btw) brute force pseudocode by ordering your images by location, and arbitrarily building a list of nearby images to the mouse cursor. along the same lines, you might maintain a list of images that are visible (since you only draw those, right?) and check against that.
Edited by - revolver on 3/18/00 1:52:38 PM
Hey revolver would this pseudocode apply to bitmap images as well?
...for over a thousand years the Jedi Knights have been the guardians of peace and justice..before the dark times..before the EmpireCasper..
it should work with any image you have in the array, as long as you store the x and y position for each.
imgarray[] is just an array of images (bitmaps). index is the current one it''s looking at, and increased every time the for loop rolls over. thus, imgarray[index] will return a certain image. imgarray[index].x gets the x position, and so on.
imgarray[] is just an array of images (bitmaps). index is the current one it''s looking at, and increased every time the for loop rolls over. thus, imgarray[index] will return a certain image. imgarray[index].x gets the x position, and so on.
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement