Sha256: 06c15df17b6c8d748a88660d98866e7af9e25cdc98c49c2ac744b6f5b741aa5e

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

describe Joybox::Physics::PhysicsSprite do
  before do
    @world = World.new gravity: [0, -9.8]
    @body = @world.new_body position: [100, 100], type: Body::Dynamic do
      polygon_fixture box: [16, 16]
    end
  end

  describe "Initialization" do
    it "should initialize with a body" do 
      physics_sprite = PhysicsSprite.new file_name: 'sprite.png', body: @body
      physics_sprite.should.not == nil
      physics_sprite.body.should == @body
      physics_sprite.position.should == CGPointMake(100, 100)
      physics_sprite.contentSize.should == CGSizeMake(101, 171)
      physics_sprite.visible.should == true
      physics_sprite.bounding_box.should == CGRectMake(49.5, 14.5, 101, 171)
    end
  end

  it "should be dirty" do
    physics_sprite = PhysicsSprite.new file_name: 'sprite.png', body: @body
    physics_sprite.dirty.should == true
  end

  it "should return its position" do
    physics_sprite = PhysicsSprite.new file_name: 'sprite.png', body: @body
    physics_sprite.position.should == CGPointMake(100, 100)
    physics_sprite.body.position.should == CGPointMake(100, 100)
  end

  it "should change its position" do
    physics_sprite = PhysicsSprite.new file_name: 'sprite.png', body: @body
    physics_sprite.position.should == CGPointMake(100, 100)

    physics_sprite.position = CGPointMake(200, 200)
    physics_sprite.position.should == CGPointMake(200, 200)
    physics_sprite.body.position.should == CGPointMake(200, 200)
  end

  it "should adjust to its body position" do
    physics_sprite = PhysicsSprite.new file_name: 'sprite.png', body: @body
    physics_sprite.position.should == CGPointMake(100, 100)

    @world.step delta:10

    physics_sprite.position.should.be.close CGPointMake(100, 36), 0.1
    physics_sprite.body.position.should.be.close CGPointMake(100, 36), 0.1
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
joybox-1.1.1 spec/motion/joybox/physics/physics_sprite_spec.rb
joybox-1.1.0 spec/motion/joybox/physics/physics_sprite_spec.rb