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.

DarkBASIC Professional Discussion / click to make objects disappear?

Author
Message
scuzz
16
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 29th Mar 2010 05:08
whats the code so that when the mouse clicks on a sprite, it disappears?
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Mar 2010 14:43 Edited at: 29th Mar 2010 14:43
1- First you have to check if there is a sprite under the mouse so position a sprite that's 1x1 pixel and transparent under the mouse and check for a collision between that sprite and another one
2- Second you have to check for a mouseclick()
3- Finally Delete the sprite you are colliding with when the first two states are established

Also, try having a go so we can show you what is wrong with your code before posting next time. I'm not meaning to sound rude, you'll just learn more by trying than you will by asking for the code straight away.

Hope that helps!

scuzz
16
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 29th Mar 2010 22:07
thanks a lot, havent tried it yet but i will. and yea i kno what u mean, but i just didnt even kno where to begin so couldnt really code to much
scuzz
16
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 30th Mar 2010 00:04
load bitmap "sky.bmp",0
load image "aim.bmp",1
load image "eyeball1.bmp",2

load image "point.bmp",3

for x = 1 to 75
xpos=rnd(600)
ypos=rnd(600)
sprite 2,xpos,ypos,2
set sprite 2,1,1
paste sprite 2,xpos,ypos
scale sprite 2, 25
next

sync
do
xpos=mousex()-40
ypos=mousey()-40
sprite 1,xpos,ypos,1
set sprite 1,1,1
sprite 3,xpos+38,ypos+38,3
set sprite 3,1,0
scale sprite 3, 25
if sprite collision(3,2) and mouseclick() =1
delete sprite 2
endif

loop

wait key
scuzz
16
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 30th Mar 2010 03:08
^^^^ for some reason the sprite i click on (sprite 2) wont disappear or delete
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 30th Mar 2010 11:39 Edited at: 30th Mar 2010 11:40
Try the attached...

EDIT: Actually I think yours might have worked with less changes but I got carried away...

luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 30th Mar 2010 12:41
@scuzz
Your title have misleading question.You ask how to make object disappear while you need to know how to make sprite to disappear, which is a bit diferent.One more thing, making something to disappear is more like hiding it, and deleting it is actualy destroying it.

You can use "CODE" button when pasting source, and also use Edit, instead of double posting

Where there is a will, there is a way.
I often edit my posts, that`s who i am
scuzz
16
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 30th Mar 2010 22:56
hey thanks a lot this really helped. and Luskos im pretty new to programming so i was basically using the words interchangable, sorry. and how exactly do you use the code button? are you supposed to put you code in the brackets that appear?
scuzz
16
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 30th Mar 2010 23:02
(sorry for the double post still a new user so my message doesnt show up for a couple hours so i cant edit it) but do you think you could tell me what was wrong with my script so i can learn my mistakes? thanks
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 31st Mar 2010 10:22
Quote: "are you supposed to put you code in the brackets that appear?"

Yes.

Quote: "do you think you could tell me what was wrong with my script so i can learn my mistakes?"

Actually I just tried it and all that was wrong was you needed to use "hide sprite" instead of "delete sprite" and it should work...

I'm not a big user of 2D though so there might be a better way to achieve the same result.

Keep coding though it's good fun when you get stuff working nicely!


Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 31st Mar 2010 22:35
To get the best accuracy with sprite collisions, I size my "mouse" sprite to 0,0 just before doing the check. This makes sure the "hotspot" is where I want it to be. As far as deleting the sprite, your earlier post has a loop that [sprite 2,xpos,ypos,2] and [paste sprite 2,xpos,ypos] each loop (BTW you still only have one sprite there; it just shows up multiple times). This does nothing for you except put the same sprite in random locations. When you do the sprite collision check, it will only check the last position of the sprite. If you are wanting several sprites, you need to make them separately and check each of them.

The fastest code is the code never written.
scuzz
16
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 1st Apr 2010 22:32 Edited at: 2nd Apr 2010 01:29
thanks a lot this helps a lot. but do you tnink you could sort of translate the code that the one user posted in response to my original question. what do all the If's mean and how am i supposed to use them? Like, why are there so many "if"s following eachother?

Login to post a reply

Server time is: 2026-07-26 21:10:43
Your offset time is: 2026-07-26 21:10:43