【问题标题】:Displaying Image in Corona sdk在 Corona sdk 中显示图像
【发布时间】:2015-09-02 19:14:43
【问题描述】:

我一直在使用 Corona SDK 制作游戏。我正在尝试在屏幕中间显示图像,但它显示在随机位置。我要显示的图像是 circle.png。如果可以,请你帮助我。

代码如下:

本地作曲家 = 要求(“作曲家”)

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

【问题讨论】:

  • 定位取决于您在 config.lua 中设置的目标大小以及 _CX 和 _CY 值。您可能还希望在 Create 方法之外使用您的函数。当您重新加载已经加载的场景时,它只运行 create 方法。此场景中的函数保留在内存中,因此没有必要加载两次(除非您根据传递到场景中的某些参数更改它们)

标签: image lua coronasdk


【解决方案1】:

试试这个,

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

【讨论】:

    【解决方案2】:

    试试这个。

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

    【讨论】:

      猜你喜欢
      • 2016-02-12
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多