Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
TNT VirtualPad: A fix for clipped pads... — Gideros Forum

TNT VirtualPad: A fix for clipped pads...

SinisterSoftSinisterSoft Maintainer
edited January 2013 in General questions
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

  • @SinisterSoft
    thanks for your fix and support!!

    will be implemented in next release.!

    thanks again
    Gianluca.

    Likes: SinisterSoft

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
    +1 -1 (+1 / -0 )Share on Facebook
  • No problem, thanks for a great lib. :)
    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
  • SinisterSoftSinisterSoft Maintainer
    edited January 2013
    @GregBUG I've made another change. I've added support for 5 and 6 buttons. I needed 5 buttons combo for a redux of the controls in my game. The 6 button combo should allow for some types of 2 player games on landscape...

    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.
    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
  • wow! ok.

    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
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • I have another idea for a change later tonight. I'll wait for your updated version first. :)
    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
  • GregBUGGregBUG Guru
    edited January 2013
    @SinisterSoft and @all

    version 1.30 out! :)

    www.tntengine.com

    :EDIT:
    internet connection slow... dropbox sources (for donators) are updating...
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • SinisterSoftSinisterSoft Maintainer
    edited January 2013
    What changes did you make? Is it the same as the source I uploaded 'cause I've added a pretty neat feature...

    -- 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... :)
    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
  • GregBUGGregBUG Guru
    edited January 2013
    only released 1.30 (your 6 buttons and clip fix)
    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
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • I'll put my new version in the drop box then. :)

    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!
    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
  • SinisterSoftSinisterSoft Maintainer
    edited January 2013
    @GregBUG I've uploaded a new version in the Dropbox with a fix for not being much space in landspace for 4 buttons, here is a section of the patch for those that have the source:


    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

    retrostar.png
    480 x 800 - 78K
    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
  • @SinisterSoft
    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...

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • I didn't know there was still a problem with the inverted buttons, I thought I fixed that last update? example 1 and 2 look ok to me...

    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). :)
    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
  • GregBUGGregBUG Guru
    edited January 2013
    try this:

    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).
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • Nice find, easy fix... check your dropbox. :)
    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
  • TNT Virtual PAD 1.35 OUT! ;)

    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)

    :D

    Likes: SinisterSoft

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited January 2013
    @GregBUG Found a bug if you change the default textures, fixed...

    -- v1.36 fix for replacing a texture resulted in the pressed button image being displayed

    It's in your dropbox.

    :)
    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
  • @SinisterSoft

    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

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
    +1 -1 (+1 / -0 )Share on Facebook
  • No problem, glad to have helped. :)
    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
Sign In or Register to comment.