Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / would appreciate help with button and source i have written. ty

Author
Message
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 4th Mar 2005 11:29
I am using dbpro. only been coding for about a week. having lots of trouble. I built my first program that uses a sprite as a button. however i had to use the if mousex() > ___ and mousX() <___ and i think you get the point. i was wondering if there was an easier way to make a button not to mention it caused the program to mess up. it is supposed to let you drag a sprite around the screen. thank you for the help. i have some of the media but my upspeed is slow so i will leave it up to you to find a background image. games resolution is in 1280,1024,32

u need unzipper for the media if you dont have one get one at [href]winrar.com[/href] or [href]winzip.com[/href]

Attachments

Login to view attachments
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 5th Mar 2005 02:54 Edited at: 5th Mar 2005 02:55
For 3d object's, there is a nifty command called Pick Object, which is very useful for determining if your mouse is pointing at an object on the screen. Unfortunately, there is no similar command for sprites. You can create similar functionality though:

Make a very small (1x1) sprite and position it at mousex() and mousey(). You could also hide the sprite. Then check it for collisions with other sprites. If you get a collision returned, then you know the mouse pointer is over another sprite. This is a very easy way to work around all those
Quote: "if mousex() > ___ and mousX() <___"

commands, and you don't have to worry about missing a number.

Here's a snippet example.


Ps. Sorry I didn't look at your code. I'm at work and can't atm. I'll check back later.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Soy Cocktail
20
Years of Service
User Offline
Joined: 23rd Dec 2003
Location:
Posted: 7th Mar 2005 09:52 Edited at: 7th Mar 2005 09:54
I normally use if mousex()>______ like you do, however i normally use variables instead of using exact values so I can easily change them.
Since you position images at the top left corner using an x and a y position I use a variable for each. So Xpos(1)=somenumber. for the if statement I then use if mousex()>xpos(1) and mousex()<xpos(1)+bitmap width(1) The "+bitmap width(1)" part will get the right edge of the image, you do the same for the y value, just replace +bitmap width(1) with +bitmap height(1).


Now about that code, When you are positioning the image you have it use
SPRITE 1,MOUSEY(),MOUSEX(),1
the command syntax is SPRITE Sprite Number, XPos, YPos, Image Number
You are using mousey for the x position and mousex for the y position.
Once the mouse is moved out of the box where you click you can no longer move the sprite. To fix this I use a while statement, While statements are like loops but only run while a condition is true. The condition I used was mouseclick()=1 This means that the mouse left button is clicked.
I eneded up with
while mouseclick()=1
SPRITE 1,MOUSEx(),MOUSEy,1
endwhile
The problem with that is that it never updates the screen, so I added the sync command below the sprite command

It works, well sort of. The plane is leaving a trail behind it, I assume that you dont want that. To fix it I added in a cls command which clears the screen at the top of the wile loop.

And now it kinda works. I assume that you want the middle of the picture to be positioned at the mouse position, and not the top left of the picture. To do this I used the bitmap height and bitmap width commands
you want the middle of the picture to be positioned at the mouse, so we need to find the middle of the picture. I used bitmap height and devided it by 2 to get the middle. I did the same for width. Now that we have those values we need to subtract them to the mousex position and mouse y position. I ended up with...

while mouseclick()=1
cls
SPRITE 1,MOUSEx()-(BITMAP WIDTH(1)/2),MOUSEy()-(bitmap height(1)/2),1
sync
endwhile

The final code i ended up with is
Hope that is what you wanted it to do.

When life hands you lemons go buy some oranges to make orange juice, and stop expecting everything to be given to you.
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 9th Mar 2005 03:51
thank you both so very much. Yes that is what i wanted it to do. i completely forgot about the while loop didnt know i could use it there. and i took a look at the sprite collision and it does work as well. sorry for the long response time internet problems.

Login to post a reply

Server time is: 2024-11-13 19:48:42
Your offset time is: 2024-11-13 19:48:42