Skip to content

Commit 2c85841

Browse files
committed
Extracted Ball creation in a separated class.
1 parent 394b64a commit 2c85841

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

index.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Created by Mihail on 3/5/2017.
33
*/
44
import createjs from 'createjs'
5+
import Ball from './src/Ball'
56

67
export default class App {
78
constructor() {
@@ -19,14 +20,7 @@ export default class App {
1920

2021
let i = 0
2122
while(i < this.BALLS_COUNT) {
22-
let bitmap = new createjs.Bitmap('static/images/ball7b.png')
23-
24-
bitmap.x = Math.floor(Math.random() * stage.canvas.width)
25-
bitmap.y = Math.floor(Math.random() * stage.canvas.height)
26-
27-
console.log('coords:', bitmap.x, bitmap.y)
28-
bitmap.shadow = new createjs.Shadow("#000000", 5, 5, 10)
29-
stage.addChild(bitmap);
23+
stage.addChild(new Ball(stage.canvas.width, stage.canvas.height))
3024
i++;
3125
}
3226

src/Ball.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Created by Mihail on 3/12/2017.
3+
*/
4+
import createjs from 'createjs'
5+
6+
export default class Ball {
7+
constructor(stageWidth, stageHeight) {
8+
9+
let bitmap = new createjs.Bitmap('static/images/ball7b.png')
10+
bitmap.x = Math.floor(Math.random() * stageWidth)
11+
bitmap.y = Math.floor(Math.random() * stageHeight)
12+
bitmap.shadow = new createjs.Shadow("#000000", 5, 5, 10)
13+
14+
return bitmap
15+
}
16+
}

webpack.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ module.exports = {
2222
plugins: ['transform-object-rest-spread']
2323
}
2424
},
25-
// Images
2625
{
2726
test: /\.(png|jpg)$/,
2827
loader: 'url-loader?limit=8192'
2928
},
30-
// SASS
3129
{
3230
test: /\.scss$/,
3331
loaders: ['style-loader', 'css-loader', 'sass-loader']

0 commit comments

Comments
 (0)