How to do dropdown scores?

Well you may not understand my question so I made a gif to show what I want to do:

b388e40a-7735-11e8-9742-1d6c9ec0f482.gif

Self explanatory…anyways:

I made something like this but I have to hardcode the position of the dropdown text.

But in reality the player may trigger multiple dropdown texts and they may overlap each other.

I need help doing this.

To save you guys time i made a sample project below:

Its plug and play!

local cash = 0 local cashboard = display.newRect(0,0,124,88) cashboard:setFillColor(1,1,0) cashboard.x=display.contentCenterX cashboard.y=display.contentCenterY+100 local cashboardtext = display.newText(cash,cashboard.x,cashboard.y,native.systemFont) cashboardtext:setFillColor(0,1,0) local add = display.newRect(0,0,124,88) add:setFillColor(1,0,0) add.x=display.contentCenterX-98 add.y=display.contentCenterY local addtext = display.newText("Add random amount",add.x+30,add.y,native.systemFont) local subtract = display.newRect(0,0,124,88) subtract:setFillColor(1,0,0) subtract.x=display.contentCenterX-98 subtract.y=display.contentCenterX-30 local subtracttext = display.newText("Subtract random amount",subtract.x+30,subtract.y,native.systemFont) local function subtract\_function() cash=cash-math.random(1,1000) cashboardtext.text=cash end local function add\_function() cash=cash+math.random(1,1000) cashboardtext.text=cash end add:addEventListener("tap",add\_function) subtract:addEventListener("tap",subtract\_function)

Can someone help!

Well bad math for the gif…

2400 is supposed to be 3400.

my bad.

This isn’t something we can show you in a few lines of code w/o actually coding the entire thing.

The key here is to:

  • Place new ‘drop down’ scores relative either to the primary score box or the last still active ‘drop down’ score.
  • One easy way to do this is to make a score module that draws the primary score.
  • Then, in the score module keep a table of ‘drop down’ scores.  When the table is empty place the next ‘drop down’ score below  the primary box and add the temporary drop down score to the end of the table/list.
  • When a ‘drop down’ element expires, remove it from the list and destroy it.
  • When drawing a ‘drop down’ score and the list length is non-zero, just draw the new ‘drop down’ score below the one at the end of the list, again adding the new one to the list.

Easy Peasy

Note: I know the answer will probably be, “No,”, but I’d be happy to code up a robust and moddable module that does this for a level-1 hit.  :) 

@romainggamer

Thanks! I got the text to dropdown but I cant get it to dissapear.

I want the text to transition up and dissapear.

Here is the code I got:

local cash = 0 local cashboard = display.newRect(0,0,124,88) cashboard:setFillColor(1,1,0) cashboard.x=display.contentCenterX cashboard.y=display.contentCenterY+100 local cashboardtext = display.newText(cash,cashboard.x,cashboard.y,native.systemFont) cashboardtext:setFillColor(0,1,0) local dropdownGroup=display.newGroup() dropdownGroup:insert(cashboardtext) local add = display.newRect(0,0,124,88) add:setFillColor(1,0,0) add.x=display.contentCenterX-98 add.y=display.contentCenterY local addtext = display.newText("Add random amount",add.x+30,add.y,native.systemFont) local subtract = display.newRect(0,0,124,88) subtract:setFillColor(1,0,0) subtract.x=display.contentCenterX-98 subtract.y=display.contentCenterX-30 local subtracttext = display.newText("Subtract random amount",subtract.x+30,subtract.y,native.systemFont) local amount= math.random(1,1000) local function subtract\_function() amount= math.random(1,1000) cash=cash-amount cashboardtext.text=cash display.newText( dropdownGroup,"-"..amount, cashboard.x, dropdownGroup[dropdownGroup.numChildren].y+10, native.systemFont, 16 ) end local function add\_function() amount= math.random(1,1000) cash=cash+amount cashboardtext.text=cash display.newText( dropdownGroup,"+"..amount, cashboard.x,dropdownGroup[dropdownGroup.numChildren].y+10, native.systemFont, 16 ) end add:addEventListener("tap",add\_function) subtract:addEventListener("tap",subtract\_function)

Any ideas?

I’d use a transition or transitions with a delay:

transition.to( obj, { y = targetY, delay = timeToWait, time = timeToTake, onComplete = function( self ) -- clean up code here end )

Ah thanks!

I used transition.fadeOut instead of .to

Think we have another bot, albeit a more sophisticated one as the post on the social media logos thread was at least relevant. The above is nonsense as it’s about Excel instead of Corona, but you can see the word dropdown has triggered it.

Well bad math for the gif…

2400 is supposed to be 3400.

my bad.

This isn’t something we can show you in a few lines of code w/o actually coding the entire thing.

The key here is to:

  • Place new ‘drop down’ scores relative either to the primary score box or the last still active ‘drop down’ score.
  • One easy way to do this is to make a score module that draws the primary score.
  • Then, in the score module keep a table of ‘drop down’ scores.  When the table is empty place the next ‘drop down’ score below  the primary box and add the temporary drop down score to the end of the table/list.
  • When a ‘drop down’ element expires, remove it from the list and destroy it.
  • When drawing a ‘drop down’ score and the list length is non-zero, just draw the new ‘drop down’ score below the one at the end of the list, again adding the new one to the list.

Easy Peasy

Note: I know the answer will probably be, “No,”, but I’d be happy to code up a robust and moddable module that does this for a level-1 hit.  :) 

@romainggamer

Thanks! I got the text to dropdown but I cant get it to dissapear.

I want the text to transition up and dissapear.

Here is the code I got:

local cash = 0 local cashboard = display.newRect(0,0,124,88) cashboard:setFillColor(1,1,0) cashboard.x=display.contentCenterX cashboard.y=display.contentCenterY+100 local cashboardtext = display.newText(cash,cashboard.x,cashboard.y,native.systemFont) cashboardtext:setFillColor(0,1,0) local dropdownGroup=display.newGroup() dropdownGroup:insert(cashboardtext) local add = display.newRect(0,0,124,88) add:setFillColor(1,0,0) add.x=display.contentCenterX-98 add.y=display.contentCenterY local addtext = display.newText("Add random amount",add.x+30,add.y,native.systemFont) local subtract = display.newRect(0,0,124,88) subtract:setFillColor(1,0,0) subtract.x=display.contentCenterX-98 subtract.y=display.contentCenterX-30 local subtracttext = display.newText("Subtract random amount",subtract.x+30,subtract.y,native.systemFont) local amount= math.random(1,1000) local function subtract\_function() amount= math.random(1,1000) cash=cash-amount cashboardtext.text=cash display.newText( dropdownGroup,"-"..amount, cashboard.x, dropdownGroup[dropdownGroup.numChildren].y+10, native.systemFont, 16 ) end local function add\_function() amount= math.random(1,1000) cash=cash+amount cashboardtext.text=cash display.newText( dropdownGroup,"+"..amount, cashboard.x,dropdownGroup[dropdownGroup.numChildren].y+10, native.systemFont, 16 ) end add:addEventListener("tap",add\_function) subtract:addEventListener("tap",subtract\_function)

Any ideas?

I’d use a transition or transitions with a delay:

transition.to( obj, { y = targetY, delay = timeToWait, time = timeToTake, onComplete = function( self ) -- clean up code here end )

Ah thanks!

I used transition.fadeOut instead of .to

Think we have another bot, albeit a more sophisticated one as the post on the social media logos thread was at least relevant. The above is nonsense as it’s about Excel instead of Corona, but you can see the word dropdown has triggered it.