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 / Clicking on one sprite to reveal another - code not working!

Author
Message
Magnolia
15
Years of Service
User Offline
Joined: 19th Jan 2009
Location: New Jersey
Posted: 26th Mar 2009 21:58
Hi guys,

I'm trying to create a code in which when sprite 1 is clicked on, sprite 2 is displayed.

I've written the following code:



The first sprite displays fine, but when I click on it, nothing happens. Can anyone shed any light?

Thanks!
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 26th Mar 2009 23:42
How about load the sprites at the beginning of the program, and show sprite 1 and hide sprite 2. Then call the function, and when sprite 1 is clicked, hide sprite 1 and show sprite 2, and throw in a wait somewhere, because it will be going really fast.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 27th Mar 2009 00:30
Maybe I don't understand fully, but what does the line notebookmode: do?
Have you tried putting a Print command both sides of that line (or removing it completely) to see what happens?
GIDustin
16
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 27th Mar 2009 00:59 Edited at: 27th Mar 2009 01:04
Your click condition might be redone:

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

Is this function called in a loop? If not, it is only checking for a click the instant after it is created, and then ending the function.

(Edited to hide my own stupidity...)
Tom0001
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location:
Posted: 28th Mar 2009 20:18 Edited at: 28th Mar 2009 20:25
- Grumble, grumble. - Look, here, this should work:
Also note -- obviously it's not being executed in a DO, LOOP because if it was, then you would have gotten an error message about loading the images, stating that it has already been loaded in. In other words, you should load all images and crap at the start of your program if you ask me. >/



There. This code should place both sprites in the middle of the screen, with one hidden and the other showing. Simply click it to have the image change, then click it again to have it change back. If you want it to simply change back after you stop holding the mouse, then just modify it accordingly. I trust you know how to do so, by now.

Hope this helps,

Tom

Login to post a reply

Server time is: 2024-11-25 08:20:52
Your offset time is: 2024-11-25 08:20:52