Touch location not update when gameCanvas's size changes dynamically

Touch location not update when gameCanvas's size changes dynamically
0.0 0


I come to the situation to scale the whole game content to match the current resolution of the device or system playing the game. So this means to change “gameCanvas” size dynamically.
Whenever it changes, touch position is still the old one and doesn’t update with the new size of gameCanvas. This effect when you try to touch the button or anything involves with touch position, even you call “setScale()” for all objects, touch position misses the button.

Any suggestions or helps to make the touch position keeps up with the resolution changes in real time ?


We have a demo for gameCanvas’s size changes dynamically in HelloHTML5World.

you need set the director’s scale.

code like this:
@ cc.renderContext.translate(0, cc.canvas.height);
cc.renderContext.scale(xScale, xScale);


It works great ! Thanks so much !

I hope there will be none of the issues although I still use alpha version 2 framework older than the code there. It seems API changes quite reasonably.

One point here is that, for so long I thought setting a content scale factor directly to “Director” should not be done as “getContentScaleFactor()” (for iOS platform, cocos2d-x) will return 1 or 2 based on retina mode enabled or not, thus it seems the function is available only for inspection to create code to be able to work on such particular device. But after I’ve known your reply, my thought twists upside down, now instead of applying a global scale factor value to all nodes in the game, I just set one point in “Director”.