This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-12 14:52:54

Geekish
Scratcher
Registered: 2012-03-10
Posts: 100+

Creating A Joystick

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  big_smile

- Geekish
____________________________________________________________________________  tongue


http://dl.dropbox.com/u/33551365/yesssss.png

Offline

 

#2 2012-03-12 15:08:03

JabberJay
New Scratcher
Registered: 2012-03-05
Posts: 75

Re: Creating A Joystick

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  big_smile

- Geekish
____________________________________________________________________________  tongue

good idea, however i dont know so this will be a learning expirience for both of us: ill see what i can do  big_smile  also you coulf just download the scripts

Offline

 

#3 2012-03-12 15:18:12

Geekish
Scratcher
Registered: 2012-03-10
Posts: 100+

Re: Creating A Joystick

Yh, I looked at a few scripts to investigate how they work.  big_smile


http://dl.dropbox.com/u/33551365/yesssss.png

Offline

 

#4 2012-03-12 15:23:59

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: Creating A Joystick

Hmm... I think you need to explain what type of things are in your project and how you want the joystick to work.

Offline

 

#5 2012-03-12 16:34:55

Geekish
Scratcher
Registered: 2012-03-10
Posts: 100+

Re: Creating A Joystick

Well I want the Joystick to be able to be like a 'magnet for the ball'


http://dl.dropbox.com/u/33551365/yesssss.png

Offline

 

#6 2012-03-12 17:06:17

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Creating A Joystick

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.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#7 2012-04-04 19:06:25

atminnick
Scratcher
Registered: 2011-11-25
Posts: 2

Re: Creating A Joystick

when gf clicked
wait
forever

Offline

 

#8 2012-04-06 15:19:11

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: Creating A Joystick


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#9 2012-04-06 15:51:53

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Creating A Joystick

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

 

Board footer