Class: RubySketch::Sprite
- Inherits:
-
Object
- Object
- RubySketch::Sprite
- Includes:
- Xot::Inspectable
- Defined in:
- lib/rubysketch/sprite.rb
Overview
Sprite object.
Instance Method Summary collapse
-
#angle ⇒ Numeric
Returns the rotation angle of the sprite.
-
#angle=(angle) ⇒ Numeric
Sets the rotation angle of the sprite.
-
#angleFixed? ⇒ Boolean
Returns the angle of the sprite is fixed or not.
-
#bottom ⇒ Numeric
Returns the bottom position of the sprite.
-
#bottom=(n) ⇒ Numeric
Set the bottom position of the sprite.
-
#capture=(bool) ⇒ Boolean
Captures key and mouse events.
-
#capturing? ⇒ Boolean
Returns whether to capture or not.
-
#center ⇒ Vector
Returns the center position of the sprite.
-
#center=(arg) ⇒ Vector
Sets the center position of the sprite.
-
#chase(*args, **options, &block) ⇒ ChaseConstraint
Creates a constraint that moves the sprite toward the target every frame.
-
#clickCount ⇒ Numeric
Returns the mouse button click count on the sprite.
-
#constraints ⇒ Array<Constraint>
Returns the constraints fastened to the sprite.
-
#contact(&block) ⇒ nil
Defines contact block.
-
#contact?(&block) ⇒ nil
Defines contact? block.
-
#contactEnd(&block) ⇒ nil
Defines contactEnd block.
-
#density ⇒ Numeric
(also: #dens)
Returns the density of the sprite.
-
#density=(n) ⇒ Numeric
(also: #dens=)
Sets the density of the sprite.
-
#draw(&block) ⇒ nil
Defines draw block.
-
#dynamic=(bool) ⇒ Boolean
Sets whether the sprite is movable by the physics engine.
-
#dynamic? ⇒ Boolean
Returns whether the sprite is movable by the physics engine.
-
#fixAngle(fix = true) ⇒ Sprite
Fixes the angle of the sprite.
-
#friction ⇒ Numeric
(also: #fric)
Returns the friction of the sprite.
-
#friction=(n) ⇒ Numeric
(also: #fric=)
Sets the friction of the sprite.
-
#fromScreen(vec) ⇒ Vector
Converts a vector from the screen coordinate.
-
#gravity_scale ⇒ Object
deprecated
Deprecated.
Use #gravityScale instead.
-
#gravity_scale=(scale) ⇒ Object
deprecated
Deprecated.
Use #gravityScale= instead.
-
#gravityScale ⇒ Numeric
Returns the gravity scale of the sprite.
-
#gravityScale=(scale) ⇒ Numeric
Sets the gravity scale of the sprite.
-
#height ⇒ Numeric
(also: #h)
Returns the height of the sprite.
-
#height=(h) ⇒ Numeric
(also: #h=)
Sets the height of the sprite.
-
#hidden? ⇒ Boolean
Returns the sprite is visible.
-
#hide ⇒ Sprite
Hides the sprite.
-
#image ⇒ Image
Returns the image of the sprite.
-
#image=(img) ⇒ Image
Sets the sprite image.
-
#initialize(x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil, shape: nil, physics: true) ⇒ Sprite
constructor
Initialize sprite object.
-
#key ⇒ String
Returns the last key that was pressed or released.
-
#keyCode ⇒ Symbol
Returns the last key code that was pressed or released.
-
#keyIsDown(keyCode) ⇒ Boolean
Returns whether or not the key is currently pressed.
-
#keyIsPressed ⇒ Boolean
Returns whether or not any key is pressed.
-
#keyIsRepeated ⇒ Boolean
Returns whether the current key is repeated or not.
-
#keyPressed(&block) ⇒ Boolean
Defines keyPressed block.
-
#keyReleased(&block) ⇒ nil
Defines keyReleased block.
-
#keyTyped(&block) ⇒ nil
Defines keyTyped block.
-
#left ⇒ Numeric
Returns the left position of the sprite.
-
#left=(n) ⇒ Numeric
Set the left position of the sprite.
-
#link(*args, **options, &block) ⇒ LinkConstraint
Creates a constraint that keeps the distance between the center of the sprite and the target point.
-
#mouseButton ⇒ LEFT, ...
Returns the mouse button clicked on the sprite.
-
#mouseClicked(&block) ⇒ nil
Defines mouseClicked block.
-
#mouseDragged(&block) ⇒ nil
Defines mouseDragged block.
-
#mouseMoved(&block) ⇒ nil
Defines mouseMoved block.
-
#mouseOut(&block) ⇒ nil
Defines mouseOut block.
-
#mouseOver(&block) ⇒ Boolean
Defines mouseOver block.
-
#mousePressed(&block) ⇒ Boolean
Defines mousePressed block.
-
#mouseReleased(&block) ⇒ nil
Defines mouseReleased block.
-
#mouseWheel(&block) ⇒ nil
Defines mouseWheel block.
-
#mouseX ⇒ Numeric
Returns the x-position of the mouse in the sprite coordinates.
-
#mouseY ⇒ Numeric
Returns the y-position of the mouse in the sprite coordinates.
-
#offset ⇒ Vector
Returns the offset of the sprite image.
-
#offset=(arg) ⇒ Vector
Sets the offset of the sprite image.
-
#ox ⇒ Numeric
Returns the x-axis offset of the sprite image.
-
#ox=(x) ⇒ Numeric
Sets the x-axis offset of the sprite image.
-
#oy ⇒ Numeric
Returns the y-axis offset of the sprite image.
-
#oy=(y) ⇒ Numeric
Sets the y-axis offset of the sprite image.
-
#pin(x = nil, y = nil) ⇒ Pin
Creates a pin that fastens a point on the sprite.
-
#pivot ⇒ Array<Numeric>
Returns the rotation center of the sprite.
-
#pivot=(array) ⇒ Array<Numeric>
Sets the rotation center of the sprite.
-
#pmouseX ⇒ Numeric
Returns the previous x-position of the mouse in the sprite coordinates.
-
#pmouseY ⇒ Numeric
Returns the previous y-position of the mouse in the sprite coordinates.
-
#position ⇒ Vector
(also: #pos)
Returns the position of the sprite.
-
#position=(arg) ⇒ Vector
(also: #pos=)
Sets the position of the sprite.
-
#restitution ⇒ Numeric
(also: #rest)
Returns the restitution of the sprite.
-
#restitution=(n) ⇒ Numeric
(also: #rest=)
Sets the restitution of the sprite.
-
#right ⇒ Numeric
Returns the right position of the sprite.
-
#right=(n) ⇒ Numeric
Set the right position of the sprite.
-
#sensor=(state) ⇒ Boolean
Set this sprite as a sensor object.
-
#sensor? ⇒ Boolean
Returns whether the shape is a sensor or not.
-
#show ⇒ Sprite
Shows the sprite.
-
#size ⇒ Vector
Returns the size of the sprite.
-
#size=(arg) ⇒ Vector
Sets the size of the sprite.
-
#snap(*args, **options, &block) ⇒ SnapConstraint
Creates a constraint that makes the center of the sprite and the target point coincide.
-
#top ⇒ Numeric
Returns the top position of the sprite.
-
#top=(n) ⇒ Numeric
Set the top position of the sprite.
-
#toScreen(vec) ⇒ Vector
Converts a vector to the screen coordinate.
-
#touchEnded(&block) ⇒ nil
Defines touchEnded block.
-
#touches ⇒ Array<Touch>
Returns the touch objects touched on the sprite.
-
#touchMoved(&block) ⇒ nil
Defines touchMoved block.
-
#touchStarted(&block) ⇒ nil
Defines touchStarted block.
-
#update(&block) ⇒ nil
Defines update block.
-
#velocity ⇒ Vector
(also: #vel)
Returns the velocity of the sprite.
-
#velocity=(arg) ⇒ Vector
(also: #vel=)
Sets the velocity of the sprite.
-
#vx ⇒ Numeric
Returns the x-axis velocity of the sprite.
-
#vx=(n) ⇒ Numeric
Sets the x-axis velocity of the sprite.
-
#vy ⇒ Numeric
Returns the y-axis velocity of the sprite.
-
#vy=(n) ⇒ Numeric
Sets the y-axis velocity of the sprite.
-
#wheel(*args, **options, &block) ⇒ WheelConstraint
Creates a constraint that makes the sprite ride on the target like a wheel: it slides along an axis for the suspension and spins freely.
-
#width ⇒ Numeric
(also: #w)
Returns the width of the sprite.
-
#width=(w) ⇒ Numeric
(also: #w=)
Sets the width of the sprite.
-
#x ⇒ Numeric
Returns the x-coordinate position of the sprite.
-
#x=(n) ⇒ Numeric
Set the x-coordinate position of the sprite.
-
#y ⇒ Numeric
Returns the y-coordinate position of the sprite.
-
#y=(n) ⇒ Numeric
Set the y-coordinate position of the sprite.
-
#z ⇒ Numeric
Returns the z-coordinate position of the sprite.
-
#z=(n) ⇒ Numeric
Set the z-coordinate position of the sprite.
Constructor Details
#new(x, y, w, h) ⇒ Sprite #new(image: img) ⇒ Sprite #new(x, y, image: img) ⇒ Sprite #new(x, y, image: img, offset: off) ⇒ Sprite #new(x, y, image: img, shape: shp) ⇒ Sprite #new(x, y, image: img, offset: off, shape: shp) ⇒ Sprite #new(x, y, shape: shp) ⇒ Sprite
Initialize sprite object.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rubysketch/sprite.rb', line 56 def initialize( x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil, shape: nil, physics: true) w ||= (image&.width || shape&.width || 0) h ||= (image&.height || shape&.height || 0) raise 'invalid size' unless w >= 0 && h >= 0 raise 'invalid image' if image && !image.getInternal__.is_a?(Rays::Image) raise 'invalid shape' if shape && !shape.getInternal__.is_a?(Reflex::Shape) @world__ = nil @shape__ = shape @view__ = View.new( self, x: x, y: y, w: w, h: h, shape: @shape__, physics: physics, back: :white) @view__.set density: 1, friction: 0, restitution: 0 self.image = image if image self.offset = offset if offset end |
Instance Method Details
#angle ⇒ Numeric
Returns the rotation angle of the sprite.
363 364 365 |
# File 'lib/rubysketch/sprite.rb', line 363 def angle() getContext__.fromDegrees__ @view__.angle end |
#angle=(angle) ⇒ Numeric
Sets the rotation angle of the sprite.
373 374 375 376 |
# File 'lib/rubysketch/sprite.rb', line 373 def angle=(angle) @view__.angle = getContext__.toDegrees__ angle angle end |
#angleFixed? ⇒ Boolean
Returns the angle of the sprite is fixed or not.
393 394 395 |
# File 'lib/rubysketch/sprite.rb', line 393 def angleFixed?() @view__.fix_angle? end |
#bottom ⇒ Numeric
Returns the bottom position of the sprite.
263 264 265 |
# File 'lib/rubysketch/sprite.rb', line 263 def bottom() @view__.bottom end |
#bottom=(n) ⇒ Numeric
Set the bottom position of the sprite.
273 274 275 |
# File 'lib/rubysketch/sprite.rb', line 273 def bottom=(n) @view__.bottom = n end |
#capture=(bool) ⇒ Boolean
Captures key and mouse events
112 113 114 115 |
# File 'lib/rubysketch/sprite.rb', line 112 def capture=(bool) @view__.capture = bool ? :all : [] bool end |
#capturing? ⇒ Boolean
Returns whether to capture or not
121 122 123 |
# File 'lib/rubysketch/sprite.rb', line 121 def capturing?() @view__.capturing? end |
#center ⇒ Vector
Returns the center position of the sprite.
281 282 283 |
# File 'lib/rubysketch/sprite.rb', line 281 def center() Vector.new(x + w / 2, y + h / 2, z) end |
#center=(vec) ⇒ Vector #center=(ary) ⇒ Vector
Sets the center position of the sprite.
295 296 297 298 299 |
# File 'lib/rubysketch/sprite.rb', line 295 def center=(arg) x, y = *(arg.is_a?(Vector) ? arg.getInternal__.to_a : arg) self.pos = [x - w / 2, y - h / 2, z] self.center end |
#chase(*args, **options, &block) ⇒ ChaseConstraint
Creates a constraint that moves the sprite toward the target every frame.
750 751 752 |
# File 'lib/rubysketch/sprite.rb', line 750 def chase(*args, **, &block) pin.chase(*args, **, &block) end |
#clickCount ⇒ Numeric
Returns the mouse button click count on the sprite.
868 869 870 |
# File 'lib/rubysketch/sprite.rb', line 868 def clickCount() @view__.clickCount end |
#constraints ⇒ Array<Constraint>
Returns the constraints fastened to the sprite.
758 759 760 |
# File 'lib/rubysketch/sprite.rb', line 758 def constraints() @view__.constraints.map {|c| Constraint.wrap__ c} end |
#contact(&block) ⇒ nil
Defines contact block.
1100 1101 1102 1103 |
# File 'lib/rubysketch/sprite.rb', line 1100 def contact(&block) @view__.contact = block if block nil end |
#contact?(&block) ⇒ nil
Defines contact? block.
1128 1129 1130 1131 |
# File 'lib/rubysketch/sprite.rb', line 1128 def contact?(&block) @view__.willContact = block if block nil end |
#contactEnd(&block) ⇒ nil
Defines contactEnd block.
1114 1115 1116 1117 |
# File 'lib/rubysketch/sprite.rb', line 1114 def contactEnd(&block) @view__.contactEnd = block if block nil end |
#density ⇒ Numeric Also known as: dens
Returns the density of the sprite.
584 585 586 |
# File 'lib/rubysketch/sprite.rb', line 584 def density() @view__.density end |
#density=(n) ⇒ Numeric Also known as: dens=
Sets the density of the sprite.
594 595 596 |
# File 'lib/rubysketch/sprite.rb', line 594 def density=(n) @view__.density = n end |
#draw(&block) ⇒ nil
Defines draw block.
905 906 907 908 |
# File 'lib/rubysketch/sprite.rb', line 905 def draw(&block) @drawBlock__ = block if block nil end |
#dynamic=(bool) ⇒ Boolean
Sets whether the sprite is movable by the physics engine.
576 577 578 |
# File 'lib/rubysketch/sprite.rb', line 576 def dynamic=(bool) @view__.dynamic = bool end |
#dynamic? ⇒ Boolean
Returns whether the sprite is movable by the physics engine.
566 567 568 |
# File 'lib/rubysketch/sprite.rb', line 566 def dynamic?() @view__.dynamic? end |
#fixAngle(fix = true) ⇒ Sprite
Fixes the angle of the sprite.
384 385 386 387 |
# File 'lib/rubysketch/sprite.rb', line 384 def fixAngle(fix = true) @view__.fix_angle = fix self end |
#friction ⇒ Numeric Also known as: fric
Returns the friction of the sprite.
602 603 604 |
# File 'lib/rubysketch/sprite.rb', line 602 def friction() @view__.friction end |
#friction=(n) ⇒ Numeric Also known as: fric=
Sets the friction of the sprite.
612 613 614 |
# File 'lib/rubysketch/sprite.rb', line 612 def friction=(n) @view__.friction = n end |
#fromScreen(vec) ⇒ Vector
Converts a vector from the screen coordinate
768 769 770 |
# File 'lib/rubysketch/sprite.rb', line 768 def fromScreen(vec) @view__.from_parent(vec.getInternal__).toVector end |
#gravity_scale ⇒ Object
Use #gravityScale instead.
683 684 685 686 |
# File 'lib/rubysketch/sprite.rb', line 683 def gravity_scale() Xot.warn "Sprite#gravity_scale is deprecated, use #gravityScale instead", uniq: true gravityScale end |
#gravity_scale=(scale) ⇒ Object
Use #gravityScale= instead.
677 678 679 680 |
# File 'lib/rubysketch/sprite.rb', line 677 def gravity_scale=(scale) Xot.warn "Sprite#gravity_scale= is deprecated, use #gravityScale= instead", uniq: true self.gravityScale = scale end |
#gravityScale ⇒ Numeric
Returns the gravity scale of the sprite.
672 673 674 |
# File 'lib/rubysketch/sprite.rb', line 672 def gravityScale() @view__.gravity_scale end |
#gravityScale=(scale) ⇒ Numeric
Sets the gravity scale of the sprite.
664 665 666 |
# File 'lib/rubysketch/sprite.rb', line 664 def gravityScale=(scale) @view__.gravity_scale = scale end |
#height ⇒ Numeric Also known as: h
Returns the height of the sprite.
340 341 342 |
# File 'lib/rubysketch/sprite.rb', line 340 def height() @view__.height end |
#height=(h) ⇒ Numeric Also known as: h=
Sets the height of the sprite.
350 351 352 |
# File 'lib/rubysketch/sprite.rb', line 350 def height=(h) @view__.height = h end |
#hidden? ⇒ Boolean
Returns the sprite is visible
102 103 104 |
# File 'lib/rubysketch/sprite.rb', line 102 def hidden?() @view__.hidden? end |
#hide ⇒ Sprite
Hides the sprite
Since one call to "hide()" increases the hide count, it is necessary to call "show()" n times to make the sprite visible again after calling "hide()" n times.
93 94 95 96 |
# File 'lib/rubysketch/sprite.rb', line 93 def hide() @view__.hide self end |
#image ⇒ Image
Returns the image of the sprite.
483 484 485 |
# File 'lib/rubysketch/sprite.rb', line 483 def image() @image__ end |
#image=(img) ⇒ Image
Sets the sprite image.
493 494 495 |
# File 'lib/rubysketch/sprite.rb', line 493 def image=(img) @image__ = img end |
#key ⇒ String
Returns the last key that was pressed or released.
786 787 788 |
# File 'lib/rubysketch/sprite.rb', line 786 def key() @view__.key end |
#keyCode ⇒ Symbol
Returns the last key code that was pressed or released.
794 795 796 |
# File 'lib/rubysketch/sprite.rb', line 794 def keyCode() @view__.keyCode end |
#keyIsDown(keyCode) ⇒ Boolean
Returns whether or not the key is currently pressed.
812 813 814 |
# File 'lib/rubysketch/sprite.rb', line 812 def keyIsDown(keyCode) @view__.keysPressed.include? keyCode end |
#keyIsPressed ⇒ Boolean
Returns whether or not any key is pressed.
802 803 804 |
# File 'lib/rubysketch/sprite.rb', line 802 def keyIsPressed() not @view__.keysPressed.empty? end |
#keyIsRepeated ⇒ Boolean
Returns whether the current key is repeated or not.
820 821 822 |
# File 'lib/rubysketch/sprite.rb', line 820 def keyIsRepeated() @view__.keyRepeat end |
#keyPressed(&block) ⇒ Boolean
Defines keyPressed block.
914 915 916 917 |
# File 'lib/rubysketch/sprite.rb', line 914 def keyPressed(&block) setViewBlock__ :keyPressed, block if block keyIsPressed end |
#keyReleased(&block) ⇒ nil
Defines keyReleased block.
923 924 925 926 |
# File 'lib/rubysketch/sprite.rb', line 923 def keyReleased(&block) setViewBlock__ :keyReleased, block if block nil end |
#keyTyped(&block) ⇒ nil
Defines keyTyped block.
932 933 934 935 |
# File 'lib/rubysketch/sprite.rb', line 932 def keyTyped(&block) setViewBlock__ :keyTyped, block if block nil end |
#left ⇒ Numeric
Returns the left position of the sprite.
209 210 211 |
# File 'lib/rubysketch/sprite.rb', line 209 def left() @view__.left end |
#left=(n) ⇒ Numeric
Set the left position of the sprite.
219 220 221 |
# File 'lib/rubysketch/sprite.rb', line 219 def left=(n) @view__.left = n end |
#link(*args, **options, &block) ⇒ LinkConstraint
Creates a constraint that keeps the distance between the center of the sprite and the target point.
724 725 726 |
# File 'lib/rubysketch/sprite.rb', line 724 def link(*args, **, &block) pin.link(*args, **, &block) end |
#mouseButton ⇒ LEFT, ...
Returns the mouse button clicked on the sprite.
860 861 862 |
# File 'lib/rubysketch/sprite.rb', line 860 def mouseButton() @view__.mouseButton end |
#mouseClicked(&block) ⇒ nil
Defines mouseClicked block.
1002 1003 1004 1005 |
# File 'lib/rubysketch/sprite.rb', line 1002 def mouseClicked(&block) setViewBlock__ :mouseClicked, block if block nil end |
#mouseDragged(&block) ⇒ nil
Defines mouseDragged block.
988 989 990 991 |
# File 'lib/rubysketch/sprite.rb', line 988 def mouseDragged(&block) setViewBlock__ :mouseDragged, block if block nil end |
#mouseMoved(&block) ⇒ nil
Defines mouseMoved block.
974 975 976 977 |
# File 'lib/rubysketch/sprite.rb', line 974 def mouseMoved(&block) setViewBlock__ :mouseMoved, block if block nil end |
#mouseOut(&block) ⇒ nil
Defines mouseOut block.
1030 1031 1032 1033 |
# File 'lib/rubysketch/sprite.rb', line 1030 def mouseOut(&block) setViewBlock__ :mouseOut, block if block nil end |
#mouseOver(&block) ⇒ Boolean
Defines mouseOver block.
1016 1017 1018 1019 |
# File 'lib/rubysketch/sprite.rb', line 1016 def mouseOver(&block) setViewBlock__ :mouseOver, block if block @view__.mouseOver? end |
#mousePressed(&block) ⇒ Boolean
Defines mousePressed block.
946 947 948 949 |
# File 'lib/rubysketch/sprite.rb', line 946 def mousePressed(&block) setViewBlock__ :mousePressed, block if block @view__.mousePressed? end |
#mouseReleased(&block) ⇒ nil
Defines mouseReleased block.
960 961 962 963 |
# File 'lib/rubysketch/sprite.rb', line 960 def mouseReleased(&block) setViewBlock__ :mouseReleased, block if block nil end |
#mouseWheel(&block) ⇒ nil
Defines mouseWheel block.
1044 1045 1046 1047 |
# File 'lib/rubysketch/sprite.rb', line 1044 def mouseWheel(&block) setViewBlock__ :mouseWheel, block if block nil end |
#mouseX ⇒ Numeric
Returns the x-position of the mouse in the sprite coordinates.
828 829 830 |
# File 'lib/rubysketch/sprite.rb', line 828 def mouseX() @view__.mouseX end |
#mouseY ⇒ Numeric
Returns the y-position of the mouse in the sprite coordinates.
836 837 838 |
# File 'lib/rubysketch/sprite.rb', line 836 def mouseY() @view__.mouseY end |
#offset ⇒ Vector
Returns the offset of the sprite image.
501 502 503 |
# File 'lib/rubysketch/sprite.rb', line 501 def offset() @offset__ end |
#offset=(vec) ⇒ Vector #offset=(ary) ⇒ Vector
Sets the offset of the sprite image.
515 516 517 518 519 520 521 522 523 524 |
# File 'lib/rubysketch/sprite.rb', line 515 def offset=(arg) @offset__ = case arg when Vector then arg when Array then Vector.new(arg[0] || 0, arg[1] || 0) when nil then nil else raise ArgumentError end offset end |
#ox ⇒ Numeric
Returns the x-axis offset of the sprite image.
530 531 532 |
# File 'lib/rubysketch/sprite.rb', line 530 def ox() @offset__&.x || 0 end |
#ox=(x) ⇒ Numeric
Sets the x-axis offset of the sprite image.
540 541 542 |
# File 'lib/rubysketch/sprite.rb', line 540 def ox=(x) self.offset = [x, oy] end |
#oy ⇒ Numeric
Returns the y-axis offset of the sprite image.
548 549 550 |
# File 'lib/rubysketch/sprite.rb', line 548 def oy() @offset__&.y || 0 end |
#oy=(y) ⇒ Numeric
Sets the y-axis offset of the sprite image.
558 559 560 |
# File 'lib/rubysketch/sprite.rb', line 558 def oy=(y) self.offset = [ox, y] end |
#pin ⇒ Pin #pin(x, y) ⇒ Pin
Creates a pin that fastens a point on the sprite.
698 699 700 |
# File 'lib/rubysketch/sprite.rb', line 698 def pin(x = nil, y = nil) Pin.new self, x, y end |
#pivot ⇒ Array<Numeric>
Returns the rotation center of the sprite.
401 402 403 |
# File 'lib/rubysketch/sprite.rb', line 401 def pivot() @view__.pivot.to_a[0, 2] end |
#pivot=(array) ⇒ Array<Numeric>
Sets the rotation center of the sprite. [0.0, 0.0] is the left-top, [1.0, 1.0] is the right-bottom, and [0.5, 0.5] is the center.
412 413 414 415 |
# File 'lib/rubysketch/sprite.rb', line 412 def pivot=(array) @view__.pivot = array pivot end |
#pmouseX ⇒ Numeric
Returns the previous x-position of the mouse in the sprite coordinates.
844 845 846 |
# File 'lib/rubysketch/sprite.rb', line 844 def pmouseX() @view__.pmouseX end |
#pmouseY ⇒ Numeric
Returns the previous y-position of the mouse in the sprite coordinates.
852 853 854 |
# File 'lib/rubysketch/sprite.rb', line 852 def pmouseY() @view__.pmouseY end |
#position ⇒ Vector Also known as: pos
Returns the position of the sprite.
129 130 131 |
# File 'lib/rubysketch/sprite.rb', line 129 def position() @view__.position.toVector end |
#position=(vec) ⇒ Vector #position=(ary) ⇒ Vector Also known as: pos=
Sets the position of the sprite.
143 144 145 146 |
# File 'lib/rubysketch/sprite.rb', line 143 def position=(arg) @view__.position = arg.is_a?(Vector) ? arg.getInternal__ : arg arg end |
#restitution ⇒ Numeric Also known as: rest
Returns the restitution of the sprite.
620 621 622 |
# File 'lib/rubysketch/sprite.rb', line 620 def restitution() @view__.restitution end |
#restitution=(n) ⇒ Numeric Also known as: rest=
Sets the restitution of the sprite.
630 631 632 |
# File 'lib/rubysketch/sprite.rb', line 630 def restitution=(n) @view__.restitution = n end |
#right ⇒ Numeric
Returns the right position of the sprite.
245 246 247 |
# File 'lib/rubysketch/sprite.rb', line 245 def right() @view__.right end |
#right=(n) ⇒ Numeric
Set the right position of the sprite.
255 256 257 |
# File 'lib/rubysketch/sprite.rb', line 255 def right=(n) @view__.right = n end |
#sensor=(state) ⇒ Boolean
Set this sprite as a sensor object. Sensor object receives contact events, but no collisions.
646 647 648 |
# File 'lib/rubysketch/sprite.rb', line 646 def sensor=(state) @view__.sensor = state end |
#sensor? ⇒ Boolean
Returns whether the shape is a sensor or not.
654 655 656 |
# File 'lib/rubysketch/sprite.rb', line 654 def sensor?() @view__.sensor? end |
#show ⇒ Sprite
Shows the sprite
Since one call to "hide()" increases the hide count, it is necessary to call "show()" n times to make the sprite visible again after calling "hide()" n times.
82 83 84 85 |
# File 'lib/rubysketch/sprite.rb', line 82 def show() @view__.show self end |
#size ⇒ Vector
Returns the size of the sprite.
305 306 307 |
# File 'lib/rubysketch/sprite.rb', line 305 def size() @view__.size.toVector end |
#size=(arg) ⇒ Vector
Sets the size of the sprite.
313 314 315 316 |
# File 'lib/rubysketch/sprite.rb', line 313 def size=(arg) @view__.size = arg.is_a?(Vector) ? arg.getInternal__ : arg arg end |
#snap(*args, **options, &block) ⇒ SnapConstraint
Creates a constraint that makes the center of the sprite and the target point coincide.
711 712 713 |
# File 'lib/rubysketch/sprite.rb', line 711 def snap(*args, **, &block) pin.snap(*args, **, &block) end |
#top ⇒ Numeric
Returns the top position of the sprite.
227 228 229 |
# File 'lib/rubysketch/sprite.rb', line 227 def top() @view__.top end |
#top=(n) ⇒ Numeric
Set the top position of the sprite.
237 238 239 |
# File 'lib/rubysketch/sprite.rb', line 237 def top=(n) @view__.top = n end |
#toScreen(vec) ⇒ Vector
Converts a vector to the screen coordinate
778 779 780 |
# File 'lib/rubysketch/sprite.rb', line 778 def toScreen(vec) @view__.to_parent(vec.getInternal__).toVector end |
#touchEnded(&block) ⇒ nil
Defines touchEnded block.
1072 1073 1074 1075 |
# File 'lib/rubysketch/sprite.rb', line 1072 def touchEnded(&block) setViewBlock__ :touchEnded, block if block nil end |
#touches ⇒ Array<Touch>
Returns the touch objects touched on the sprite.
876 877 878 |
# File 'lib/rubysketch/sprite.rb', line 876 def touches() @view__.touches end |
#touchMoved(&block) ⇒ nil
Defines touchMoved block.
1086 1087 1088 1089 |
# File 'lib/rubysketch/sprite.rb', line 1086 def touchMoved(&block) setViewBlock__ :touchMoved, block if block nil end |
#touchStarted(&block) ⇒ nil
Defines touchStarted block.
1058 1059 1060 1061 |
# File 'lib/rubysketch/sprite.rb', line 1058 def touchStarted(&block) setViewBlock__ :touchStarted, block if block nil end |
#update(&block) ⇒ nil
Defines update block.
889 890 891 892 |
# File 'lib/rubysketch/sprite.rb', line 889 def update(&block) @view__.update = block if block nil end |
#velocity ⇒ Vector Also known as: vel
Returns the velocity of the sprite.
421 422 423 |
# File 'lib/rubysketch/sprite.rb', line 421 def velocity() @view__.velocity.toVector end |
#velocity=(vec) ⇒ Vector #velocity=(ary) ⇒ Vector Also known as: vel=
Sets the velocity of the sprite.
435 436 437 438 |
# File 'lib/rubysketch/sprite.rb', line 435 def velocity=(arg) @view__.velocity = arg.is_a?(Vector) ? arg.getInternal__ : arg arg end |
#vx ⇒ Numeric
Returns the x-axis velocity of the sprite.
444 445 446 |
# File 'lib/rubysketch/sprite.rb', line 444 def vx() @view__.velocity.x end |
#vx=(n) ⇒ Numeric
Sets the x-axis velocity of the sprite.
454 455 456 |
# File 'lib/rubysketch/sprite.rb', line 454 def vx=(n) @view__.velocity = @view__.velocity.tap {|v| v.x = n} end |
#vy ⇒ Numeric
Returns the y-axis velocity of the sprite.
462 463 464 |
# File 'lib/rubysketch/sprite.rb', line 462 def vy() @view__.velocity.y end |
#vy=(n) ⇒ Numeric
Sets the y-axis velocity of the sprite.
472 473 474 |
# File 'lib/rubysketch/sprite.rb', line 472 def vy=(n) @view__.velocity = @view__.velocity.tap {|v| v.y = n} end |
#wheel(*args, **options, &block) ⇒ WheelConstraint
Creates a constraint that makes the sprite ride on the target like a wheel: it slides along an axis for the suspension and spins freely.
737 738 739 |
# File 'lib/rubysketch/sprite.rb', line 737 def wheel(*args, **, &block) pin.wheel(*args, **, &block) end |
#width ⇒ Numeric Also known as: w
Returns the width of the sprite.
322 323 324 |
# File 'lib/rubysketch/sprite.rb', line 322 def width() @view__.width end |
#width=(w) ⇒ Numeric Also known as: w=
Sets the width of the sprite.
332 333 334 |
# File 'lib/rubysketch/sprite.rb', line 332 def width=(w) @view__.width = w end |
#x ⇒ Numeric
Returns the x-coordinate position of the sprite.
152 153 154 |
# File 'lib/rubysketch/sprite.rb', line 152 def x() @view__.x end |
#x=(n) ⇒ Numeric
Set the x-coordinate position of the sprite.
162 163 164 |
# File 'lib/rubysketch/sprite.rb', line 162 def x=(n) @view__.x = n end |
#y ⇒ Numeric
Returns the y-coordinate position of the sprite.
170 171 172 |
# File 'lib/rubysketch/sprite.rb', line 170 def y() @view__.y end |
#y=(n) ⇒ Numeric
Set the y-coordinate position of the sprite.
180 181 182 |
# File 'lib/rubysketch/sprite.rb', line 180 def y=(n) @view__.y = n end |
#z ⇒ Numeric
Returns the z-coordinate position of the sprite.
188 189 190 |
# File 'lib/rubysketch/sprite.rb', line 188 def z() @view__.z end |
#z=(n) ⇒ Numeric
Set the z-coordinate position of the sprite.
198 199 200 |
# File 'lib/rubysketch/sprite.rb', line 198 def z=(n) @view__.z = n end |