On Scratch there have been many joystick projects, and I was wondering if anyone knew how to create/program them, I was thinking of creating a joystick maze or puzzle or something like that, but don't have a clue how they work. Help would be well appreciated
- Geekish
____________________________________________________________________________

Offline
Geekish wrote:
On Scratch there have been many joystick projects, and I was wondering if anyone knew how to create/program them, I was thinking of creating a joystick maze or puzzle or something like that, but don't have a clue how they work. Help would be well appreciated
![]()
- Geekish
____________________________________________________________________________![]()
good idea, however i dont know so this will be a learning expirience for both of us: ill see what i can do
also you coulf just download the scripts
Offline
Hmm... I think you need to explain what type of things are in your project and how you want the joystick to work.
Offline
Have a drag script for the ball. When it is dragged, subtract it's x/y from the original x/y. The difference is the direction.
Offline
got a perfect one!
http://scratch.mit.edu/projects/chip_tester/2451681
Offline
Here's an example script I just came up with. CAUTION: It hasn't been tested yet.
You would then in your other scripts use joystick_x_output and joystick_y_output to control the character's motion.
when gf clicked // For Joystick sprite.
forever
if <mouse down?> // Only drag the joystick if you click it first.
if <<<touching [mouse-pointer v]?> and <(can_drag) = [true]>> and <(dragging) = [false]>>
set [x_offset v] to ((mouse x) - (x position))
set [y_offset v] to ((mouse y) - (y position))
set [dragging? v] to [true]
else
set [can_drag? v] to [false]
end
else
set [can_drag? v] to [true]
set [dragging? v] to [false]
end
if <(dragging?) = [true]>
set x to ((mouse x) - (x_offset))
set y to ((mouse y) - (y_offset))
set [joystick_x_output v] to (x position)
set [joystick_y_output v] to (y position)
broadcast [joystick update v] and wait
else
go to x: [0] y: [0]
set [joystick_x_output v] to [0]
set [joystick_y_output v] to [0]
end
end
when I receive [joystick update v] // For the sprite in the maze.
change x by ((joystick_x_output) / [10])
change y by ((joystick_y_output) / [10])
Last edited by amcerbu (2012-04-06 18:22:18)
Offline