当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.clamp方法代码示例

本文整理汇总了Java中com.badlogic.gdx.math.MathUtils.clamp方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.clamp方法的具体用法?Java MathUtils.clamp怎么用?Java MathUtils.clamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.math.MathUtils的用法示例。


在下文中一共展示了MathUtils.clamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: trustEffect

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private void trustEffect() {

        // work towards full thrust.
        if (active) {
            timer += world.delta * 0.25f;
            timer = MathUtils.clamp(timer, 0f, 1f);
            speedFactor = Interpolation.exp5.apply(timer * 0.6f);
            if (playSoundState == 0) {
                playSoundState = 1;
            }
        } else {
            timer -= world.delta * 0.25f;
            timer = MathUtils.clamp(timer, 0f, 1f);
            speedFactor = Interpolation.exp5.apply(timer * 0.6f);
            if (playSoundState == 1) {
                playSoundState = 0;
            }
        }

    }
 
开发者ID:DaanVanYperen,项目名称:odb-little-fortune-planet,代码行数:21,代码来源:StarEffectSystem.java

示例2: processSystem

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
protected void processSystem() {


    float halfScreenWidth = (Gdx.graphics.getWidth() / G.CAMERA_ZOOM) * 0.5f;
    float halfScreenHeight = (Gdx.graphics.getHeight() / G.CAMERA_ZOOM) * 0.5f;

    float minCameraX = halfScreenWidth;
    float maxCameraX = mapSystem.width * G.CELL_SIZE - halfScreenWidth;
    float minCameraY = halfScreenHeight;
    float maxCameraY = mapSystem.height * G.CELL_SIZE - halfScreenHeight;

    if (minCameraX > maxCameraX) {
        maxCameraX = minCameraX;
    }
    if (minCameraY > maxCameraY) maxCameraY = minCameraY;

    cameraSystem.camera.position.x = MathUtils.clamp(cameraSystem.camera.position.x, minCameraX, maxCameraX);
    cameraSystem.camera.position.y = MathUtils.clamp(cameraSystem.camera.position.y, minCameraY, maxCameraY);
    cameraSystem.camera.update();
}
 
开发者ID:DaanVanYperen,项目名称:odb-artax,代码行数:22,代码来源:CameraClampToMapSystem.java

示例3: smoothMask

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private void smoothMask(Planet planet) {
    for (int y = 1; y < (SIMULATION_HEIGHT / GRADIENT_SCALE) - 1; y++) {
        if (G.INTERLACING_SIMULATION && y % 2 == lace) {
            for (int x = 1; x < (SIMULATION_WIDTH / GRADIENT_SCALE) - 1; x++) {
                planet.tempMask[y][x].temperature = planet.mask[y][x].temperature;
                for (int i = 0; i < 8; i++) {
                    planet.tempMask[y][x].temperature =
                            Math.max(
                                    (planet.mask[y + PlanetCell.directions[i][1]][x + PlanetCell.directions[i][0]].temperature) * TEMPERATURE_LOSS,
                                    planet.tempMask[y][x].temperature
                            );
                }
            }
        }
    }
    for (int y = 1; y < (SIMULATION_HEIGHT / GRADIENT_SCALE) - 1; y++) {
        for (int x = 1; x < (SIMULATION_WIDTH / GRADIENT_SCALE) - 1; x++) {
            planet.mask[y][x].temperature = MathUtils.clamp(planet.tempMask[y][x].temperature, -100f, StatusMask.MAX_TEMPERATURE) * 0.95f;
        }
    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-little-fortune-planet,代码行数:22,代码来源:PlanetMaskSystem.java

示例4: render

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void render() {
    if (Gdx.input.justTouched() && Gdx.input.getY() < 100) {
        if (Gdx.input.getX() < 100) {
            xOffsetTarget = Math.max(xOffsetTarget - 0.2f, 0);
        } else if (Gdx.input.getX() > (Gdx.graphics.getWidth() - 100)) {
            xOffsetTarget = Math.min(xOffsetTarget + 0.2f, 1);
        }
        MathUtils.clamp(xOffsetTarget, 0, 1);
    }
    xOffset += (xOffsetTarget - xOffset) * 2 * Gdx.graphics.getDeltaTime();

    handleFakeTouch();

    liveWallpaper.render();
    liveWallpaper.render(xOffsetFake, 0.5f, xOffsetFake, xOffsetFake);
}
 
开发者ID:CypherCove,项目名称:gdx-cclibs,代码行数:18,代码来源:DesktopLiveWallpaperWrapper.java

示例5: updateMotionX

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
protected void updateMotionX(float deltaTime) {
    if (velocity.x != 0) {
        //应用摩擦力
        if (velocity.x > 0) {
            velocity.x = Math.max(velocity.x - friction.x * deltaTime, 0);
        } else {
            velocity.x = Math.max(velocity.x + friction.x * deltaTime, 0);
        }
    }

    //应用加速度
    velocity.x += acceleration.x * deltaTime;
    //确保速度没超过最大值
    velocity.x = MathUtils.clamp(velocity.x, -terminalVelocity.x, terminalVelocity.x);
}
 
开发者ID:davyjoneswang,项目名称:libgdx-learnlib,代码行数:16,代码来源:AbstractGameObject.java

示例6: getCurvePercent

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Returns the interpolated percentage for the specified key frame and linear percentage. */
public float getCurvePercent (int frameIndex, float percent) {
	percent = MathUtils.clamp(percent, 0, 1);
	float[] curves = this.curves;
	int i = frameIndex * BEZIER_SIZE;
	float type = curves[i];
	if (type == LINEAR) return percent;
	if (type == STEPPED) return 0;
	i++;
	float x = 0;
	for (int start = i, n = i + BEZIER_SIZE - 1; i < n; i += 2) {
		x = curves[i];
		if (x >= percent) {
			float prevX, prevY;
			if (i == start) {
				prevX = 0;
				prevY = 0;
			} else {
				prevX = curves[i - 2];
				prevY = curves[i - 1];
			}
			return prevY + (curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
		}
	}
	float y = curves[i - 1];
	return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
}
 
开发者ID:laurencegw,项目名称:jenjin,代码行数:28,代码来源:Animation.java

示例7: process

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
protected void process(E e) {
    if (e.explosivePrimed()) {
        int cx = (int) (e.posX() + e.boundsCx());
        int cy = (int) (e.posY() + e.boundsCy());
        drawingSystem.draw(planetCreationSystem.planetEntity,
                cx, cy,
                e.explosiveYield(),
                PlanetCell.CellType.FIRE);
        e.deleteFromWorld();

        for (E wanderer : allEntitiesMatching(Aspect.all(Wander.class, Pos.class, Physics.class))) {

            v2.set(wanderer.posX(), wanderer.posY()).sub(cx, cy);

            float len = Math.abs(v2.len());
            if (len < 100) {
                float strength = MathUtils.clamp(0, 220 - len, 100);
                v2.nor().scl(strength);

                v3.set(wanderer.posX(), wanderer.posY()).sub(G.PLANET_CENTER_X, G.PLANET_CENTER_Y).nor().scl(strength / 2);

                v2.add(v3);

                wanderer.physicsVx(v2.x);
                wanderer.physicsVy(v2.y);
            }
        }
    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-little-fortune-planet,代码行数:31,代码来源:ExplosiveSystem.java

示例8: readJson

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void readJson(JsonValue json) {
	this.f = json.asFloat();
	if (hasRange)
		MathUtils.clamp(f, rangeStart, rangeEnd);
	onChange();
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:8,代码来源:FloatSetting.java

示例9: calculateFadeout

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Calculates the fadeout of this effect, if any. Only considers the second half of the duration. */
protected float calculateFadeout () {
	if (Float.isInfinite(duration)) return 1;

	// Calculate raw progress
	float progress = MathUtils.clamp(totalTime / duration, 0, 1);

	// If progress is before the split point, return a full factor
	if (progress < FADEOUT_SPLIT) return 1;

	// Otherwise calculate from the split point
	return Interpolation.smooth.apply(1, 0, (progress - FADEOUT_SPLIT) / (1f - FADEOUT_SPLIT));
}
 
开发者ID:rafaskb,项目名称:typing-label,代码行数:14,代码来源:Effect.java

示例10: onApply

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
protected void onApply (Glyph glyph, int localIndex) {
	// Make sure we can hold enough entries for the current index
	if (localIndex >= lastOffsets.size / 2) {
		lastOffsets.setSize(lastOffsets.size + 16);
	}

	// Get last offsets
	float lastX = lastOffsets.get(localIndex * 2);
	float lastY = lastOffsets.get(localIndex * 2 + 1);

	// Calculate new offsets
	float x = getLineHeight() * distance * MathUtils.random(-1, 1) * DEFAULT_DISTANCE;
	float y = getLineHeight() * distance * MathUtils.random(-1, 1) * DEFAULT_DISTANCE;

	// Apply intensity
	float normalIntensity = MathUtils.clamp(intensity * DEFAULT_INTENSITY, 0, 1);
	x = Interpolation.linear.apply(lastX, x, normalIntensity);
	y = Interpolation.linear.apply(lastY, y, normalIntensity);

	// Apply fadeout
	float fadeout = calculateFadeout();
	x *= fadeout;
	y *= fadeout;
	x = Math.round(x);
	y = Math.round(y);

	// Store offsets for the next tick
	lastOffsets.set(localIndex * 2, x);
	lastOffsets.set(localIndex * 2 + 1, y);

	// Apply changes
	glyph.xoffset += x;
	glyph.yoffset += y;
}
 
开发者ID:rafaskb,项目名称:typing-label,代码行数:36,代码来源:ShakeEffect.java

示例11: setOpacity

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
* Change node opacity.
* @param opacity A float opacity value. [0, 1]
*/
public void setOpacity(float opacity) {
 _displayColor.a = _opacity = MathUtils.clamp(opacity, 0, 1);
 updateCascadeOpacity();
}
 
开发者ID:mingwuyun,项目名称:cocos2d-java,代码行数:9,代码来源:Node.java

示例12: updateVelocities

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private void updateVelocities() {
    velocity.x = MathUtils.clamp(velocity.x + acceleration.x, -1, 1f);
    velocity.y = MathUtils.clamp(velocity.y + acceleration.y, -1f, 3f);
    acceleration.x *= 0f; /* make player left and right movement very responsive. */
}
 
开发者ID:treeman1111,项目名称:Particles,代码行数:6,代码来源:Player.java

示例13: setXSpeed

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
public void setXSpeed(float x_speed) {
	this.x_speed = MathUtils.clamp(x_speed, .01f, 100f);
}
 
开发者ID:kyperbelt,项目名称:KyperBox,代码行数:4,代码来源:GameCameraSystem.java

示例14: applyGravity

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private void applyGravity() {
    acceleration.y = MathUtils.clamp(acceleration.y - 0.25f, -0.25f, 10);
}
 
开发者ID:treeman1111,项目名称:Particles,代码行数:4,代码来源:Player.java

示例15: Update

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
public void Update(float y, Vector3 vectorUp, Vector3 position, float elapsedTime)
{
 this.up.set(vectorUp);
    boolean needResetTie = false;
    time += elapsedTime;
    if (y != lastY)
    {
        interpolatedSpeed = MathUtils.clamp(chaseSpeed * elapsedTime, 0.0f, 1.0f);
        y = Utils.Lerp(lastY, y, interpolatedSpeed);
    }
    else
    {
        needResetTie = true;
    }
   
    if (lastPosition != position)
    {
        interpolatedSpeed = MathUtils.clamp(chaseSpeed * elapsedTime, 0.0f, 1.0f);
        this.position.set(Utils.Lerp(lastPosition, position, interpolatedSpeed));
    }
    else
    {
        needResetTie = true;
    }
    if (needResetTie)
    {
        time = 0f;
    }
    
    Matrix4 rotationMatrix = new Matrix4();
    rotationMatrix.setToRotation(0, 1, 0, y);
    Vector3 transformedheadOffset = Utils.Transform(AvatarHeadOffset, rotationMatrix);
    Vector3 transformedReference = Utils.Transform(TargetOffset, rotationMatrix);

    Vector3 cameraPosition = Utils.addVector(this.position, transformedheadOffset);
    Vector3 cameraTarget = Utils.addVector(this.position , transformedReference);
    
    vectorUp  = Utils.Transform(vectorUp, rotationMatrix);

    lastY = y;
    lastPosition = this.position;
    
    view.setToLookAt(cameraPosition, cameraTarget, vectorUp);
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:45,代码来源:ChaseCamera.java


注:本文中的com.badlogic.gdx.math.MathUtils.clamp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。