I think there is a bug in v3.4 cocos2d-x when simulators height (in pixels) is bigger than monitors resolutions height when using lua and simulator on windows

Hello I am new to cocos2dx, and I am trying to figure out the system, when I noticed a strange behaviour with button clicks when I set the simulators size to use android 1080x1920 resolution and 100% size. The button click hit box areas are way off from where it renders the texts for a button. Here is my code from mainscene.lua. I created new project and then just modified the mainscene.lua. I am using Cocos Code Ide 1.2.0 on windows 7 64 bit.

Also if I set it to portrait mode, and 100% zoom out, the check boxes for button clicks are completely off. But if I change the zoom out to any other %, it works just fine.

local MainScene = class("MainScene", cc.load("mvc").ViewBase)
local ccui
local buttons = {}
local buttonOrder = {
    [1] = "firstButton",
    [2] = "secondButton",
    [3] = "thirdButton",
    [4] = "fourthButton",
    [5] = "fifthButton",
    [6] = "sixthButton",

}
local text
local touchEventValue = {
    began = 0,
    moved = 1,
    ended = 2,
    cancelled = 3
}

local function touchEvent( sender, event )
    print( sender:getTitleText(), event )
    text:setString( sender:getTitleText() )
    if event == touchEventValue.began then
        print( "Event began")    
    elseif event == touchEventValue.moved then
        print( "Event moved")    
    elseif event == touchEventValue.ended then
        print( "Event ended")    
    elseif event == touchEventValue.cancelled then
        print( "Event cancelled")    
    end   
end

local function createButton( text, scene )
    local button = ccui.Button:create():addTo(scene)
    button:addTouchEventListener( touchEvent )
    button:setTitleText(text)
    button:setTitleFontSize(72)
    button:setAnchorPoint(cc.p(0,0))
    return button
end

function MainScene:onCreate()
    ccui = _G.ccui

    buttons.firstButton = createButton( "First", self )
    buttons.secondButton = createButton( "Second", self )
    buttons.thirdButton = createButton( "Third", self )
    buttons.fourthButton = createButton( "Fourth", self )
    buttons.fifthButton = createButton( "Fifth!", self )    
    buttons.sixthButton = createButton( "Sixth!", self )

    text = ccui.Text:create("0", "", 32 ):addTo(self)
    text:setAnchorPoint( cc.p(0,0))
    local x,y = 5,5

    local buttonHeight = buttons.firstButton:getContentSize().height
    
    print( buttonHeight )
    for i = 1, #buttonOrder do
        buttons[buttonOrder[i]]:setPosition( cc.p(x, y) )
        y = y + buttonHeight
    end
       
end

return MainScene

Also it could be that I am just using these components compeletly wrong.

Edit: I think this is something to do when the simulators height is bigger than the resolution of the screen. Then it draws the items from bottom left corner where y axis grows from 0,0 to up, and hit boxes there y grows from top left corner going down… I could be wrong but thats the impression I got from the tests that I did.

Edit2: Changed the topic to be bit more describing

FYI,
I have the same problem on Windows when running height resolution (plus simulator windows) is larger than screen size.
No problem on Mac in this case.

  • Cocos Code IDE 1.2.0
  • Cocos2d-x 3.4

The problem exist since Cocos Code IDE 1.1.0 with Cocos2d-x 3.3

Hmm, sounds like a bug, can you open an issue here? It will help us track down the problem :slight_smile: