Skip to content

Commit

Permalink
3.16.6
Browse files Browse the repository at this point in the history
  • Loading branch information
quinton-ashley committed Nov 17, 2023
1 parent 1e3c9f7 commit c109255
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 31 deletions.
54 changes: 39 additions & 15 deletions p5play.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,20 @@ class Sprite {
* </a>
*
* The Sprite constructor can be used in many different ways.
*
* In fact it's so flexible that I've only listed out some of the
* most common ways it can be used in the examples section below.
* Try experimenting with it! It's likely to work the way you
* expect it to, if not you'll just get an error.
*
* Special feature! If the first parameter to this constructor is a
* loaded p5.Image, SpriteAnimation, or name of a SpriteAnimation,
* then the Sprite will be created with that animation. If the
* dimensions of the sprite are not given, then the Sprite will be
* created using the dimensions of the animation.
*
* Every sprite you create is added to the `allSprites`
* group and put on the top layer, in front of all
* group and put on the top draw order layer, in front of all
* previously created sprites.
*
* @param {Number} [x] - horizontal position of the sprite
Expand All @@ -91,12 +103,14 @@ class Sprite {
* 'static', 'kinematic', or 'none'
* @example
*
* let sprite = new Sprite();
* let spr = new Sprite();
*
* let rectangle = new Sprite(x, y, width, height);
*
* let circle = new Sprite(x, y, diameter);
*
* let spr = new Sprite(aniName, x, y);
*
* let line = new Sprite(x, y, [length, angle]);
*/
constructor(x?: number, y?: number, w?: number, h?: number, collider?: string, ...args: any[]);
Expand Down Expand Up @@ -201,6 +215,12 @@ class Sprite {
* @type {Number}
*/
get w(): number;
set h(arg: number);
/**
* The height of the sprite.
* @type {Number}
*/
get h(): number;
/**
* The sprite's position on the previous frame.
* @type {object}
Expand Down Expand Up @@ -757,12 +777,6 @@ class Sprite {
* @type {Number}
*/
get halfWidth(): number;
set h(arg: number);
/**
* The height of the sprite.
* @type {Number}
*/
get h(): number;
set hh(arg: number);
/**
* Half the height of the sprite.
Expand Down Expand Up @@ -881,14 +895,22 @@ class Sprite {
*/
applyTorque(val: any): void;
/**
* Moves a sprite towards a position.
* Moves a sprite towards a position at a percentage of the distance
* between itself and the destination.
*
* @param {Number|Object} x|position destination x or any object with x and y properties
* @param {Number} y destination y
* @param {Number} tracking [optional] 1 represents 1:1 tracking, the mouse moves to the destination immediately, 0 represents no tracking. Default is 0.1 (10% tracking).
* @param {Number|Object} x destination x or any object with x and y properties
* @param {Number} [y] destination y
* @param {Number} [tracking] 1 represents 1:1 tracking, the mouse moves to the destination immediately, 0 represents no tracking. Default is 0.1 (10% tracking).
*/
moveTowards(x: number | any, y: number, tracking: number): void;
moveAway(x: any, y: any, repel: any, ...args: any[]): void;
moveTowards(x: number | any, y?: number, tracking?: number): void;
/**
* Moves the sprite away from a position, the opposite of moveTowards,
* at a percentage of the distance between itself and the position.
* @param {Number} x
* @param {Number} [y]
* @param {Number} [repel] range from 0-1
*/
moveAway(x: number, y?: number, repel?: number, ...args: any[]): void;
/**
* Move the sprite a certain distance from its current position.
*
Expand Down Expand Up @@ -1746,7 +1768,9 @@ class Group extends Array<Sprite> {
/**
*/
moveTowards(x: any, y: any, tracking: any): void;
moveAway(x: any, y: any, tracking: any): void;
/**
*/
moveAway(x: any, y: any, repel: any): void;
/**
* Alias for group.length
* @deprecated
Expand Down
57 changes: 43 additions & 14 deletions p5play.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,20 @@ p5.prototype.registerMethod('init', function p5playInit() {
* </a>
*
* The Sprite constructor can be used in many different ways.
*
* In fact it's so flexible that I've only listed out some of the
* most common ways it can be used in the examples section below.
* Try experimenting with it! It's likely to work the way you
* expect it to, if not you'll just get an error.
*
* Special feature! If the first parameter to this constructor is a
* loaded p5.Image, SpriteAnimation, or name of a SpriteAnimation,
* then the Sprite will be created with that animation. If the
* dimensions of the sprite are not given, then the Sprite will be
* created using the dimensions of the animation.
*
* Every sprite you create is added to the `allSprites`
* group and put on the top layer, in front of all
* group and put on the top draw order layer, in front of all
* previously created sprites.
*
* @param {Number} [x] - horizontal position of the sprite
Expand All @@ -194,12 +206,14 @@ p5.prototype.registerMethod('init', function p5playInit() {
* 'static', 'kinematic', or 'none'
* @example
*
* let sprite = new Sprite();
* let spr = new Sprite();
*
* let rectangle = new Sprite(x, y, width, height);
*
* let circle = new Sprite(x, y, diameter);
*
* let spr = new Sprite(aniName, x, y);
*
* let line = new Sprite(x, y, [length, angle]);
*/
constructor(x, y, w, h, collider) {
Expand Down Expand Up @@ -244,30 +258,45 @@ p5.prototype.registerMethod('init', function p5playInit() {
throw new FriendlyError('Sprite', 0, [args[0]]);
}

x = args[0];
y = args[1];
w = args[2];
h = args[3];
collider = args[4];

if (Array.isArray(x)) {
if (!Array.isArray(args[0])) {
// valid use for creating a box collider:
// new Sprite(x, y, w, h, colliderType)
x = args[0];
y = args[1];
w = args[2];
h = args[3];
collider = args[4];
} else {
// valid use for creating chain/polygon using vertex mode:
// new Sprite([[x1, y1], [x2, y2], ...], colliderType)
x = undefined;
y = undefined;
w = args[0];
h = args[1];
collider = args[2];
h = undefined;
collider = args[1];
if (Array.isArray(collider)) {
throw new FriendlyError('Sprite', 1, [`[[${w}], [${h}]]`]);
}
}

// valid use without setting size:
// new Sprite(x, y, colliderType)
if (typeof w == 'string') {
collider = w;
w = undefined;
}

// valid use to create a circle: new Sprite(x, y, d, colliderType)
if (typeof h == 'string') {
if (isColliderType(h)) {
// valid use to create a circle:
// new Sprite(x, y, d, colliderType)
collider = h;
} else {
// valid use to create a regular polygon:
// new Sprite(x, y, sideLength, polygonName)
w = getRegularPolygon(w, h);
}
h = undefined;
} else if (Array.isArray(h)) {
throw new FriendlyError('Sprite', 1, [`[[${w}], [${h}]]`]);
}

this.idNum = this.p.p5play.spritesCreated;
Expand Down
2 changes: 1 addition & 1 deletion p5play.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"version": "git add -A",
"postversion": "git push"
},
"version": "3.16.5"
"version": "3.16.6"
}

0 comments on commit c109255

Please sign in to comment.