Im making a new dress up game, not the boring usual kind either so...
I was just wondering how to make it so when you click a clothing item (click it once, not drag it) you can pick it up, when you click again, you put it down. and you can carry on picking it up and putting it down throughout the whole game.
There are many items and i only want each one to move if i click on that ONE.
=]
Offline
I've got a technique I've used that makes use of a variable called Selected that I define for each sprite (not for all sprites). The code to pick up the sprite then looks like
When Sprite Clicked
Set Selected to 1 - Selected (this toggles the value between 1 and zero)
Wait 0.01 Seconds (let things settle down a bit)
If Selected = 1
Repeat Until Selected = 0
Goto Mousepointer
If you want things to happen after the sprite is released from the mouse, you can put an ELSE branch on the IF statement and handle them there. Good luck!
Offline
Snowberry23, it sounds like you want code like I used in my MasterMind game:
http://scratch.mit.edu/projects/kevin_karplus/12236
Try downloading that and looking at how the pegs are moved.
Offline
Paddle2See wrote:
I've got a technique I've used that makes use of a variable called Selected that I define for each sprite (not for all sprites). The code to pick up the sprite then looks like
When Sprite Clicked
Set Selected to 1 - Selected (this toggles the value between 1 and zero)
Wait 0.01 Seconds (let things settle down a bit)
If Selected = 1
Repeat Until Selected = 0
Goto Mousepointer
If you want things to happen after the sprite is released from the mouse, you can put an ELSE branch on the IF statement and handle them there. Good luck!
Thanks, that works for picking up the items, but i cant place them down on the character.
Offline
Hmmm, it works when I try it. Can you upload the project so I can take a look at it? You have to click again to put it down, but you probably already knew that.
Offline
Just realized that the code can be simplifed even further if you aren't doing anything special when you release the object. You don't even need the IF statement. It also looks like the Wait statement isn't really necessary. The code is then just
When Sprite Clicked
Set Selected to 1 - Selected (this toggles the value between 1 and zero)
Repeat Until Selected = 0
Goto Mousepointer
Of course if you want to make sure the object lines up perfectly with the person underneath, you might want to keep the IF and add some logic to reposition the object where it is supposed to go. That gets a little more complicated.
Last edited by Paddle2See (2008-01-23 16:05:27)
Offline
Paddle2See wrote:
Just realized that the code can be simplifed even further if you aren't doing anything special when you release the object. You don't even need the IF statement. It also looks like the Wait statement isn't really necessary. The code is then just
When Sprite Clicked
Set Selected to 1 - Selected (this toggles the value between 1 and zero)
Repeat Until Selected = 0
Goto Mousepointer
Of course if you want to make sure the object lines up perfectly with the person underneath, you might want to keep the IF and add some logic to reposition the object where it is supposed to go. That gets a little more complicated.
How does "selected" change from 1 back to zero to the item doesnt move anymore?
Offline
When you click the mouse again (with the object dangling off of the mouse pointer), it generates another When Clicked event so the (Selected = 1 - Selected) equation results in Selected becoming zero. This stops the Until loop and releases the object. Maybe you don't have the
set Selected = 1- Selected
coded correctly?
[kevin_karplus: fixed typo in set statement.]
Last edited by kevin_karplus (2008-01-23 19:57:27)
Offline