Hi everyone,
I’m new to Corona and Lua programming, only have been on it for a couple of weeks, so been following the guides and sample codes to learn what i can, as well as testing out code using the simulator. Prior knowledge are just algorithms in university which is well over 10 years ago! so lots of knowledge forgotten.
So currently, I’m working on programming the mechanics of an art-math puzzle app and one of it which I have very little ideas and knowledge to start with, and I can’t find a guide or doc for it (or I don’t know the right search strings I need to make it appear!). I’m also looking at https://coronalabs.com/blog/2016/04/28/corona-calculator-a-sample-utility-app-built-with-corona-sdk/ for ideas.
I’m having difficulty finding words to describe this mechanic but this is the best I can think of currently:
The idea of this mechanic is to allow the user to form equations by choosing numbers and math operators by moving his finger from one number to another, and operators in between, without the finger leaving the screen(either event.phase == began or moved, i’m not certain at this point). These numbers will be contained within different shapes(squares at the moment). Or as said above, using tapping to select the numbers and outputting them to a display, similar to the calculator app but it shows the whole operation on a single line, including the operators.
when event.phase == ended, i.e. fingers off, the app takes the numbers and operators and performs a calculation. It then takes the result, and passes it into another function which spawns rectangles using this result as it’s width (other values are already pre-determined in the function)
I’ve tried tap instead of touch but I don’t know how to “save” the different event.target.number from tapping multiple numbers, since with each tap, event.target changes.
The relevant code I have as of now are functions to generate numbers and rectangles when I call them, and the basic touch code for objects which doesn’t seem to work for me either as I tried to start by calling back the numbers upon touching them.
code:
local createNum1, x1, x2, x3, x4, Numgrp1, Numgrp2 x1 = 5; x2 = 8; x3 = 4; x4 = 2 Numgrp1 = display.newGroup() Numgrp1.x = 345 ; Numgrp1.y = 325 Numgrp1.anchorChildren = true createNum1 = function (numdisp, numX, numY) Number\_stored = display.newText(numdisp, numX, numY, "Arial", 20) Number\_stored.number = numdisp Number\_stored.x = numX Number\_stored.y = numY Number\_stored.anchorX = 0.5 Number\_stored.anchorY = 0.5 Numgrp1:insert(Number\_stored) return true end createNum1(x1, 320, 300) createNum1(x2, 370, 300) createNum1(x3, 370, 350) createNum1(x4, 320, 350) function Numgrp1[1]:touch( event ) if ( event.phase == "began" ) then print( "Touch event began on: " .. self.number ) -- set touch focus display.getCurrentStage():setFocus( self ) self.isFocus = true elseif ( self.isFocus ) then if ( event.phase == "moved" ) then print( "Moved phase of touch event detected." ) elseif ( event.phase == "ended" or event.phase == "cancelled" ) then -- reset touch focus display.getCurrentStage():setFocus( nil ) self.isFocus = nil end end return true end Numgrp1[1]:addEventListener( "touch", Numgrp1[1] )
All advice, guidance and opinions gladly welcome!