images are backwards on screen

Hello,  I created a very basic game that has images randomly appearing from the left and right of the screen heading toward an object in the middle of the screen.  when they objects come from the right side, they are backwards.  Is there some small fix for this?

Thanks!

Can you post your code?  What do you mean “backwards”?  Screenshot?

Hello, here is the chunk where the enemy png files are spawned.  I think this is where its at.  For example one pic is basically the letters HP.  Its fine when it comes from the left side.  When it spawns from the right side, it shows PH so its reversed for some reason.  this is just a basic game for fun and my first one so the code is not too complex.  thanks for looking.

function spawnEnemy()

    local enemypics = {“Windows3.png”,“linux3.png”, “samsung3.png”,“Fire.png”,“Galaxy.png”,“redhat.png”,“hp.png”,“dell.png”}

    local enemy = display.newImage(enemypics[math.random (#enemypics)])

    enemy:addEventListener ( “tap”, shipSmash )

    

    if math.random(2) == 1 then

        enemy.x = math.random ( -100, -10 )

    else

        enemy.x = math.random ( display.contentWidth + 10, display.contentWidth + 100 )

        enemy.xScale = -1

    end

    enemy.y = math.random (display.contentHeight)

    enemy.trans = transition.to ( enemy, { x=centerX, y=centerY, time=math.random(2500-speedBump, 4500-speedBump), onComplete=hitPlanet } )

    speedBump = speedBump + 50

    

end

When you write enemy.xScale = -1 (a negative number), that causes the image to be flipped x-wise (i.e., over a vertical line cut through the middle of the image).  So the behavior you’re seeing is correct.  Were you trying to accomplish something different when you wrote enemy.xScale = -1?

  • Andrew

Hi Andrew, its always good to have someone else look at the code.  I removed the - sign from the 1 and it worked.  Thanks for pointing that out.  i was actually working from a tutorial and realized after you said that the example had the enemy objects reversed like that so it looked like they were coming from that direction.  however in my code it did not need to do that.  thanks again!

Can you post your code?  What do you mean “backwards”?  Screenshot?

Hello, here is the chunk where the enemy png files are spawned.  I think this is where its at.  For example one pic is basically the letters HP.  Its fine when it comes from the left side.  When it spawns from the right side, it shows PH so its reversed for some reason.  this is just a basic game for fun and my first one so the code is not too complex.  thanks for looking.

function spawnEnemy()

    local enemypics = {“Windows3.png”,“linux3.png”, “samsung3.png”,“Fire.png”,“Galaxy.png”,“redhat.png”,“hp.png”,“dell.png”}

    local enemy = display.newImage(enemypics[math.random (#enemypics)])

    enemy:addEventListener ( “tap”, shipSmash )

    

    if math.random(2) == 1 then

        enemy.x = math.random ( -100, -10 )

    else

        enemy.x = math.random ( display.contentWidth + 10, display.contentWidth + 100 )

        enemy.xScale = -1

    end

    enemy.y = math.random (display.contentHeight)

    enemy.trans = transition.to ( enemy, { x=centerX, y=centerY, time=math.random(2500-speedBump, 4500-speedBump), onComplete=hitPlanet } )

    speedBump = speedBump + 50

    

end

When you write enemy.xScale = -1 (a negative number), that causes the image to be flipped x-wise (i.e., over a vertical line cut through the middle of the image).  So the behavior you’re seeing is correct.  Were you trying to accomplish something different when you wrote enemy.xScale = -1?

  • Andrew

Hi Andrew, its always good to have someone else look at the code.  I removed the - sign from the 1 and it worked.  Thanks for pointing that out.  i was actually working from a tutorial and realized after you said that the example had the enemy objects reversed like that so it looked like they were coming from that direction.  however in my code it did not need to do that.  thanks again!