Java 在直线或斜坡上向左或向右移动精灵
如果有坡度,我如何向左或向右移动精灵 如果它只是一条直线,就会有类似的东西Java 在直线或斜坡上向左或向右移动精灵,java,libgdx,Java,Libgdx,如果有坡度,我如何向左或向右移动精灵 如果它只是一条直线,就会有类似的东西 if(Pressed(Keys.Left)) position.x-=5; if(Pressed(Keys.Right)) position.x+=5; 但是如果我有这样的东西呢 当我向左或向右走的时候,我如何告诉精灵向上或向下走? 我正在使用libGDX。我建议在游戏中加入重力。重力将始终向下拉动精灵(y轴上为-5),但与地板的碰撞将始终停止精灵。除非有斜坡,否则精灵不会与地板碰撞,它会向下移动,而且
if(Pressed(Keys.Left))
position.x-=5;
if(Pressed(Keys.Right))
position.x+=5;
但是如果我有这样的东西呢
当我向左或向右走的时候,我如何告诉精灵向上或向下走?
我正在使用libGDX。我建议在游戏中加入重力。重力将始终向下拉动精灵(y轴上为-5),但与地板的碰撞将始终停止精灵。除非有斜坡,否则精灵不会与地板碰撞,它会向下移动,而且会沿着按键的方向移动。我建议在游戏中增加重力。重力将始终向下拉动精灵(y轴上为-5),但与地板的碰撞将始终停止精灵。除非有斜坡,否则精灵不会与地板碰撞,它会向下移动,而且会沿着按键的方向移动。我建议在游戏中增加重力。重力将始终向下拉动精灵(y轴上为-5),但与地板的碰撞将始终停止精灵。除非有斜坡,否则精灵不会与地板碰撞,它会向下移动,而且会沿着按键的方向移动。我建议在游戏中增加重力。重力将始终向下拉动精灵(y轴上为-5),但与地板的碰撞将始终停止精灵。除非有坡度,否则精灵不会与地板碰撞,它会向下移动,也会沿着按键的方向移动
final int ELEVATION = 10; // how high above we slope we want to levitate
if(Pressed(Keys.Left)) {
position.x-=5;
int slopecoord = position.y; // you may want to start from 0 if you have steep ascents
// assuming your background is BufferedImage and has same size as playing screen
do {
slopecoord--;
Color c = new Color(bgImage.getRGB(position.x, slopecoord));
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();
//comparing colors takes some effort as your blue in image is not same over the picture
while( Math.abs(red - 48) < 25 && Math.abs(green - 158) < 25 && blue > 200 );
position.y = slopecoord - ELEVATION;
}
final int-ELEVATION=10;//我们想漂浮在多高的斜坡上
如果(按下(左键)){
位置x-=5;
int slopecord=position.y;//如果您有陡峭的上升,您可能希望从0开始
//假设您的背景是BuffereImage,并且与播放屏幕大小相同
做{
slopecord--;
颜色c=新颜色(bgImage.getRGB(position.x,slopecord));
int red=c.getRed();
int green=c.getGreen();
int blue=c.getBlue();
//比较颜色需要一些努力,因为图像中的蓝色与图片中的不同
而(数学abs(红色-48)<25和数学abs(绿色-158)<25和蓝色>200);
位置y=坡度命令-高程;
}
final int ELEVATION = 10; // how high above we slope we want to levitate
if(Pressed(Keys.Left)) {
position.x-=5;
int slopecoord = position.y; // you may want to start from 0 if you have steep ascents
// assuming your background is BufferedImage and has same size as playing screen
do {
slopecoord--;
Color c = new Color(bgImage.getRGB(position.x, slopecoord));
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();
//comparing colors takes some effort as your blue in image is not same over the picture
while( Math.abs(red - 48) < 25 && Math.abs(green - 158) < 25 && blue > 200 );
position.y = slopecoord - ELEVATION;
}
final int-ELEVATION=10;//我们要悬浮的坡度有多高
如果(按下(左键)){
位置x-=5;
int slopecord=position.y;//如果您有陡峭的上升,您可能希望从0开始
//假设您的背景是BuffereImage,并且与播放屏幕大小相同
做{
slopecord--;
颜色c=新颜色(bgImage.getRGB(position.x,slopecord));
int red=c.getRed();
int green=c.getGreen();
int blue=c.getBlue();
//比较颜色需要一些努力,因为图像中的蓝色与图片中的不同
而(数学abs(红色-48)<25和数学abs(绿色-158)<25和蓝色>200);
位置y=坡度命令-高程;
}
final int ELEVATION = 10; // how high above we slope we want to levitate
if(Pressed(Keys.Left)) {
position.x-=5;
int slopecoord = position.y; // you may want to start from 0 if you have steep ascents
// assuming your background is BufferedImage and has same size as playing screen
do {
slopecoord--;
Color c = new Color(bgImage.getRGB(position.x, slopecoord));
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();
//comparing colors takes some effort as your blue in image is not same over the picture
while( Math.abs(red - 48) < 25 && Math.abs(green - 158) < 25 && blue > 200 );
position.y = slopecoord - ELEVATION;
}
final int-ELEVATION=10;//我们要悬浮的坡度有多高
如果(按下(左键)){
位置x-=5;
int slopecord=position.y;//如果您有陡峭的上升,您可能希望从0开始
//假设您的背景是BuffereImage,并且与播放屏幕大小相同
做{
slopecord--;
颜色c=新颜色(bgImage.getRGB(position.x,slopecord));
int red=c.getRed();
int green=c.getGreen();
int blue=c.getBlue();
//比较颜色需要一些努力,因为图像中的蓝色与图片中的不同
而(数学abs(红色-48)<25和数学abs(绿色-158)<25和蓝色>200);
位置y=坡度命令-高程;
}
final int ELEVATION = 10; // how high above we slope we want to levitate
if(Pressed(Keys.Left)) {
position.x-=5;
int slopecoord = position.y; // you may want to start from 0 if you have steep ascents
// assuming your background is BufferedImage and has same size as playing screen
do {
slopecoord--;
Color c = new Color(bgImage.getRGB(position.x, slopecoord));
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();
//comparing colors takes some effort as your blue in image is not same over the picture
while( Math.abs(red - 48) < 25 && Math.abs(green - 158) < 25 && blue > 200 );
position.y = slopecoord - ELEVATION;
}
final int-ELEVATION=10;//我们要悬浮的坡度有多高
如果(按下(左键)){
位置x-=5;
int slopecord=position.y;//如果您有陡峭的上升,您可能希望从0开始
//假设您的背景是BuffereImage,并且与播放屏幕大小相同
做{
slopecord--;
颜色c=新颜色(bgImage.getRGB(position.x,slopecord));
int red=c.getRed();
int green=c.getGreen();
int blue=c.getBlue();
//比较科罗拉多