Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problem with player sprite behavior
Started by juandariogarciagimeno Mar 08 2019 03:32 PM

No replies to this topic
sprite pyhsics bounds
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

juandariogarciagimeno

[GLOBAL: userInfoPane.html]
juandariogarciagimeno
  • Observer

  • 2 posts
  • Corona SDK

Hello, I just started using corona and I'm having a little trouble with the behavior of the character's sprite, even having well configured values for both the character and the platforms (or so I think) it seems to have a different size and... well an image says more than a thousand words

 

0VsXK9c.png

 

It's not falling, it seems that it's body is so wide that it's still on the platform and is hitting either the front platform or the upper one. (I've manually added the borders)

 

Here is my code for the character

    local options = local options = {
         width = 192,
         height = 159,
         numFrames = 8,
         --sheetContentWidth = 160,  
         --sheetContentHeight = 200
    }
    local animations = {
    {
      name = "static-f",
      frames = {3},
      time = 400,
      loopCount = 0,
      loopDirection = 0
    },
    {
      name = "move-forward",
      frames = {1, 2, 3, 4},
      time = 400,
      loopCount = 0,
      loopDirection = 0
    },
    {
      name = "static-b",
      frames = {6},
      time = 400,
      loopCount = 0,
      loopDirection = 0
    },
    {
      name = "move-backward",
      frames = {5, 6, 7, 8},
      time = 400,
      loopCount = 0,
      loopDirection = 0
    }
}

    local sheetPersonaje = graphics.newImageSheet("images/sprite.png", options)

    local personaje = display.newSprite(sheetPersonaje, animations)
    local psPersonaje = physic.addBody(personaje, {density = 5, bounce = 0.01, friction=1})
    personaje.x = 145
    personaje.y = 300
    personaje.anchorX = 0
    personaje.anchorY = 0
    personaje.width = 0
    personaje.height = 0
    personaje.isFixedRotation = true
    personaje.angularVelocity = 0
    personaje.sensorOverlaps = 0
    personaje:scale(0.53, 0.53)
    personaje.stroke = {1, 0, 0.5}
    personaje.strokeWidth = 4
    personaje:play()

And here my code for a single platform (since all others have the same properties except for the position)

    local platform = display.newRect(150, 400, 120,30)
    platform.objType = "ground"
    platform:setFillColor( color )
    local paPlatform = physic.addBody(levelPlatform[i], "static", { friction=1, bounce=0 })
    platform.stroke = {1, 0, 0.5}
    platform.strokeWidth = 4

Thanks in advance :)




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: sprite, pyhsics, bounds