Skip to content

Commit

Permalink
Created the width property for Viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
jamillosantos committed Sep 18, 2012
1 parent 360bd68 commit 7995779
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/chingu/viewport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def lag=(lag)
# TODO: Add support for x,y here!
#
def center_around(object)
self.x = object.x * @factor_x - $window.width / 2
self.y = object.y * @factor_y - $window.height / 2
self.x = object.x * @factor_x - (@width || $window.width) / 2
self.y = object.y * @factor_y - (@height || $window.height) / 2
end

#
Expand Down Expand Up @@ -88,8 +88,8 @@ def game_area_object=(game_object)
#
def inside?(object, y = nil)
x, y = y ? [object,y] : [object.x, object.y]
x >= @x && x <= (@x + $window.width) &&
y >= @y && y <= (@y + $window.height)
x >= @x && x <= (@x + (@width || $window.width)) &&
y >= @y && y <= (@y + (@height || $window.height))
end

# Returns true object is outside the view port
Expand Down Expand Up @@ -135,7 +135,7 @@ def x=(x)
@x = x
if @game_area
@x = @game_area.x * @factor_x if @x < @game_area.x * @factor_x
@x = @game_area.width * @factor_x - $window.width if @x > @game_area.width * @factor_x - $window.width
@x = @game_area.width * @factor_x - (@width || $window.width) if @x > @game_area.width * @factor_x - (@width || $window.width)
end
end

Expand All @@ -146,9 +146,17 @@ def y=(y)
@y = y
if @game_area
@y = @game_area.y * @factor_y if @y < @game_area.y * @factor_y
@y = @game_area.height * @factor_y - $window.height if @y > @game_area.height * @factor_y - $window.height
@y = @game_area.height * @factor_y - (@height || $window.height) if @y > @game_area.height * @factor_y - (@height || $window.height)
end
end

def width=(width)
@width = width
end

def height=(width)

This comment has been minimized.

Copy link
@ndrluis

ndrluis Apr 19, 2015

copy and paste typo

@height = height
end

#
# Apply the X/Y viewport-translation, used by trait "viewport"
Expand Down

0 comments on commit 7995779

Please sign in to comment.