Displaying Image in Corona sdk

343 views Asked by At

I've been making a game with Corona SDK. I'm trying display an image in the middle of the screen, but it displays in the random location. Image that I'm trying to display is circle.png. Please help me if you can.

Here is the code:

local composer = require( "composer" )

strong textlocal scene = composer.newScene()
local widget = require "widget"
widget.setTheme ("widget_theme_ios")



local score
local scoreEarn = 1 

local lives = {} 
local livesCount = 1

local balls = {}

local ballsCount = 0 

local ballsSendSpeed = 65 

local ballsTravelSpeed = 3500 

local ballsIncrementSpeed = 1.5 

local ballsMaxSendSpeed = 30

local timer_Counter

local onGameOver, gameOverBox, gameoverBackground, btn_returnToMenu 

-- -------------------------------------------------------------------------------


-- "scene:create()"
function scene:create( event )

    local sceneGroup = self.view

    -- Initialize the scene here.
    -- Example: add display objects to "sceneGroup", add touch listeners, etc.
local function ballTap(event)

end

local function ballDrag()

end

local function ballSend ()

end

local function ballsCollision ()

end 

local function onCollision (event)

end

local function circleDamage ()

end

function gameOver ()

end 

local background = display.newImageRect(sceneGroup, "images/gamescreen/background.png", 1600, 1200)
background.x = _CX
background.y = _CY 

local cirlce = display.newImageRect(sceneGroup, "images/gamescreen/circle.png", 184, 179)
      cirlce.x = _CX
      cirlce.y = _CY 





end


-- "scene:show()"
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is still off screen (but is about to come on screen).
    elseif ( phase == "did" ) then
        -- Called when the scene is now on screen.
        -- Insert code here to make the scene come alive.
        -- Example: start timers, begin animation, play audio, etc.
    end
end


-- "scene:hide()"
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is on screen (but is about to go off screen).
        -- Insert code here to "pause" the scene.
        -- Example: stop timers, stop animation, stop audio, etc.
    elseif ( phase == "did" ) then
        -- Called immediately after scene goes off screen.
    end
end


-- "scene:destroy()"
function scene:destroy( event )

    local sceneGroup = self.view

    -- Called prior to the removal of scene's view ("sceneGroup").
    -- Insert code here to clean up the scene.
    -- Example: remove display objects, save state, etc.
end


-- -------------------------------------------------------------------------------

-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

-- -------------------------------------------------------------------------------

return scene
2

There are 2 answers

0
Kumar KS On

Just try this ,

 local cirlce = display.newImageRect(sceneGroup, "images/gamescreen/circle.png", 184, 179)
  cirlce.x = display.viewableContentWidth/2
  cirlce.y = display.viewableContentHeight/2 
0
W001W On

Give This a try.

local cirlce = display.newImageRect("images/gamescreen/circle.png", 184, 179)
  cirlce.x = centerX
  cirlce.y = centerY