Class: PIXI::Point

Inherits:
Object
  • Object
show all
Includes:
Native
Defined in:
lib/opal/pixi/point.rb,
lib/opal/pixi/core/math/point.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(x_or_native, y) ⇒ Object



12
13
14
# File 'lib/opal/pixi/point.rb', line 12

def self.new(x,y)
  `new window.PIXI.Point(x,y)`
end

Instance Method Details

#add(point) ⇒ Object

just add another point to this one return self for chaining



26
27
28
29
30
# File 'lib/opal/pixi/point.rb', line 26

def add point
  self.x += point.x
  self.y += point.y
  self
end

#add_and_bounce(distance, wall) ⇒ Object

add a point (the first arg), but “bounce” off the wall, second arg second arg is a pint that defines a rectangle with 0,0 if the adding makes the point go beyond the rectangle it bounces off the wall back in



35
36
37
38
# File 'lib/opal/pixi/point.rb', line 35

def add_and_bounce distance , wall
  self.add(distance).bounce(wall)
  self
end

#at_x(new_x) ⇒ Object

return new point with same y coordiante but the given x



65
66
67
# File 'lib/opal/pixi/point.rb', line 65

def at_x new_x
  PIXI::Point.new(new_x , self.y)
end

#at_y(new_y) ⇒ Object

return new point with same x coordiante but the given y



60
61
62
# File 'lib/opal/pixi/point.rb', line 60

def at_y new_y
  PIXI::Point.new(self.x ,new_y)
end

#bounce(wall) ⇒ Object

check if the point is outside the rectangle spanned by the wall arg (a point)



41
42
43
44
45
46
# File 'lib/opal/pixi/point.rb', line 41

def bounce wall
  self.x = - self.x    if self.x  < 0
  self.x = wall.x - (self.x - wall.x)  if self.x  > wall.x
  self.y = -self.y    if self.y  < 0
  self.y = wall.y - (self.y - wall.y)    if self.y  > wall.y
end

#scale_by(num) ⇒ Object

scale the point down by the given factor. off course for factors smaller than 1 that means it gets bigger try to avoid 0 division by applying a minimum of 0.0001



51
52
53
54
55
56
57
# File 'lib/opal/pixi/point.rb', line 51

def scale_by num
  min = 0.001
  num = min if num < min and num > -min
  self.x = self.x / num
  self.y = self.y / num
  self
end