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


Java CGPoint.getX方法代码示例

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


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

示例1: moveTowards

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
public void moveTowards (CGPoint position, double timeInterval) {
    CGPoint curPosition = getPosition();
    double dx = position.getX() - curPosition.getX();
    double dy = position.getY() - curPosition.getY();
    double dt = movementSpeed * timeInterval;

    double ang = APAUtils.polarAdjust(APAUtils.getRadiansBetweenPoints(position, curPosition));
    setZRotation(ang);

    double distRemaining = Math.hypot(dx, dy);
    if (distRemaining < dt) {
        setPosition(position);
    } else {
        setPosition(new CGPoint(curPosition.getX() - Math.sin(ang) * dt, curPosition.getY() + Math.cos(ang) * dt));
    }

    requestedAnimation = APAAnimationState.Walk;
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:19,代码来源:APACharacter.java

示例2: moveInDirection

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
public void moveInDirection (CGPoint direction, double timeInterval) {
    CGPoint curPosition = getPosition();
    double dx = movementSpeed * direction.getX();
    double dy = movementSpeed * direction.getY();
    double dt = movementSpeed * timeInterval;

    CGPoint targetPosition = new CGPoint(curPosition.getX() + dx, curPosition.getY() + dy);

    double ang = APAUtils.polarAdjust(APAUtils.getRadiansBetweenPoints(targetPosition, curPosition));
    setZRotation(ang);

    double distRemaining = Math.hypot(dx, dy);
    if (distRemaining < dt) {
        setPosition(targetPosition);
    } else {
        setPosition(new CGPoint(curPosition.getX() - Math.sin(ang) * dt, curPosition.getY() + Math.cos(ang) * dt));
    }

    // Don't change to a walk animation if we planning an attack.
    if (!attacking) {
        requestedAnimation = APAAnimationState.Walk;
    }
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:24,代码来源:APACharacter.java

示例3: pickRandomFacing

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
private void pickRandomFacing (CGPoint position) {
    APAMultiplayerLayeredCharacterScene scene = getCharacterScene();

    // Pick best random facing from 8 test rays.
    double maxDoorCanSee = 0.0;
    double preferredZRotation = 0.0;
    for (int i = 0; i < 8; i++) {
        double testZ = Math.random() * (Math.PI * 2.0);
        CGPoint pos2 = new CGPoint(-Math.sin(testZ) * 1024 + position.getX(), Math.cos(testZ) * 1024 + position.getY());
        double dist = scene.getDistanceToWall(position, pos2);
        if (dist > maxDoorCanSee) {
            maxDoorCanSee = dist;
            preferredZRotation = testZ;
        }
    }

    setZRotation(preferredZRotation);
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:19,代码来源:APACave.java

示例4: updateOffset

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
public void updateOffset () {
    SKScene scene = getScene();
    SKNode parent = getParent();

    if (!usesParallaxEffect || parent == null) {
        return;
    }

    CGPoint scenePos = scene.convertPointFromNode(getPosition(), parent);

    // Calculate the offset directions relative to the center of the screen.
    // Bias to (-0.5, 0.5) range.
    double offsetX = -1.0 + (2.0 * (scenePos.getX() / scene.getSize().getWidth()));
    double offsetY = -1.0 + (2.0 * (scenePos.getY() / scene.getSize().getHeight()));

    double delta = parallaxOffset / getChildren().size();

    int childNumber = 0;
    for (SKNode node : getChildren()) {
        node.setPosition(new CGPoint(offsetX * delta * childNumber, offsetY * delta * childNumber));
        childNumber++;
    }
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:24,代码来源:APAParallaxSprite.java

示例5: getDistanceToWall

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
@Override
public double getDistanceToWall(CGPoint pos0, CGPoint pos1) {
    CGPoint a = convertWorldPointToLevelMapPoint(pos0);
    CGPoint b = convertWorldPointToLevelMapPoint(pos1);

    double deltaX = b.getX() - a.getX();
    double deltaY = b.getY() - a.getY();
    double dist = APAUtils.getDistanceBetweenPoints(a, b);
    double inc = 1.0 / dist;
    CGPoint p = CGPoint.Zero();

    for (double i = 0; i <= 1; i += inc) {
        p.setX(a.getX() + i * deltaX);
        p.setY(a.getY() + i * deltaY);

        APADataMap point = queryLevelMap(p);
        if (point.getWall() > 200) {
            CGPoint wpos2 = convertLevelMapPointToWorldPoint(p);
            return APAUtils.getDistanceBetweenPoints(pos0, wpos2);
        }
    }
    return Float.MAX_VALUE;
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:24,代码来源:APAAdventureScene.java

示例6: canSee

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
@Override
public boolean canSee(CGPoint pos0, CGPoint pos1) {
    CGPoint a = convertWorldPointToLevelMapPoint(pos0);
    CGPoint b = convertWorldPointToLevelMapPoint(pos1);

    double deltaX = b.getX() - a.getX();
    double deltaY = b.getY() - a.getY();
    double dist = APAUtils.getDistanceBetweenPoints(a, b);
    double inc = 1.0 / dist;
    CGPoint p = CGPoint.Zero();

    for (double i = 0; i <= 1; i += inc) {
        p.setX(a.getX() + i * deltaX);
        p.setY(a.getY() + i * deltaY);

        APADataMap point = queryLevelMap(p);
        if (point.getWall() > 200) {
            return false;
        }
    }
    return true;
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:23,代码来源:APAAdventureScene.java

示例7: recoverFromResizing

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
private void recoverFromResizing() {
    setMaxMinZoomScalesForCurrentBounds();

    // Step 1: restore zoom scale, first making sure it is within the
    // allowable range.
    double maxZoomScale = Math.max(getMinimumZoomScale(), scaleToRestoreAfterResize);
    setZoomScale(Math.min(getMaximumZoomScale(), maxZoomScale));

    // Step 2: restore center point, first making sure it is within the
    // allowable range.

    // 2a: convert our desired center point back to our own coordinate space
    CGPoint boundsCenter = convertPointFromView(pointToCenterAfterResize, zoomView);

    // 2b: calculate the content offset that would yield that center point
    CGPoint offset = new CGPoint(boundsCenter.getX() - getBounds().getSize().getWidth() / 2.0, boundsCenter.getY()
            - getBounds().getSize().getHeight() / 2.0);

    // 2c: restore offset, adjusted to be within the allowable range
    CGPoint maxOffset = getMaximumContentOffset();
    CGPoint minOffset = getMinimumContentOffset();

    double realMaxOffset = Math.min(maxOffset.getX(), offset.getX());
    offset.setX(Math.max(minOffset.getX(), realMaxOffset));

    realMaxOffset = Math.min(maxOffset.getY(), offset.getY());
    offset.setY(Math.max(minOffset.getY(), realMaxOffset));

    setContentOffset(offset);
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:31,代码来源:ImageScrollView.java

示例8: convertLevelMapPointToWorldPoint

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
private CGPoint convertLevelMapPointToWorldPoint(CGPoint location) {
    // Given a level map pixel point, convert up to a world point.
    // This determines which "tile" the point falls in and centers within
    // that tile.
    int x = (int) ((location.getX() * LEVEL_MAP_DIVISOR) - (WORLD_CENTER * WORLD_TILE_SIZE / 2));
    int y = (int) -((location.getY() * LEVEL_MAP_DIVISOR) - (WORLD_CENTER * WORLD_TILE_SIZE / 2));
    location.setX(x);
    location.setY(y);
    return location;
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:11,代码来源:APAAdventureScene.java

示例9: convertWorldPointToLevelMapPoint

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
private CGPoint convertWorldPointToLevelMapPoint(CGPoint location) {
    // Given a world based point, resolve to a pixel location in the level
    // map.
    int x = (int) ((location.getX() + WORLD_CENTER) / LEVEL_MAP_DIVISOR);
    int y = (int) ((WORLD_SIZE - (location.getY() + WORLD_CENTER)) / LEVEL_MAP_DIVISOR);
    location.setX(x);
    location.setY(y);
    return location;
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:10,代码来源:APAAdventureScene.java

示例10: didSimulatePhysics

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
@Override
public void didSimulatePhysics() {
    APAHeroCharacter defaultHero = defaultPlayer.hero;

    // Move the world relative to the default player position.
    if (defaultHero != null) {
        CGPoint heroPosition = defaultHero.getPosition();
        CGPoint worldPos = world.getPosition();
        double yCoordinate = worldPos.getY() + heroPosition.getY();
        if (yCoordinate < MIN_HERO_TO_EDGE_DISTANCE) {
            worldPos.setY(worldPos.getY() - yCoordinate + MIN_HERO_TO_EDGE_DISTANCE);
            worldMovedForUpdate = true;
        } else if (yCoordinate > (getFrame().getSize().getHeight() - MIN_HERO_TO_EDGE_DISTANCE)) {
            worldPos.setY(worldPos.getY() + (getFrame().getSize().getHeight() - yCoordinate)
                    - MIN_HERO_TO_EDGE_DISTANCE);
            worldMovedForUpdate = true;
        }

        double xCoordinate = worldPos.getX() + heroPosition.getX();
        if (xCoordinate < MIN_HERO_TO_EDGE_DISTANCE) {
            worldPos.setX(worldPos.getX() - xCoordinate + MIN_HERO_TO_EDGE_DISTANCE);
            worldMovedForUpdate = true;
        } else if (xCoordinate > (getFrame().getSize().getHeight() - MIN_HERO_TO_EDGE_DISTANCE)) {
            worldPos.setX(worldPos.getX() + (getFrame().getSize().getWidth() - xCoordinate)
                    - MIN_HERO_TO_EDGE_DISTANCE);
            worldMovedForUpdate = true;
        }
        world.setPosition(worldPos);
    }
    // Using performSelector:withObject:afterDelay: withg a delay of 0.0
    // means that the selector call occurs after
    // the current pass through the run loop.
    // This means the property will be cleared after the subclass
    // implementation of didSimulatePhysics completes.
    performSelector(clearWorldMoved, null, 0.0);
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:37,代码来源:APAMultiplayerLayeredCharacterScene.java

示例11: setPhoto

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
public void setPhoto(PAPPhoto photo) {
    this.photo = photo;

    // user's avatar
    PAPUser user = photo.getUser();
    if (PAPUtility.userHasProfilePictures(user)) {
        PFFile profilePictureSmall = user.getProfilePicSmall();
        avatarImageView.setFile(profilePictureSmall);
    } else {
        avatarImageView.setImage(PAPUtility.getDefaultProfilePicture());
    }

    avatarImageView.setContentMode(UIViewContentMode.ScaleAspectFill);
    avatarImageView.getLayer().setCornerRadius(17.5);
    avatarImageView.getLayer().setMasksToBounds(true);

    String authorName = user.getDisplayName();
    userButton.setTitle(authorName, UIControlState.Normal);

    double constrainWidth = containerView.getBounds().getSize().getWidth();

    if (buttons.contains(PAPPhotoHeaderButton.User)) {
        userButton.addOnTouchUpInsideListener(didTapUserButton);
    }

    if (buttons.contains(PAPPhotoHeaderButton.Comment)) {
        constrainWidth = commentButton.getFrame().getOrigin().getX();
        commentButton.addOnTouchUpInsideListener(didTapCommentOnPhotoButton);
    }

    if (buttons.contains(PAPPhotoHeaderButton.Like)) {
        constrainWidth = likeButton.getFrame().getOrigin().getX();
        likeButton.addOnTouchUpInsideListener(didTapLikePhotoButton);
    }

    // we resize the button to fit the user's name to avoid having a huge
    // touch area
    CGPoint userButtonPoint = new CGPoint(50, 6);
    constrainWidth -= userButtonPoint.getX();
    CGSize constrainSize = new CGSize(constrainWidth, containerView.getBounds().getSize().getHeight()
            - userButtonPoint.getY() * 2f);

    CGSize userButtonSize = NSString.getBoundingRect(
            userButton.getTitleLabel().getText(),
            constrainSize,
            NSStringDrawingOptions.with(NSStringDrawingOptions.TruncatesLastVisibleLine,
                    NSStringDrawingOptions.UsesLineFragmentOrigin),
            new NSAttributedStringAttributes().setFont(userButton.getTitleLabel().getFont()), null).getSize();

    CGRect userButtonFrame = new CGRect(userButtonPoint.getX(), userButtonPoint.getY(), userButtonSize.getWidth(),
            userButtonSize.getHeight());
    userButton.setFrame(userButtonFrame);

    double timeInterval = photo.getCreatedAt().getTimeIntervalSinceNow();
    String timestamp = timeFormatter.format(timeInterval);
    timestampLabel.setText(timestamp);

    setNeedsDisplay();
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:60,代码来源:PAPPhotoHeaderView.java

示例12: queryLevelMap

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
private APADataMap queryLevelMap(CGPoint point) {
    // Grab the level map pixel for a given x,y (upper left).
    return levelMap[(int) point.getY() * LEVEL_MAP_SIZE + (int) point.getX()];
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:5,代码来源:APAAdventureScene.java

示例13: queryTreeMap

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
private APATreeMap queryTreeMap(CGPoint point) {
    // Grab the tree map pixel for a given x,y (upper left).
    return treeMap[(int) point.getY() * LEVEL_MAP_SIZE + (int) point.getX()];
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:5,代码来源:APAAdventureScene.java

示例14: getRadiansBetweenPoints

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
public static double getRadiansBetweenPoints (CGPoint first, CGPoint second) {
    double deltaX = second.getX() - first.getX();
    double deltaY = second.getY() - first.getY();
    return Math.atan2(deltaY, deltaX);
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:6,代码来源:APAUtils.java

示例15: getPointByAddingPoints

import org.robovm.apple.coregraphics.CGPoint; //导入方法依赖的package包/类
public static CGPoint getPointByAddingPoints (CGPoint first, CGPoint second) {
    return new CGPoint(first.getX() + second.getX(), first.getY() + second.getY());
}
 
开发者ID:robovm,项目名称:robovm-samples,代码行数:4,代码来源:APAUtils.java


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