Module Joyau::StickFollower
In: ruby/site_ruby/joyau/cursor.rb

Joyau has got a Cursor class, which allows to move a sprite via the stick, but this class isn’t a module which can be included in any drawable. Therefore, StickFollower allows to do that, and works pretty much the same way.

Methods

Attributes

area  [RW]  The area in which the object may move.
sensibility  [RW]  If the sensibility is higher, the object moves harder.

Public Instance methods

Configurates the cursor’s attribute

[Source]

# File ruby/site_ruby/joyau/cursor.rb, line 64
    def cursor_conf(sensibility, area = Rect.new(0, 0, 480, 272))
      @sensibility = sensibility
      @area = area
    end

Updates the object’s position, according to the analogic stick’s position.

[Source]

# File ruby/site_ruby/joyau/cursor.rb, line 35
    def update_pos
      Pad.update

      unless @sensibility == 0
        move(Pad.stickX / @sensibility, Pad.stickY / @sensibility);

        if self.x > (@area.x + @area.w)
          x_pos = @area.x + @area.w
        elsif self.x < @area.x
          x_pos = @area.x
        else
          x_pos = self.x
        end
        
        if self.y > (@area.y + @area.h)
          y_pos = @area.y + @area.h
        elsif self.y < @area.y
          y_pos = @area.y
        else
          y_pos = self.y
        end

        setPos(x_pos, y_pos)
      end
    end

[Validate]