Skip to content

Commit 5933757

Browse files
author
Greg
committedAug 9, 2012
added more methods and options for better coverage and consistency
1 parent a854bc5 commit 5933757

File tree

3 files changed

+1033
-38
lines changed

3 files changed

+1033
-38
lines changed
 

‎boxbox.js

+217
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ Created at Bocoup http://bocoup.com
464464
* @friction (default 1)
465465
* @restitution or bounciness (default .2)
466466
* @active (default true) participates in collisions and dynamics
467+
* @rotation (default 0) initial rotation in degrees
467468
* @fixedRotation (default false) prevent entity from rotating
468469
* @bullet (default false) perform expensive continuous
469470
* collision detection
@@ -798,6 +799,7 @@ Created at Bocoup http://bocoup.com
798799
friction: 1,
799800
restitution: 0.2, // bounciness
800801
active: true, // participates in collision and dynamics
802+
rotation: null,
801803
fixedRotation: false,
802804
bullet: false, // perform expensive continuous collision detection
803805
maxVelocityX: 1000,
@@ -1000,6 +1002,11 @@ Created at Bocoup http://bocoup.com
10001002
fixture.shape.SetAsArray(ops.points, ops.points.length);
10011003
}
10021004

1005+
// rotation
1006+
if (ops.rotation) {
1007+
body.angle = ops.rotation / DEGREES_PER_RADIAN;
1008+
}
1009+
10031010
// rendering stuff
10041011
if (ops.draw) {
10051012
this._draw = ops.draw;
@@ -1027,6 +1034,18 @@ Created at Bocoup http://bocoup.com
10271034
if (ops.onImpact) {
10281035
this._world._addImpactHandler(id, ops.onImpact);
10291036
}
1037+
if (ops.onKeyDown) {
1038+
this._world._addKeydownHandler(id, ops.onKeyDown);
1039+
}
1040+
if (ops.onKeyUp) {
1041+
this._world._addKeyupHandler(id, ops.onKeyUp);
1042+
}
1043+
if (ops.onRender) {
1044+
this.onRender(ops.onRender);
1045+
}
1046+
if (ops.onTick) {
1047+
this.onTick(ops.onTick);
1048+
}
10301049

10311050
// custom init function
10321051
if (ops.init) {
@@ -1134,6 +1153,204 @@ Created at Bocoup http://bocoup.com
11341153
}
11351154
return this._body.GetFixtureList().GetFriction();
11361155
},
1156+
1157+
/**
1158+
* @_module entity
1159+
* @_params [value]
1160+
* @value number
1161+
* @return number
1162+
* @description get or set entity restitution (bounciness)
1163+
*/
1164+
restitution: function(value) {
1165+
if (value !== undefined) {
1166+
this._body.GetFixtureList().SetRestitution(value);
1167+
}
1168+
return this._body.GetFixtureList().GetRestitution();
1169+
},
1170+
1171+
/**
1172+
* @_module entity
1173+
* @_params [value]
1174+
* @value number
1175+
* @return number
1176+
* @description get or set entity max velocity left or right
1177+
*/
1178+
maxVelocityX: function(value) {
1179+
if (value !== undefined) {
1180+
this._ops.maxVelocityX = value;
1181+
}
1182+
return this._ops.maxVelocityX;
1183+
},
1184+
1185+
/**
1186+
* @_module entity
1187+
* @_params [value]
1188+
* @value number
1189+
* @return number
1190+
* @description get or set entity max velocity up or down
1191+
*/
1192+
maxVelocityY: function(value) {
1193+
if (value !== undefined) {
1194+
this._ops.maxVelocityY = value;
1195+
}
1196+
return this._ops.maxVelocityY;
1197+
},
1198+
1199+
/**
1200+
* @_module entity
1201+
* @_params [value]
1202+
* @value string
1203+
* @return string
1204+
* @description get or set entity image
1205+
*/
1206+
image: function(value) {
1207+
if (value !== undefined) {
1208+
this._sprite = new Image();
1209+
this._sprite.src = value;
1210+
}
1211+
return this._sprite.src;
1212+
},
1213+
1214+
/**
1215+
* @_module entity
1216+
* @_params [value]
1217+
* @value number
1218+
* @return number
1219+
* @description get or set entity image offset in the x direction
1220+
*/
1221+
imageOffsetX: function(value) {
1222+
if (value !== undefined) {
1223+
this._ops.imageOffsetX = value;
1224+
}
1225+
return this._ops.imageOffsetX;
1226+
},
1227+
1228+
/**
1229+
* @_module entity
1230+
* @_params [value]
1231+
* @value number
1232+
* @return number
1233+
* @description get or set entity image offset in the y direction
1234+
*/
1235+
imageOffsetY: function(value) {
1236+
if (value !== undefined) {
1237+
this._ops.imageOffsetY = value;
1238+
}
1239+
return this._ops.imageOffsetY;
1240+
},
1241+
1242+
/**
1243+
* @_module entity
1244+
* @_params [value]
1245+
* @value boolean
1246+
* @return boolean
1247+
* @description set to true to stretch image to entity size
1248+
*/
1249+
imageStretchToFit: function(value) {
1250+
if (value !== undefined) {
1251+
this._ops.imageStretchToFit = value;
1252+
}
1253+
return this._ops.imageStretchToFit;
1254+
},
1255+
1256+
/**
1257+
* @_module entity
1258+
* @_params [value]
1259+
* @value css color string
1260+
* @return css color string
1261+
* @description get or set entity's color
1262+
*/
1263+
color: function(value) {
1264+
if (value !== undefined) {
1265+
this._ops.color = value;
1266+
}
1267+
return this._ops.color;
1268+
},
1269+
1270+
/**
1271+
* @_module entity
1272+
* @_params [value]
1273+
* @value css color string
1274+
* @return css color string
1275+
* @description get or set entity's border color
1276+
*/
1277+
borderColor: function(value) {
1278+
if (value !== undefined) {
1279+
this._ops.borderColor = value;
1280+
}
1281+
return this._ops.borderColor;
1282+
},
1283+
1284+
/**
1285+
* @_module entity
1286+
* @_params [value]
1287+
* @value number
1288+
* @return number
1289+
* @description get or set entity's border width.
1290+
* Set to 0 to not show a border.
1291+
*/
1292+
borderWidth: function(value) {
1293+
if (value !== undefined) {
1294+
this._ops.borderWidth = value;
1295+
}
1296+
return this._ops.borderWidth;
1297+
},
1298+
1299+
/**
1300+
* @_module entity
1301+
* @_params [value]
1302+
* @value boolean
1303+
* @return boolean
1304+
* @description get or set if this entity's image is a sprite sheet
1305+
*/
1306+
spriteSheet: function(value) {
1307+
if (value !== undefined) {
1308+
this._ops.spriteSheet = value;
1309+
}
1310+
return this._ops.spriteSheet;
1311+
},
1312+
1313+
/**
1314+
* @_module entity
1315+
* @_params [value]
1316+
* @value number
1317+
* @return number
1318+
* @description get or set width of a sprite on the sprite sheet
1319+
*/
1320+
spriteWidth: function(value) {
1321+
if (value !== undefined) {
1322+
this._ops.spriteWidth = value;
1323+
}
1324+
return this._ops.spriteWidth;
1325+
},
1326+
1327+
/**
1328+
* @_module entity
1329+
* @_params [value]
1330+
* @value number
1331+
* @return number
1332+
* @description get or set height of a sprite on the sprite sheet
1333+
*/
1334+
spriteHeight: function(value) {
1335+
if (value !== undefined) {
1336+
this._ops.spriteHeight = value;
1337+
}
1338+
return this._ops.spriteHeight;
1339+
},
1340+
1341+
/**
1342+
* @_module entity
1343+
* @_params [value]
1344+
* @value function
1345+
* @return function
1346+
* @description get or set the draw function for this entity
1347+
*/
1348+
draw: function(value) {
1349+
if (value !== undefined) {
1350+
this._draw = value;
1351+
}
1352+
return this._draw;
1353+
},
11371354

11381355
/**
11391356
* @_module entity

‎boxbox.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎updoc.html

+815-37
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.