Class: RubySketch::Sprite

Inherits:
Object
  • Object
show all
Includes:
Xot::Inspectable
Defined in:
lib/rubysketch/sprite.rb

Overview

Sprite object.

Instance Method Summary collapse

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.

Overloads:

  • #new(x, y, w, h) ⇒ Sprite

    pos(x, y), size: [w, h]

    Parameters:

    • x (Numeric)

      x of the sprite position

    • y (Numeric)

      y of the sprite position

    • w (Numeric)

      width of the sprite

    • h (Numeric)

      height of the sprite

  • #new(image: img) ⇒ Sprite

    pos: [0, 0], size: [image.width, image.height]

    Parameters:

    • img (Image)

      sprite image

  • #new(x, y, image: img) ⇒ Sprite

    pos: [x, y], size: [image.width, image.height]

    Parameters:

    • x (Numeric)

      x of the sprite position

    • y (Numeric)

      y of the sprite position

    • img (Image)

      sprite image

  • #new(x, y, image: img, offset: off) ⇒ Sprite

    pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]

    Parameters:

    • x (Numeric)

      x of the sprite position

    • y (Numeric)

      y of the sprite position

    • img (Image)

      sprite image

    • off (Vector)

      offset of the sprite image

  • #new(x, y, image: img, shape: shp) ⇒ Sprite

    pos: [x, y], size: [image.width, image.height]

    Parameters:

    • x (Numeric)

      x of the sprite position

    • y (Numeric)

      y of the sprite position

    • img (Image)

      sprite image

  • #new(x, y, image: img, offset: off, shape: shp) ⇒ Sprite

    pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]

    Parameters:

    • x (Numeric)

      x of the sprite position

    • y (Numeric)

      y of the sprite position

    • img (Image)

      sprite image

    • off (Vector)

      offset of the sprite image

    • shp (Shape)

      shape of the sprite for physics calculations

  • #new(x, y, shape: shp) ⇒ Sprite

    pos: [x, y], size: [shape.width, shape.height]

    Parameters:

    • x (Numeric)

      x of the sprite position

    • y (Numeric)

      y of the sprite position

    • shp (Shape)

      shape of the sprite for physics calculations



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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, context: nil)

  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)

  @context__ = context || Context.context__
  @shape__   = shape
  @view__    = SpriteView.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

#angleNumeric

Returns the rotation angle of the sprite.

Returns:

  • (Numeric)

    radians or degrees depending on angleMode()



348
349
350
351
# File 'lib/rubysketch/sprite.rb', line 348

def angle()
  a, c = @view__.angle, @context__
  c ? c.fromDegrees__(a) : a * Processing::GraphicsContext::DEG2RAD__
end

#angle=(angle) ⇒ Numeric

Sets the rotation angle of the sprite.

Parameters:

  • angle (Numeric)

    radians or degrees depending on angleMode()

Returns:

  • (Numeric)

    angle



359
360
361
362
363
364
# File 'lib/rubysketch/sprite.rb', line 359

def angle=(angle)
  c = @context__
  @view__.angle =
    c ? c.toDegrees__(angle) : angle * Processing::GraphicsContext::RAD2DEG__
  angle
end

#angleFixed?Boolean

Returns the angle of the sprite is fixed or not.

Returns:

  • (Boolean)

    whether the rotation is fixed or not



381
382
383
# File 'lib/rubysketch/sprite.rb', line 381

def angleFixed?()
  @view__.fix_angle?
end

#bottomNumeric

Returns the bottom position of the sprite.

Returns:

  • (Numeric)

    bottom



248
249
250
# File 'lib/rubysketch/sprite.rb', line 248

def bottom()
  @view__.bottom
end

#bottom=(bottom) ⇒ Numeric

Set the bottom position of the sprite.

Parameters:

  • n (Numeric)

    sprite bottom position

Returns:

  • (Numeric)

    sprite bottom position



258
259
260
# File 'lib/rubysketch/sprite.rb', line 258

def bottom=(bottom)
  @view__.bottom = bottom
end

#centerVector

Returns the center position of the sprite.

Returns:

  • (Vector)

    center position



266
267
268
# File 'lib/rubysketch/sprite.rb', line 266

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.

Overloads:

  • #center=(vec) ⇒ Vector

    Parameters:

    • vec (Vector)

      center position

  • #center=(ary) ⇒ Vector

    Parameters:

    • ary (Array<Numeric>)

      an array of centerX and centerY

Returns:

  • (Vector)

    center position



280
281
282
283
284
# File 'lib/rubysketch/sprite.rb', line 280

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

#clickCountNumeric

Returns the mouse button click count on the sprite.

Returns:

  • (Numeric)

    click count



700
701
702
# File 'lib/rubysketch/sprite.rb', line 700

def clickCount()
  @view__.clickCount
end

#contact(&block) ⇒ nil

Defines contact block.

Examples:

Score increases when the player sprite touches a coin

playerSprite.contact do |o|
  score += 1 if o.coin?
end

Returns:

  • (nil)

    nil



863
864
865
866
# File 'lib/rubysketch/sprite.rb', line 863

def contact(&block)
  @view__.contact = block if block
  nil
end

#contact?(&block) ⇒ nil

Defines contact? block.

Examples:

Only collide with an enemy

playerSprite.contact? do |o|
  o.enemy?
end

Returns:

  • (nil)

    nil



891
892
893
894
# File 'lib/rubysketch/sprite.rb', line 891

def contact?(&block)
  @view__.will_contact = block if block
  nil
end

#contact_end(&block) ⇒ nil

Defines contact_end block.

Examples:

Call jumping() when the player sprite leaves the ground sprite

playerSprite.contact_end do |o|
  jumping if o == groundSprite
end

Returns:

  • (nil)

    nil



877
878
879
880
# File 'lib/rubysketch/sprite.rb', line 877

def contact_end(&block)
  @view__.contact_end = block if block
  nil
end

#densityNumeric Also known as: dens

Returns the density of the sprite.

Returns:

  • (Numeric)

    density



576
577
578
# File 'lib/rubysketch/sprite.rb', line 576

def density()
  @view__.density
end

#density=(n) ⇒ Numeric Also known as: dens=

Sets the density of the sprite.

Parameters:

  • n (Numeric)

    density

Returns:

  • (Numeric)

    density



586
587
588
589
# File 'lib/rubysketch/sprite.rb', line 586

def density=(n)
  @view__.density = n
  n
end

#draw(&block) ⇒ nil

Defines draw block.

Examples:

Draw on your own before and after default drawing

sprite.draw do |&defaultDrawSprite|
  rect 0, 0, 10, 10
  defaultDrawSprite.call
  text :hello, 10, 20
end

Returns:

  • (nil)

    nil



737
738
739
740
# File 'lib/rubysketch/sprite.rb', line 737

def draw(&block)
  @drawBlock__ = block if block
  nil
end

#dynamic=(bool) ⇒ Boolean

Sets whether the sprite is movable by the physics engine.

Parameters:

  • bool (Boolean)

    movable or not

Returns:

  • (Boolean)

    true if dynamic



567
568
569
570
# File 'lib/rubysketch/sprite.rb', line 567

def dynamic=(bool)
  @view__.dynamic = bool
  bool
end

#dynamic?Boolean

Returns whether the sprite is movable by the physics engine.

Returns:

  • (Boolean)

    true if dynamic



557
558
559
# File 'lib/rubysketch/sprite.rb', line 557

def dynamic?()
  @view__.dynamic?
end

#fixAngle(fix = true) ⇒ Sprite

Fixes the angle of the sprite.

Parameters:

  • fix (Boolean) (defaults to: true)

    fix rotation or not

Returns:



372
373
374
375
# File 'lib/rubysketch/sprite.rb', line 372

def fixAngle(fix = true)
  @view__.fix_angle = fix
  self
end

#frictionNumeric Also known as: fric

Returns the friction of the sprite.

Returns:

  • (Numeric)

    friction



595
596
597
# File 'lib/rubysketch/sprite.rb', line 595

def friction()
  @view__.friction
end

#friction=(n) ⇒ Numeric Also known as: fric=

Sets the friction of the sprite.

Parameters:

  • n (Numeric)

    friction

Returns:

  • (Numeric)

    friction



605
606
607
608
# File 'lib/rubysketch/sprite.rb', line 605

def friction=(n)
  @view__.friction = n
  n
end

#fromScreen(vec) ⇒ Vector

Converts a vector from the screen coordinate

Parameters:

  • vec (Vector)

    screen coordinate vector

Returns:

  • (Vector)

    sprite coordinate vector



642
643
644
# File 'lib/rubysketch/sprite.rb', line 642

def fromScreen(vec)
  @view__.from_parent(vec.getInternal__).toVector
end

#heightNumeric Also known as: h

Returns the height of the sprite.

Returns:

  • (Numeric)

    height



325
326
327
# File 'lib/rubysketch/sprite.rb', line 325

def height()
  @view__.height
end

#height=(h) ⇒ Numeric Also known as: h=

Sets the height of the sprite.

Parameters:

  • h (Numeric)

    height

Returns:

  • (Numeric)

    height



335
336
337
# File 'lib/rubysketch/sprite.rb', line 335

def height=(h)
  @view__.height = h
end

#hidden?Boolean

Returns the sprite is visible

Returns:

  • (Boolean)

    true: invisible, false: visible



102
103
104
# File 'lib/rubysketch/sprite.rb', line 102

def hidden?()
  @view__.hidden?
end

#hideSprite

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.

Returns:



94
95
96
# File 'lib/rubysketch/sprite.rb', line 94

def hide()
  @view__.hide
end

#imageImage

Returns the image of the sprite.

Returns:

  • (Image)

    sprite image



473
474
475
# File 'lib/rubysketch/sprite.rb', line 473

def image()
  @image__
end

#image=(img) ⇒ Image

Sets the sprite image.

Parameters:

  • img (Image)

    sprite image

Returns:

  • (Image)

    sprite image



483
484
485
# File 'lib/rubysketch/sprite.rb', line 483

def image=(img)
  @image__ = img
end

#leftNumeric

Returns the left position of the sprite.

Returns:

  • (Numeric)

    left position



193
194
195
# File 'lib/rubysketch/sprite.rb', line 193

def left()
  @view__.left
end

#left=(n) ⇒ Numeric

Set the left position of the sprite.

Parameters:

  • n (Numeric)

    sprite left position

Returns:

  • (Numeric)

    sprite left position



203
204
205
206
# File 'lib/rubysketch/sprite.rb', line 203

def left=(n)
  @view__.left = n
  n
end

#mouseButtonLEFT, ...

Returns the mouse button clicked on the sprite.

Returns:

  • (LEFT, RIGHT, CENTER)

    mouse button



692
693
694
# File 'lib/rubysketch/sprite.rb', line 692

def mouseButton()
  @view__.mouseButton
end

#mouseClicked(&block) ⇒ nil

Defines mouseClicked block.

Examples:

Print mouse states on mouse click

sprite.mouseClicked do
  p [sprite.mouseX, sprite.mouseY, sprite.mouseButton]
end

Returns:

  • (nil)

    nil



807
808
809
810
# File 'lib/rubysketch/sprite.rb', line 807

def mouseClicked(&block)
  @view__.mouseClicked = block if block
  nil
end

#mouseDragged(&block) ⇒ nil

Defines mouseDragged block.

Examples:

Print mouse states on mouse drag

sprite.mouseDragged do
  p [sprite.mouseX, sprite.mouseY, sprite.pmouseX, sprite.pmouseY]
end

Returns:

  • (nil)

    nil



793
794
795
796
# File 'lib/rubysketch/sprite.rb', line 793

def mouseDragged(&block)
  @view__.mouseDragged = block if block
  nil
end

#mouseMoved(&block) ⇒ nil

Defines mouseMoved block.

Examples:

Print mouse states on mouse move

sprite.mouseMoved do
  p [sprite.mouseX, sprite.mouseY, sprite.pmouseX, sprite.pmouseY]
end

Returns:

  • (nil)

    nil



779
780
781
782
# File 'lib/rubysketch/sprite.rb', line 779

def mouseMoved(&block)
  @view__.mouseMoved = block if block
  nil
end

#mousePressed(&block) ⇒ Boolean

Defines mousePressed block.

Examples:

Print mouse states on mouse press

sprite.mousePressed do
  p [sprite.mouseX, sprite.mouseY, sprite.mouseButton]
end

Returns:

  • (Boolean)

    is any mouse button pressed or not



751
752
753
754
# File 'lib/rubysketch/sprite.rb', line 751

def mousePressed(&block)
  @view__.mousePressed = block if block
  @view__.mousePressed?
end

#mouseReleased(&block) ⇒ nil

Defines mouseReleased block.

Examples:

Print mouse states on mouse release

sprite.mouseReleased do
  p [sprite.mouseX, sprite.mouseY, sprite.mouseButton]
end

Returns:

  • (nil)

    nil



765
766
767
768
# File 'lib/rubysketch/sprite.rb', line 765

def mouseReleased(&block)
  @view__.mouseReleased = block if block
  nil
end

#mouseXNumeric

Returns the x-position of the mouse in the sprite coordinates.

Returns:

  • (Numeric)

    x position



660
661
662
# File 'lib/rubysketch/sprite.rb', line 660

def mouseX()
  @view__.mouseX
end

#mouseYNumeric

Returns the y-position of the mouse in the sprite coordinates.

Returns:

  • (Numeric)

    y position



668
669
670
# File 'lib/rubysketch/sprite.rb', line 668

def mouseY()
  @view__.mouseY
end

#offsetVector

Returns the offset of the sprite image.

Returns:

  • (Vector)

    offset of the sprite image



491
492
493
# File 'lib/rubysketch/sprite.rb', line 491

def offset()
  @offset__
end

#offset=(vec) ⇒ Vector #velocity=(ary) ⇒ Vector

Sets the offset of the sprite image.

Overloads:

  • #offset=(vec) ⇒ Vector

    Parameters:

  • #velocity=(ary) ⇒ Vector

    Parameters:

    • ary (Array<Numeric>)

      an array of offsetX and offsetY

Returns:

  • (Vector)

    offset of the sprite image



505
506
507
508
509
510
511
512
513
514
# File 'lib/rubysketch/sprite.rb', line 505

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

#oxNumeric

Returns the x-axis offset of the sprite image.

Returns:

  • (Numeric)

    offset.x



520
521
522
# File 'lib/rubysketch/sprite.rb', line 520

def ox()
  @offset__&.x || 0
end

#ox=(n) ⇒ Numeric

Sets the x-axis offset of the sprite image.

Parameters:

  • n (Numeric)

    x-axis offset

Returns:

  • (Numeric)

    offset.x



530
531
532
533
# File 'lib/rubysketch/sprite.rb', line 530

def ox=(n)
  self.offset = [n, oy]
  n
end

#oyNumeric

Returns the y-axis offset of the sprite image.

Returns:

  • (Numeric)

    offset.y



539
540
541
# File 'lib/rubysketch/sprite.rb', line 539

def oy()
  @offset__&.y || 0
end

#oy=(n) ⇒ Numeric

Sets the y-axis offset of the sprite image.

Parameters:

  • n (Numeric)

    y-axis offset

Returns:

  • (Numeric)

    offset.y



549
550
551
# File 'lib/rubysketch/sprite.rb', line 549

def oy=(n)
  self.offset = [ox, n]
end

#pivotArray<Numeric>

Returns the rotation center of the sprite.

Returns:

  • (Array<Numeric>)
    pivotX, pivotY


389
390
391
# File 'lib/rubysketch/sprite.rb', line 389

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.

Parameters:

  • ary (Array<Numeric>)

    an array of pivotX and pivotY

Returns:

  • (Array<Numeric>)
    pivotX, pivotY


400
401
402
403
# File 'lib/rubysketch/sprite.rb', line 400

def pivot=(array)
  @view__.pivot = array
  pivot
end

#pmouseXNumeric

Returns the previous x-position of the mouse in the sprite coordinates.

Returns:

  • (Numeric)

    x position



676
677
678
# File 'lib/rubysketch/sprite.rb', line 676

def pmouseX()
  @view__.pmouseX
end

#pmouseYNumeric

Returns the previous y-position of the mouse in the sprite coordinates.

Returns:

  • (Numeric)

    y position



684
685
686
# File 'lib/rubysketch/sprite.rb', line 684

def pmouseY()
  @view__.pmouseY
end

#positionVector Also known as: pos

Returns the position of the sprite.

Returns:



110
111
112
# File 'lib/rubysketch/sprite.rb', line 110

def position()
  @view__.position.toVector
end

#position=(vec) ⇒ Vector #position=(ary) ⇒ Vector Also known as: pos=

Sets the position of the sprite.

Overloads:

  • #position=(vec) ⇒ Vector

    Parameters:

    • vec (Vector)

      position vector

  • #position=(ary) ⇒ Vector

    Parameters:

    • ary (Array<Numeric>)

      an array of positionX and positionY

Returns:



124
125
126
127
# File 'lib/rubysketch/sprite.rb', line 124

def position=(arg)
  @view__.position = arg.is_a?(Vector) ? arg.getInternal__ : arg
  arg
end

#restitutionNumeric Also known as: rest

Returns the restitution of the sprite.

Returns:

  • (Numeric)

    restitution



614
615
616
# File 'lib/rubysketch/sprite.rb', line 614

def restitution()
  @view__.restitution
end

#restitution=(n) ⇒ Numeric Also known as: rest=

Sets the restitution of the sprite.

Parameters:

  • n (Numeric)

    restitution

Returns:

  • (Numeric)

    restitution



624
625
626
627
# File 'lib/rubysketch/sprite.rb', line 624

def restitution=(n)
  @view__.restitution = n
  n
end

#rightNumeric

Returns the right position of the sprite.

Returns:

  • (Numeric)

    right position



230
231
232
# File 'lib/rubysketch/sprite.rb', line 230

def right()
  @view__.right
end

#right=(n) ⇒ Numeric

Set the right position of the sprite.

Parameters:

  • n (Numeric)

    sprite right position

Returns:

  • (Numeric)

    sprite right position



240
241
242
# File 'lib/rubysketch/sprite.rb', line 240

def right=(n)
  @view__.right = n
end

#showSprite

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.

Returns:



83
84
85
86
# File 'lib/rubysketch/sprite.rb', line 83

def show()
  @view__.show
  self
end

#sizeVector

Returns the size of the sprite.

Returns:



290
291
292
# File 'lib/rubysketch/sprite.rb', line 290

def size()
  @view__.size.toVector
end

#size=(arg) ⇒ Vector

Returns the size of the sprite.

Returns:



298
299
300
301
# File 'lib/rubysketch/sprite.rb', line 298

def size=(arg)
  @view__.size = arg.is_a?(Vector) ? arg.getInternal__ : arg
  arg
end

#topNumeric

Returns the top position of the sprite.

Returns:

  • (Numeric)

    top position



212
213
214
# File 'lib/rubysketch/sprite.rb', line 212

def top()
  @view__.top
end

#top=(n) ⇒ Numeric

Set the top position of the sprite.

Parameters:

  • n (Numeric)

    sprite top position

Returns:

  • (Numeric)

    sprite top position



222
223
224
# File 'lib/rubysketch/sprite.rb', line 222

def top=(n)
  @view__.top = n
end

#toScreen(vec) ⇒ Vector

Converts a vector to the screen coordinate

Parameters:

  • vec (Vector)

    sprite coordinate vector

Returns:

  • (Vector)

    screen coordinate vector



652
653
654
# File 'lib/rubysketch/sprite.rb', line 652

def toScreen(vec)
  @view__.to_parent(vec.getInternal__).toVector
end

#touchEnded(&block) ⇒ nil

Defines touchEnded block.

Examples:

Print touches on touch end

sprite.touchEnded do
  p sprite.touches
end

Returns:

  • (nil)

    nil



835
836
837
838
# File 'lib/rubysketch/sprite.rb', line 835

def touchEnded(&block)
  @view__.touchEnded = block if block
  nil
end

#touchesArray<Touch>

Returns the touch objects touched on the sprite.

Returns:

  • (Array<Touch>)

    touches



708
709
710
# File 'lib/rubysketch/sprite.rb', line 708

def touches()
  @view__.touches
end

#touchMoved(&block) ⇒ nil

Defines touchMoved block.

Examples:

Print touches on touch move

sprite.touchMoved do
  p sprite.touches
end

Returns:

  • (nil)

    nil



849
850
851
852
# File 'lib/rubysketch/sprite.rb', line 849

def touchMoved(&block)
  @view__.touchMoved = block if block
  nil
end

#touchStarted(&block) ⇒ nil

Defines touchStarted block.

Examples:

Print touches on touch start

sprite.touchStarted do
  p sprite.touches
end

Returns:

  • (nil)

    nil



821
822
823
824
# File 'lib/rubysketch/sprite.rb', line 821

def touchStarted(&block)
  @view__.touchStarted = block if block
  nil
end

#update(&block) ⇒ nil

Defines update block.

Examples:

vx is updated every frame

sprite.update do
  self.vx *= 0.9
end

Returns:

  • (nil)

    nil



721
722
723
724
# File 'lib/rubysketch/sprite.rb', line 721

def update(&block)
  @view__.update = block if block
  nil
end

#velocityVector Also known as: vel

Returns the velocity of the sprite.

Returns:



409
410
411
# File 'lib/rubysketch/sprite.rb', line 409

def velocity()
  @view__.velocity.toVector
end

#velocity=(vec) ⇒ Vector #velocity=(ary) ⇒ Vector Also known as: vel=

Sets the velocity of the sprite.

Overloads:

  • #velocity=(vec) ⇒ Vector

    Parameters:

    • vec (Vector)

      velocity vector

  • #velocity=(ary) ⇒ Vector

    Parameters:

    • ary (Array<Numeric>)

      an array of velocityX and velocityY

Returns:



423
424
425
426
# File 'lib/rubysketch/sprite.rb', line 423

def velocity=(arg)
  @view__.velocity = arg.is_a?(Vector) ? arg.getInternal__ : arg
  arg
end

#vxNumeric

Returns the x-axis velocity of the sprite.

Returns:

  • (Numeric)

    velocity.x



432
433
434
# File 'lib/rubysketch/sprite.rb', line 432

def vx()
  @view__.velocity.x
end

#vx=(n) ⇒ Numeric

Sets the x-axis velocity of the sprite.

Parameters:

  • n (Numeric)

    x-axis velocity

Returns:

  • (Numeric)

    velocity.x



442
443
444
445
# File 'lib/rubysketch/sprite.rb', line 442

def vx=(n)
  @view__.velocity = @view__.velocity.tap {|v| v.x = n}
  n
end

#vyNumeric

Returns the y-axis velocity of the sprite.

Returns:

  • (Numeric)

    velocity.y



451
452
453
# File 'lib/rubysketch/sprite.rb', line 451

def vy()
  @view__.velocity.y
end

#vy=(n) ⇒ Numeric

Sets the y-axis velocity of the sprite.

Parameters:

  • n (Numeric)

    y-axis velocity

Returns:

  • (Numeric)

    velocity.y



461
462
463
464
# File 'lib/rubysketch/sprite.rb', line 461

def vy=(n)
  @view__.velocity = @view__.velocity.tap {|v| v.y = n}
  n
end

#widthNumeric Also known as: w

Returns the width of the sprite.

Returns:

  • (Numeric)

    width



307
308
309
# File 'lib/rubysketch/sprite.rb', line 307

def width()
  @view__.width
end

#width=(w) ⇒ Numeric Also known as: w=

Sets the width of the sprite.

Parameters:

  • w (Numeric)

    width

Returns:

  • (Numeric)

    width



317
318
319
# File 'lib/rubysketch/sprite.rb', line 317

def width=(w)
  @view__.width = w
end

#xNumeric

Returns the x-coordinate position of the sprite.

Returns:

  • (Numeric)

    sprite position x



133
134
135
# File 'lib/rubysketch/sprite.rb', line 133

def x()
  @view__.x
end

#x=(n) ⇒ Numeric

Set the x-coordinate position of the sprite.

Parameters:

  • n (Numeric)

    sprite position x

Returns:

  • (Numeric)

    sprite position x



143
144
145
146
# File 'lib/rubysketch/sprite.rb', line 143

def x=(n)
  @view__.x = n
  n
end

#yNumeric

Returns the y-coordinate position of the sprite.

Returns:

  • (Numeric)

    sprite position y



152
153
154
# File 'lib/rubysketch/sprite.rb', line 152

def y()
  @view__.y
end

#y=(n) ⇒ Numeric

Set the y-coordinate position of the sprite.

Parameters:

  • n (Numeric)

    sprite position y

Returns:

  • (Numeric)

    sprite position y



162
163
164
165
# File 'lib/rubysketch/sprite.rb', line 162

def y=(n)
  @view__.y = n
  n
end

#zNumeric

Returns the z-coordinate position of the sprite.

Returns:

  • (Numeric)

    sprite position z



171
172
173
# File 'lib/rubysketch/sprite.rb', line 171

def z()
  @view__.z
end

#z=(n) ⇒ Numeric

Set the z-coordinate position of the sprite.

Parameters:

  • n (Numeric)

    sprite position z

Returns:

  • (Numeric)

    sprite position z



181
182
183
184
# File 'lib/rubysketch/sprite.rb', line 181

def z=(n)
  @view__.z = n
  n
end