Posted: 22nd Oct 2003 8:57
here is a snippit to drag a sprite...a little wirld, but it works

+ Code Snippet
`drag sprites
`by zach turnlund

`make box and images
box 0,0,50,50
get image 1,0,0,50,50
cls
sprite 1,300,300,1

`do
do



`find where the mouse is and change the selected variable
if mousex()=>sprite x(1) and mousex()=<sprite x(1)+50 and mousey()=>sprite y(1) and mousey()=<sprite y(1)+50
	if selected=0
		if mouseclick()=1
			selected=1
			wait 100
		endif
	endif
	if selected=1
		if mouseclick()=0
			selected=0
			wait 100
		endif
	endif
endif
if selected=1 
	sprite 1,mousex(),mousey(),1
	wait 100
endif


`sync and loop
loop


Bishop

ps-do comment on how to make it better...thanx
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
Posted: 22nd Oct 2003 18:36
Here is an approach

+ Code Snippet
Rem Project: DragSprite
Rem Created: 10/22/2003 7:15:07 AM

Rem ***** Main Source File *****

Randomize Timer()

For i = 1 to rnd(15)+5
   X = Rnd(Screen width()/3)
   Y = Rnd(Screen Height()/3)

   ink rgb (rnd(255),rnd(255),rnd(255)),0
   cls
   box 0,0,x,y
   get image i,0,0,x,y
   sprite i,Rnd(Screen width()),Rnd(Screen height()),i
next i


do
   if mouseclick() &lt;&gt; 0
      target = Pick_Sprite(0)
      if target &lt;&gt; 0
         sprite target, Mousex()-(sprite width(target)/2),MouseY()-(sprite height(target)/2),target
      endif
   endif
   sync
loop

Function Pick_Sprite(Target)
   rem change 999 to any number you wish
   rem move the next line outside of main loop should only be called once
  get image 999,1,1,2,2
  sprite 999,mousex(),Mousey(),999
  hit = sprite collision(999,Target)
  rem the following is only for testing
  set cursor mousex()-200,Mousey()
  print "Hit Sprite # : ",hit
EndFunction hit
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
Posted: 22nd Oct 2003 23:35
That's because High number sprites are over low number Sprites. It is a feature of DBP
Posted: 23rd Oct 2003 0:00
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]
Posted: 23rd Oct 2003 1:21
By George I thinks weeve got it

Nice final Touch IanM
Posted: 23rd Oct 2003 2:02
One More time I knew that was too much code IanM

+ Code Snippet
Rem Project: DragSprite
Rem Created: 10/22/2003 7:15:07 AM

Rem ***** Main Source File *****

Randomize Timer()

For i = 1 to rnd(15)+5
   X = Rnd(Screen width()/3)
   Y = Rnd(Screen Height()/3)

   ink rgb (rnd(255),rnd(255),rnd(255)),0
   cls
   box 0,0,x,y
   get image i,0,0,x,y
   sprite i,Rnd(Screen width()),Rnd(Screen height()),i
next i

Target = 998

do
   if mouseclick() = 1
      if target  &lt;&gt; 0 and Pick_Sprite(Target)= 1
         sprite target, Mousex()-(sprite width(target)/2),MouseY()-(sprite height(target)/2),target
      else
         Target = Pick_Sprite(0)
            if Target &lt;&gt; 0
               sprite target, Mousex()-(sprite width(target)/2),MouseY()-(sprite height(target)/2),target
            endif
      endif
   endif
   sync
loop

Function Pick_Sprite(Target)
   rem change 999 to any number you wish
   rem move the next line outside of main loop should only be called once
  get image 999,1,1,2,2
  sprite 999,mousex(),Mousey(),999
  hit = sprite collision(999,Target)
  rem the following is only for testing
  set cursor mousex()-200,Mousey()
  print "Hit Sprite # : ",hit
  delete sprite 999
EndFunction hit


I can't stand too much code
Posted: 23rd Oct 2003 4:12
hmmm.this post has grown alot

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

thanks alot guys!!

Bishop