Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add: backbone-gravity

  • Loading branch information...
commit 771f9cb9de2b2e74f785726724f3a49705102bbb 1 parent b1f6f78
@hugomallet hugomallet authored
View
7 app/index.html
@@ -27,6 +27,7 @@
<div id="container">
+
<div id="header">
<header>
@@ -37,11 +38,14 @@ <h1 class="Three-Dee">Gravity Blog</h1>
<button id="new-article"class="btn" type="button">Submit</button>
</div>
<button class="btn" id="add-article" type="button"><i class="icon-plus-sign"></i></button>
+ <button class="btn" id="toggle-debug" type="button"><i class="icon-screenshot"></i></button>
</header>
</div>
<div id="blog">
+ <canvas id="debug" width="560" height="0">
+ </canvas>
</div>
</div>
@@ -63,6 +67,9 @@ <h1 class="Three-Dee">Gravity Blog</h1>
<script src="components/jquery/jquery.min.js"></script>
<script src="components/underscore/underscore-min.js"></script>
<script src="components/backbone/backbone-min.js"></script>
+ <script src="components/backbone-gravity/lib/Box2dWeb-2.1.a.3.min.js"></script>
+ <script src="components/backbone-gravity/helpers/box2d-helper.js"></script>
+ <script src="components/backbone-gravity/helpers/backbone-gravity.js"></script>
<script src="scripts/main.js"></script>
<script src="scripts/views/application-view.js"></script>
<script src="scripts/models/application-model.js"></script>
View
3  app/scripts/main.js
@@ -11,9 +11,10 @@ window.gravityBlog = {
var articleList = new gravityBlog.Collections.ArticleCollection();
articleList.fetch();
- gravityBlog.view = new gravityBlog.Views.applicationView({
+ var view = gravityBlog.view = new gravityBlog.Views.applicationView({
collection : articleList,
});
+ view.debug();
}
};
View
38 app/scripts/views/application-view.js
@@ -1,14 +1,16 @@
'use strict';
-gravityBlog.Views.applicationView = Backbone.View.extend({
+gravityBlog.Views.applicationView = BackboneGravity.Views.WorldView.extend({
el: $('#container'),
events: {
'click #new-article': 'createArticle',
- 'click #add-article': 'showTools'
+ 'click #add-article': 'showTools',
+ 'click #toggle-debug': 'debug'
},
initialize: function() {
+ BackboneGravity.Views.WorldView.prototype.initialize.call(this);
this.addCollectionListener(this.collection);
},
@@ -24,6 +26,14 @@ gravityBlog.Views.applicationView = Backbone.View.extend({
});
//on ajoute la vue au DOM
this.$el.find('#blog').prepend(view.render().el);
+ this.$el.height(this.$el.height() + view.$el.height())
+ if (this.debugCanvas)
+ this.debugCanvas.height = this.$el.height();
+ this.bodies['ground'].setPosition({y: this.$el.height()});
+ this.createBody(view, {
+ x: view.$el.width() / 2,
+ y: view.$el.height() / 2
+ });
return false;
},
@@ -31,7 +41,29 @@ gravityBlog.Views.applicationView = Backbone.View.extend({
},
reset: function() {
- this.collection.each(this.addOne, this);
+ console.log($(window).width())
+ this.createBody({
+ cid: 'ground',
+ width: $(window).width() * 2,
+ height: 10,
+ x: 560 / 2,
+ y: this.$el.height(),
+ angle: 0,
+ dynamic: false
+ });
+ var self = this;
+ console.log(self.collection.models.length)
+ function loop(i) {
+ if (!self.collection.models[i])
+ return;
+ self.addOne(self.collection.models[i]);
+ i++;
+ window.setTimeout(function() {
+ loop(i);
+ }, 2000);
+ }
+ loop(0);
+ this.update();
},
createArticle: function(){
View
9 app/scripts/views/article-view.js
@@ -47,6 +47,15 @@ gravityBlog.Views.articleView = Backbone.View.extend({
this.$el.find('label').show();
this.$el.find('p').show();
this.$el.find('.tools').hide();
+ },
+
+ update: function () {
+ var position = this.getPosition();
+ this.$el.css({
+ left: position.x - this.$el.outerWidth() / 2,
+ top: position.y - this.$el.outerHeight() / 2,
+ transform: 'rotate(' + this.getAngle() + 'deg)'
+ });
}
});
View
30 app/styles/main.css
29 additions, 1 deletion not shown
View
3  component.json
@@ -5,7 +5,8 @@
"jquery": "~1.9.0",
"underscore": "~1.4.3",
"backbone": "~0.9.10",
- "modernizr": "~2.6.2"
+ "modernizr": "~2.6.2",
+ "backbone-gravity": "../backbone-gravity"
},
"devDependencies": {}
}
Please sign in to comment.
Something went wrong with that request. Please try again.