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.

Code Snippets / sprite dragging

Author
Message
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 22nd Oct 2003 08:57
here is a snippit to drag a sprite...a little wirld, but it works



Bishop

ps-do comment on how to make it better...thanx

"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Oct 2003 10:05
Change this line:

if mousex()=>sprite x(1) and mousex()=<sprite x(1)+50 and mousey()=>sprite y(1) and mousey()=<sprite y(1)+50

to this:

if mousex()=>sprite x(1) and mousex()<sprite x(1)+sprite width(1) and mousey()=>sprite y(1) and mousey()<sprite y(1)+sprite height(1)

This way, it doesn't depend on a 50x50 sprite being used and can use any size sprite

Also, if you change this line:

sprite 1,mousex(),mousey(),1

to this:

sprite 1, mousex()-(sprite width(1)/2), mousey()-(sprite height(1)/2), 1

Then the mouse will be centred on the sprite instead of the top left
Codger
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 22nd Oct 2003 18:36
Here is an approach



System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Oct 2003 22:20
Yes, but you'll have problems if you drag a high-numbered sprite over a low-numbered one using that code ... try it and see
Codger
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 22nd Oct 2003 23:35
That's because High number sprites are over low number Sprites. It is a feature of DBP

System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Oct 2003 00:00 Edited at: 23rd Oct 2003 00:02
What I meant was that sometimes when you drag one sprite over another, your code will switch sprites

Here's a fixed version, plus I've also made the dragging a bit better ... you'll see what I mean when you run it

[edit]I've also hidden the sprite created by your pick sprite function - if you don't, you'll see the single dot image. Collision still works correctly with a hidden image[/edit]
Codger
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 23rd Oct 2003 01:21
By George I thinks weeve got it

Nice final Touch IanM

System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX
Codger
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 23rd Oct 2003 02:02
One More time I knew that was too much code IanM



I can't stand too much code

System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 23rd Oct 2003 04:12
hmmm.this post has grown alot

intersting, but works well....makes my original snippit look really pathetic

thanks alot guys!!

Bishop

"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."

Login to post a reply

Server time is: 2024-11-23 23:50:21
Your offset time is: 2024-11-23 23:50:21