@Override public Layer setAlpha(float alpha) { this.alpha = alpha; int ialpha = (int)(0xFF * MathUtil.clamp(alpha, 0, 1)); this.tint = (ialpha << 24) | (tint & 0xFFFFFF); return this; }
/** Sets the alpha component of {@code tint} to {@code alpha}. * @return the new tint. */ public static int setAlpha(int tint, float alpha) { int ialpha = (int)(0xFF * MathUtil.clamp(alpha, 0, 1)); return (ialpha << 24) | (tint & 0xFFFFFF); }
@Override public Surface setAlpha(float alpha) { int ialpha = (int)(0xFF * MathUtil.clamp(alpha, 0, 1)); this.tint = (ialpha << 24) | (tint & 0xFFFFFF); return this; }
/** Sets the alpha component of {@code tint} to {@code alpha}. * @return the new tint. */ public static int setAlpha(int tint, float alpha) { int ialpha = (int)(0xFF * MathUtil.clamp(alpha, 0, 1)); return (ialpha << 24) | (tint & 0xFFFFFF); }
/** * Sets the alpha component of this layer's current tint. Note that this value will be quantized * to an integer between 0 and 255. Also see {@link #setTint}. * * <p> Values outside the range [0,1] will be clamped to the range [0,1]. </p> * * @param alpha alpha value in range [0,1] where 0 is transparent and 1 is opaque. * * @return a reference to this layer for call chaining. */ public Layer setAlpha(float alpha) { this.alpha = alpha; int ialpha = (int)(0xFF * MathUtil.clamp(alpha, 0, 1)); this.tint = (ialpha << 24) | (tint & 0xFFFFFF); return this; }
@Override public void setVolume(float volume) { this.volume = MathUtil.clamp(volume, 0, 1); if (impl != null) setVolumeImpl(this.volume); }
@Override public void setVolume(float volume) { this.volume = MathUtil.clamp(volume, 0, 1); if (impl != null) setVolumeImpl(this.volume); }
/** * Interpolates between two values, as in {@link #apply} except that {@code dt} is clamped to * [0..t] to avoid interpolation weirdness if {@code dt} is ever negative or exceeds {@code t}. */ public float applyClamp (float start, float range, float dt, float t) { return apply(start, range, MathUtil.clamp(dt, 0, t), t); } }
@Override public void setVolume(float volume) { this.volume = MathUtil.clamp(volume, 0, 1); if (impl != null) setVolumeImpl(this.volume); }
@Override protected Float updateAndNotifyIf (Float value) { return super.updateAndNotifyIf(MathUtil.clamp(value, 0, 1)); } };
@Override public void becameActive () { setPosition(MathUtil.clamp(position, min, max)); _vel = 0; }
public void update (float delta) { if (_vel.x == 0 && _vel.y == 0) return; _prev.set(_position); // apply x and y velocity float x = MathUtil.clamp(_position.x + _vel.x * delta, _min.x, _max.x); float y = MathUtil.clamp(_position.y + _vel.y * delta, _min.y, _max.y); // stop when we hit the edges if (x == _position.x) _vel.x = 0; if (y == _position.y) _vel.y = 0; _position.set(x, y); // apply x and y acceleration _vel.x = applyAccelertion(_vel.x, _accel.x, delta); _vel.y = applyAccelertion(_vel.y, _accel.y, delta); }
/** * Computes the point inside the bounds of the rectangle that's closest to the given point, * writing the result into {@code out}. * @return {@code out} for call chaining convenience. */ public static Point closestInteriorPoint (IRectangle r, IPoint p, Point out) { out.set(MathUtil.clamp(p.x(), r.minX(), r.maxX()), MathUtil.clamp(p.y(), r.minY(), r.maxY())); return out; }
/** * Computes the point inside the bounds of the rectangle that's closest to the given point, * writing the result into {@code out}. * @return {@code out} for call chaining convenience. */ public static Point closestInteriorPoint (IRectangle r, IPoint p, Point out) { out.set(MathUtil.clamp(p.x(), r.minX(), r.maxX()), MathUtil.clamp(p.y(), r.minY(), r.maxY())); return out; }
@Override protected void update (Clock clock, Entities entities) { Vector v = _vel; for (int ii = 0, ll = entities.size(); ii < ll; ii++) { int eid = entities.get(ii); spin.set(eid, _angvel); if (_accel != 0) { Layer s = sprite.get(eid); float ang = s.rotation(); vel.get(eid, v); v.x = MathUtil.clamp(v.x + FloatMath.cos(ang)*_accel, -MAX_VEL, MAX_VEL); v.y = MathUtil.clamp(v.y + FloatMath.sin(ang)*_accel, -MAX_VEL, MAX_VEL); vel.set(eid, v); } } }
@Override public void onDrag (Pointer.Interaction iact) { // check whether we are processing this interaction if (_state != DRAGGING) return; _prev = _cur; _prevStamp = _curStamp; _cur = getPosition(iact.event); _curStamp = iact.event.time; // update our position based on the drag delta float delta = _cur - _start; setPosition(_origPos + delta); // if we're not allowed to rebound, clamp the position to our bounds if (!allowRebound()) setPosition(MathUtil.clamp(position, min, max)); // otherwise if we're exceeding min/max then only use a fraction of the delta else if (position < min) position += (min-position)*overFraction(); else if (position > max) position -= (position-max)*overFraction(); float absDelta = Math.abs(delta); if (!_minFlickExceeded && absDelta > maxClickDelta()) { _minFlickExceeded = true; minFlickExceeded(iact); } _maxDelta = Math.max(absDelta, _maxDelta); }