motion/joybox/physics/physics_sprite.rb in joybox-1.0.0 vs motion/joybox/physics/physics_sprite.rb in joybox-1.1.0

- old
+ new

@@ -1,42 +1,75 @@ -# TODO: Revisar el nombre de esto module Joybox - module Core + module Physics - class PhysicsSprite < Sprite + class PhysicsSprite < Joybox::Core::Sprite attr_accessor :body - def self.new(options = {}) - sprite = super - sprite.body = options[:body] if options.include? :body - - sprite + def initialize(options = {}) + super + self.body = options.delete(:body) if options.has_key? :body + self.body[:sprite] = self end # We need this method to return true, so Cocos2d continue # to call the nodeToParentTransform method def dirty true end + def position + if @body and not self.running_actions? + @body.position + else + super + end + end + def position=(position) - @body.position = position + if @body and not self.running_actions? + @body.position = position + else + super + end end - def position - @body.position.from_pixel_coordinates + def rotation + if @body and not self.running_actions? + @body.rotation + else + super + end end + def rotation=(rotation) + if @body and not self.running_actions? + @body.rotation = rotation + else + super + end + end + + def run_action(action) + callback = Callback.with do + @body.position = self.position unless @body.nil? + @body.angle = self.rotation unless @body.nil? + end + sequence = Sequence.with actions: [action, callback] + super(sequence) + + self.position = @body.position unless @body.nil? + end + def nodeToParentTransform - return super if @body.nil? + return super if @body.nil? or self.running_actions? super - position = @body.position.from_pixel_coordinates + position = @body.position position = position + anchorPointInPoints if ignoreAnchorPointForPosition - angle = @body.angle + angle = @body.radian_angle x = position.x y = position.y cosine = Math.cos(angle) sine = Math.sin(angle) @@ -44,12 +77,13 @@ unless anchorPointInPoints == CGPointZero x = x + cosine * -anchorPointInPoints.x + -sine * -anchorPointInPoints.y y = y + sine * -anchorPointInPoints.x + cosine * -anchorPointInPoints.y end - CGAffineTransformMake(cosine, sine, -sine, cosine, x, y) + rotated_transform = CGAffineTransformMake(cosine, sine, -sine, cosine, x, y) + CGAffineTransformScale(rotated_transform, self.scaleX, self.scaleY) end end end -end \ No newline at end of file +end