Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------
- --
- -- main.lua
- --
- -----------------------------------------------------------------------------------------
- -- Your code here
- -- constants.
- local fullw = display.contentWidth -- variable for the highest X value of the screen
- local fullh = display.contentHeight -- variable for the highest Y value of the screen
- local centerX = display.contentCenterX -- variable for the center X value of the device you are coding for. changes device to device.
- local centerY = display.contentCenterY -- variable for the center Y value of the device you are coding for. changes device to device.
- -------------------------------------------------------------------------------------------------------------------------------------------
- local defaultField = native.newTextField(centerX, centerY + 230, 150,30) -- draws a text field on the screen. centerX being the X coordinate and centery being the Y coordinate. The other two numbers are the width and height of the field.
- defaultField.placeholder = "Enter your speed from 0,100"
- defaultField.size = 11
- -- local widget = require( "widget" )
- local speedText = display.newText("Speed = ", centerX-20, centerY+222,50 , 50 ,nil, 12) -- draws the text for which the speed will be shown. will update when another number is put into the textfield.
- -- local function handleButtonEvent(event)
- -- Checks field content
- -- if defaultField.text == "" then
- -- Check for content
- -- print ("Text Field Is Empty")
- -- local alert = native.showAlert ("Alert", "Please input your wanted speed (0,100) into the text box")
- -- elseif tonumber(defaultField.text) then
- -- print ("All Good")
- -- local alert = native.showAlert("", "")
- -- elseif tonumber(defaultField.text) == nil then
- -- defaultField.text = ""
- -- local alert = native.showAlert ("Error", "Speed needs to be a number, not text.")
- -- end
- -- end
- -- local buttonTable = {
- -- table with all the button ids(not including the stop button)
- -- it gives the button ids values for X,Y, rotation
- -- {"#CF",centerX,centerY-100},
- -- {"#CRF",centerX+95,centerY-100,},
- -- {"#CHR",centerX+95,centerY},
- -- {"#CRB",centerX+95,centerY+100},
- -- {"#CB",centerX,centerY+100},
- -- {"#CLB",centerX-95,centerY+100},
- -- {"#CHL",centerX-95,centerY},
- -- {"#CLF",centerX-95,centerY-100},
- -- }
- local drawSpeedButton = display.newText("Set speed",centerX,centerY + 260)
- local function buttonListener(event) -- this function listens for the button id for when a button ID is pressed. it will then send a command to the console to print "event.target.id"
- local id = event.target.id -- sets a variable for the event.target.id to "id"
- if id == "#CF" then -- if button "#CF" is pressed, print out "#CF" into the console. Happens for all the buttons below.
- print(id)
- elseif id == "#CRF" then
- print(id)
- elseif id == "#CHR" then
- print(id)
- elseif id == "#CRB" then
- print(id)
- elseif id == "#CB" then
- print(id)
- elseif id == "#CLB" then
- print(id)
- elseif id == "#CHL" then
- print(id)
- elseif id == "#CLF" then
- print(id)
- elseif id == "#CS" then
- print(id)
- end
- end
- local function drawButton(xValue,yValue,buttonID,buttonRot)-- function for displaying the arrows, calls for an xvalue, yvalue, button id(declared above), and the rotation of the button.
- local button = display.newImage("images/arrow.png", xValue, yValue) -- draws the arrow, using the values declared from the values of the function
- button:scale(0.35,0.35)-- scales the button down to 35% of original size.
- button.id = buttonID -- the id of the button, used by the event listener gets put into the variable.
- button:addEventListener("touch",buttonListener)--adds an event to make it so you can click on the button and it
- button.rotation = buttonRot -- sets the rotation of the arrow to the value declared with the function calls below.
- print(buttonRot)-- prints the rotation of the button
- end
- local function drawStopButton(xValue,yValue,buttonID)
- local stopButton = display.newImage("images/stop.png", centerX,centerY)
- stopButton:scale( 0.5, 0.5)
- stopButton.id = buttonID
- stopButton:addEventListener("touch",buttonListener)
- end
- -- local button1 = widget.newButton(
- -- {
- -- defaultFile = "Images/Button.png",
- -- overFile = "Images/ButtonPressed.png",
- -- label = "button",
- -- onEvent = handleButtonEvent
- -- }
- -- )
- drawButton(centerX,centerY-100,"#CF",nil) -- need all these for the different buttons, havent made a for loop for it yet.
- drawButton(centerX+95,centerY-100,"#CRF",45)
- drawButton(centerX+95,centerY,"#CHR",90)
- drawButton(centerX+95,centerY+100,"#CRB",135)
- drawButton(centerX,centerY+100,"#CB",180)
- drawButton(centerX-95,centerY+100,"#CLB",225)
- drawButton(centerX-95,centerY,"#CHL",270)
- drawButton(centerX-95,centerY-100,"#CLF",315)
- drawStopButton(centerX,centerY,"#CS",nil) -- need a seperate function for the stop button for convience
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement