jicehel
Number of posts : 15 Registration date : 2013-03-12
| Subject: Clic to select on sprite and move it !! (Thanks Klaus) Sat Mar 23, 2013 1:48 pm | |
| A cool source from Klaus until he can connect: The source create 2 sprites: - A blue rectangle - A red ring The ring is on the rectangle at the begin. You can clic on one of the sprites to select it and then you can or clic somether to move the sprote or click on other sprites to deselect the current and select the one you clicked on This source can be adapted for many use of sprites ... English users show us you can do cool things too with Panoramic !! PS: Germans users are alot too (Klaus, Stephan, Severin). I'm sure you make cool things too... - Code:
-
' ON_SPRITE_CLICK.bas label click, tim dim i%, x%, y%, ns%, spr%, x1%, y1%, delta% dim number_sprite_click%, save_sprite_click%
delta% = 1
scene2d 1 : on_click 1,click : full_space 1 : color 1,200,200,200 image 2 timer 3 : timer_interval 3,100 : on_timer 3,tim : timer_off 3
ns% = 0 : ' initialement pas de sprites dim sprites%(10,2) : ' pérvoir pour 10 sprites
' premier sprite: rectangle bleu sprite 17 : sprite_position 17,300,10 picture 17 : hide 17 : width 17,200 : height 17,10 2d_target_is 17 : 2d_pen_color 0,0,255 : 2d_fill_color 0,0,255 2d_rectangle 0,0,199,9 2d_image_copy 2,0,0,199,9 sprite_image_load 17,2 memoriser_sprite(17,200,10) sprite_position 17,200,200
' deuxième sprite: anneau rouge sprite 12 : sprite_position 12,10,50 picture 12 : hide 12 : width 12,120 : height 12,120 color 12,0,0,0 : ' fond transparent 2d_target_is 12 : 2d_pen_color 255,0,0 : 2d_fill_color 255,0,0 2d_circle 60,60,50 2d_fill_color 0,0,0 2d_circle 60,60,25 2d_image_copy 2,0,0,119,119 sprite_image_load 12,2 memoriser_sprite(12,120,120) sprite_position 12,250,150
end
sub memoriser_sprite(n%,w%,h%) ns% = ns% + 1 : ' compter le nouveau sprite sprites%(ns%,0) = n% : ' numéro du sprite sprites%(ns%,1) = w% : ' largeur du sprite sprites%(ns%,2) = h% : ' hauteur du sprite end_sub
tim: sprite_position number_sprite_click%,sprite_x_position(number_sprite_click%)+delta%,sprite_y_position(number_sprite_click%)+delta% delta% = 0 - delta% return
click: timer_off 3 save_sprite_click% = number_sprite_click% number_sprite_click% = 0 : ' supposer "aucun sprite n'est cliqué" x% = mouse_x_left_down(1) y% = mouse_y_left_down(1) for i%=ns% to 1 step -1 : ' boucle sur les sprites existants spr% = sprites%(i%,0) x1% = x% - sprite_x_position(spr%) y1% = y% - sprite_y_position(spr%) ' test si l'abscisse du clic correspond à ce sprite if x%>=sprite_x_position(spr%) if x%<(sprite_x_position(spr%)+sprites%(i%,1)) ' test si l'ordonnée du clic correspond à ce sprite if y%>=sprite_y_position(spr%) if y%<(sprite_y_position(spr%)+sprites%(i%,2)) ' test si ce n'est pas la couleur transparente if (color_pixel_red(spr%,x1%,y1%)+color_pixel_green(spr%,x1%,y1%)+color_pixel_blue(spr%,x1%,y1%))>0 ' alors on a identifié le sprite number_sprite_click% = spr% : ' .. lancer ici la routine on_sprite_click caption 0,"NUMBER_SPRITE_CLICK = "+str$(number_sprite_click%) timer_on 3 return end_if end_if end_if end_if end_if next i% if save_sprite_click%>0 then sprite_position save_sprite_click%,x%,y% caption 0,"NUMBER_SPRITE_CLICK = 0" return | |
|
Klaus
Number of posts : 18 Age : 74 Localisation : France Registration date : 2013-03-23
| Subject: Re: Clic to select on sprite and move it !! (Thanks Klaus) Sat Mar 23, 2013 9:19 pm | |
| Hello, here I am ! I use KGF as pseudo on the english form because Klaus is simply refused here, but it's me anyway ! Thanks to you, Papydall, for estimating my little sample worth to be published here ! | |
|
jicehel
Number of posts : 15 Registration date : 2013-03-12
| Subject: Re: Clic to select on sprite and move it !! (Thanks Klaus) Sun Mar 24, 2013 1:35 am | |
| Klaus Jicehel is the same Jicehel as on the french Forum... Not papydall | |
|
papydall
Number of posts : 39 Age : 73 Localisation : TUNISIA Registration date : 2013-03-16
| Subject: Re: Clic to select on sprite and move it !! (Thanks Klaus) Sun Mar 24, 2013 1:40 am | |
| - Klaus wrote:
- Hello, here I am ! I use KGF as pseudo on the english form because Klaus is simply refused here, but it's me anyway ! Thanks to you, Papydall, for estimating my little sample worth to be published here !
Let us return to Caesar what belongs to Caesar: it is rather Jicehel whom you have to thank. | |
|
Klaus
Number of posts : 18 Age : 74 Localisation : France Registration date : 2013-03-23
| Subject: Re: Clic to select on sprite and move it !! (Thanks Klaus) Sun Mar 24, 2013 10:51 am | |
| Oh yes, sorry Jicehel ! And thank you ! | |
|
Sponsored content
| Subject: Re: Clic to select on sprite and move it !! (Thanks Klaus) | |
| |
|