With TNT virtual pad, the pads/buttons are drawn relative to logical screen positions. Although this works well for game objects, it doesn't for user interface objects: they could be clipped partially off screen.
Here is a fix for two sections of code with the VirtualPad source (it's only good for those who have made donations). I've tested it for V and H orientations with all the various clip/scaling rendering methods.
First replace "CTNTVirtualPad:updateDeviceInfo()" with this:
------------------------
-- update device info --
------------------------
function CTNTVirtualPad:updateDeviceInfo()
self.screenWidth = application:getDeviceWidth()
self.screenHeight = application:getDeviceHeight()
self.screenLogicWidth = application:getLogicalWidth()
self.screenLogicHeight = application:getLogicalHeight()
self.screenContentWidth = application:getContentWidth()
self.screenContentHeight = application:getContentHeight()
self.halfScreenWidth = self.screenContentWidth / 2
-- SinisterSoft fix (pt1/2) for clipped drawing problem
self.clippedX1 = -application:getLogicalTranslateX() / application:getLogicalScaleX()
self.clippedY1 = -application:getLogicalTranslateY() / application:getLogicalScaleY()
local orientation = application:getOrientation()
if orientation == Application.PORTRAIT or orientation == Application.PORTRAIT_UPSIDE_DOWN then
self.clippedX2 = self.clippedX1+(application:getDeviceWidth()/application:getLogicalScaleX())
self.clippedY2 = self.clippedY1+(application:getDeviceHeight()/application:getLogicalScaleY())
else
self.clippedX2 = self.clippedX1+(application:getDeviceHeight()/application:getLogicalScaleX())
self.clippedY2 = self.clippedY1+(application:getDeviceWidth()/application:getLogicalScaleY())
end
end
Then replace the "buttons" section of "CTNTVirtualPad:init(parent, textureFileName, padSticks, padButtons, borderSpace, layerIndex)" with this:
-- ======= --
-- BUTTONS --
-- ======= --
-- SinisterSoft fix (pt2/2) for clipped drawing problem
if padButtons == PAD.BUTTONS_NONE then -- NO BUTTONS
self.buttonsCount = 0
elseif padButtons == PAD.BUTTONS_ONE then -- ONE BUTTON
self.buttons[1] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[1]:setPosition(self.clippedX2 - self.buttons[1].hWidthB - borderSpace, self.clippedY2 - self.buttons[1].hHeightB - borderSpace)
self.buttons[1]:setColor(255, 70, 60)
self.buttonsCount = 1
elseif padButtons == PAD.BUTTONS_TWO then -- TWO BUTTON
self.buttons[1] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[1]:setPosition(self.clippedX2 - (self.buttons[1].hWidthB * 3) - borderSpace, self.clippedY2 - self.buttons[1].hHeightB - borderSpace)
self.buttons[1]:setColor(255, 70, 60)
self.buttons[2] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[2]:setPosition(self.clippedX2 - self.buttons[2].hWidthB - borderSpace, self.clippedY2 - (self.buttons[2].hHeightB * 2) - borderSpace)
self.buttons[2]:setColor(70, 255, 120)
self.buttonsCount = 2
elseif padButtons == PAD.BUTTONS_THREE then -- THREE BUTTONS
self.buttons[1] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[1]:setPosition(self.clippedX2 - (self.buttons[1].hWidthB * 3) - borderSpace, self.clippedY2 - self.buttons[1].hHeightB - borderSpace)
self.buttons[1]:setColor(255, 70, 60)
self.buttons[2] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[2]:setPosition(self.clippedX2 - self.buttons[2].hWidthB - borderSpace, self.clippedY2 - (self.buttons[2].hHeightB * 2) - borderSpace)
self.buttons[2]:setColor(70, 255, 120)
self.buttons[3] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[3]:setPosition(self.clippedX2 - (self.buttons[3].hWidthB * 2.8) - borderSpace, self.clippedY2 - (self.buttons[3].hHeightB * 3.2) - borderSpace)
self.buttons[3]:setColor(90, 120, 255)
self.buttonsCount = 3
elseif padButtons == PAD.BUTTONS_FOUR then -- FOUR BUTTONS
self.buttons[1] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[1]:setPosition(self.clippedX2 - (self.buttons[1].hWidthB * 3) - borderSpace, self.clippedY2 - self.buttons[1].hHeightB - borderSpace)
self.buttons[1]:setColor(255, 70, 60)
self.buttons[2] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[2]:setPosition(self.clippedX2 - self.buttons[2].hWidthB - borderSpace, self.clippedY2 - (self.buttons[2].hHeightB * 2) - borderSpace)
self.buttons[2]:setColor(70, 255, 120)
self.buttons[3] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[3]:setPosition(self.clippedX2 - (self.buttons[3].hWidthB * 3) - borderSpace, self.clippedY2 - (self.buttons[3].hHeightB * 3.2) - borderSpace)
self.buttons[3]:setColor(90, 120, 255)
self.buttons[4] = CTNTVirtualButton.new(self.parent, self.skin, self.layer)
self.buttons[4]:setPosition(self.clippedX2 - (self.buttons[4].hWidthB * 5) - borderSpace, self.clippedY2 - (self.buttons[4].hHeightB * 2) - borderSpace)
self.buttons[4]:setColor(210, 210, 60)
self.buttonsCount = 4
end
-- ================ --
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
https://deluxepixel.com
Comments
thanks for your fix and support!!
will be implemented in next release.!
thanks again
Gianluca.
Likes: SinisterSoft
www.tntengine.com
https://deluxepixel.com
If you look at the screenshots on this link you will see the 5 button (with some of them recoloured and reduced thru the size and colour options)...
https://play.google.com/store/apps/details?id=com.sinistersoft.bacteria
I've put the new source in your dropbox folder.
https://deluxepixel.com
as soon as i go home from work i integrate your fixes with current Version and Release New version (1.30).
thanks again. for your help and support!.
:x
www.tntengine.com
https://deluxepixel.com
version 1.30 out!
www.tntengine.com
:EDIT:
internet connection slow... dropbox sources (for donators) are updating...
www.tntengine.com
-- v1.31 optional vertical border space also activated flipped mode if negative, else same as horizontal border space
-- v1.3 5 and 6 button combo's added by SinisterSoft
The flipped mode allows you to make a second vpad, but this time flipped at the other end of the screen - for 2 player vs games...
https://deluxepixel.com
wow! you are a coding machine!
so tomorrow new release...
(i think dropbox is very very very slow tonight)!
now i go to bed!..
look at www.tntengine.com
www.tntengine.com
I notice a couple of typos as I was doing the flip code, fixed them for you. They were things like using the width of the left pad on the right pad, etc... sorted now.
Night!
https://deluxepixel.com
self.buttons[4] = CTNTVirtualButton.new(self.parent, self.skin, self.layer, self.flipped)
if application:getOrientation()=="landscape" then
self.buttons[4]:setPosition(self.clippedX2 - self.buttons[4].hWidthB*5*self.flipped - self.borderSpace*self.flipped, self.clippedY2 - self.buttons[4].hHeightB*2*self.flipped - self.vBorderSpace)
else
self.buttons[4]:setPosition(self.clippedX2 - self.buttons[4].hWidthB*self.flipped - self.borderSpace*self.flipped, self.clippedY2 - self.buttons[4].hHeightB*4.2*self.flipped - self.vBorderSpace)
end
self.buttons[4]:setColor(210, 210, 60)
self.buttonsCount = 4
This is why I needed the patch:
http://ɯoɔ.com/images/retrostar.png
https://deluxepixel.com
thanks again.
for your support i haven't yet published new version because the are little problems with "swapped/inverted" buttons...
but this days i'm very very busy (work/family)...
hope to publish soon...
www.tntengine.com
If you put a project that goes wrong in my dropbox then I'll take a looka nd fix it.
This latest update just checks for orientation and if portrait it puts the yellow button higherup and to the right (see the pic). The colours in my pic are different to your defaults as most people use red for fire and I think that that is best being in that corner (in the actual lib they are the same as your normal colours).
https://deluxepixel.com
open example 1
change vpad init line:
-- setup Virutal Pad
local vPad = CTNTVirtualPad.new(stage, "tntskinpad", PAD.STICK_SINGLE, PAD.BUTTONS_TWO, 20,2, -20)
now run the example and click near the airplane (on the right side)
and virtual pad lock on screen! (move only up and down on y axis).
www.tntengine.com
https://deluxepixel.com
22/01/2013 v1.35
- Several Bug Fix for new Buttons system (by SinisterSoft)
- Fix a possible Crash if layerIndex is nil or < 1
+ Added screen Restrict (By Sinistersoft)
+ New Button “default”position (By Sinistersoft)
Likes: SinisterSoft
www.tntengine.com
-- v1.36 fix for replacing a texture resulted in the pressed button image being displayed
It's in your dropbox.
https://deluxepixel.com
as always soon public update!
and really a big thanks to you because with your fix and new features added to VPad is really become stable and configurable!
awesome work!
Likes: SinisterSoft
www.tntengine.com
https://deluxepixel.com