【问题标题】:I drawed a player into my love2d but it only fills out 1/4?我在love2d中画了一个玩家,但它只填了1/4?
【发布时间】:2015-03-09 18:12:49
【问题描述】:

这是我在 love2d 中跳跃时的角色。 看起来不错,但是..

当我落地时,它看起来像这样。

我发现它可能与 img 有关,它没有填满整个正方形。 所以简直就是脱离了碰撞方块。

这应该是它应该在的广场,但是由于我对编程很陌生,所以我不知道该怎么做。 我一直在寻找解决方案,但找不到一台 ATM。

这是我的 爱.load

function love.load()
love.graphics.setBackgroundColor( 204, 255, 204 )
crazy = love.graphics.newImage("player.png")
pwidth = crazy.getWidth
pheight = crazy.getHeight


AdvTiledLoader.path = "maps/"
map = AdvTiledLoader.load("map.tmx")
map:setDrawRange(0, 0, map.width * map.tileWidth, map.height * map.tileHeight)

camera:setBounds(0, 0, map.width * map.tileWidth - love.graphics.getWidth(), map.height * map.tileHeight - love.graphics.getHeight() )

world =     {
            gravity = 1536,
            ground = 512,
            }

player =    {
            x = 256,
            y = 256,
            x_vel = 0,
            y_vel = 0,
            jump_vel = -1024,
            speed = 512,
            flySpeed = 700,
            state = "",
            h = 32,
            w = 32,
            standing = false,
            }
function player:jump()
    if self.standing then
        self.y_vel = self.jump_vel
        self.standing = false
    end
end

function player:right()
    self.x_vel = self.speed
end

function player:left()
    self.x_vel = -1 * (self.speed)
end

function player:stop()
    self.x_vel = 0
end

function player:collide(event)
    if event == "floor" then
        self.y_vel = 0
        self.standing = true
    end
    if event == "cieling" then
        self.y_vel = 0
    end
end

还有我的爱.draw

function love.draw()
camera:set()

love.graphics.draw(crazy, player.x , player.y)


love.graphics.setColor( 255, 255, 255 )
map:draw()

camera:unset()
end

如果您需要查看我的碰撞或其他任何内容,请询问,我会将其粘贴在下面:)

非常感谢您的帮助!

【问题讨论】:

    标签: lua love2d


    【解决方案1】:

    最有可能发生的是,您将 x,y 坐标作为精灵的中心。所以当地图与中心相遇时它就会停止。

    当您在地图之前绘制精灵时,您只能看到地图未覆盖的部分。

    证明这一点的一种简单方法是在地图之后绘制精灵,您应该在地图上看到整个精灵。

    有几种方法可以解决这个问题。要么将碰撞留在原处,然后使用 ox=-width/2,oy=-height/2 绘制精灵。

    或者通过将宽度/2 和高度/2 添加到碰撞点来在精灵底部进行碰撞。

    如果这没有帮助,那么我们可能需要碰撞逻辑。

    【讨论】:

      【解决方案2】:

      首先,我假设您希望 pwidth/pheight 是数字,而不是 get 函数。

      pwidth = crazy.getWidth()
      pheight = crazy.getHeight()
      

      图像是从它的左上角绘制的,但我猜你的碰撞逻辑让 hitbox 以玩家的位置为中心。

      您可以通过更改绘图函数的坐标来进行补偿,或者将原点偏移量传递给图像。指定原点偏移的好处是您可以相对于该原点进行旋转和缩放。

      love.graphics.draw(crazy, player.x - pwidth/2 , player.y - pheight/2)
      

      或

      rotation, scalex, scaley = 0, 1, 1
      love.graphics.draw(crazy, player.x, player.y, rotation, scalex, scaley, pwidth/2, pheight/2)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-22
        • 2022-01-06
        • 1970-01-01
        • 1970-01-01
        • 2021-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多