Hello,
I am trying to limit the amount of line the user can draw in my game, i have dissected samurai fruit’s code. When you draw the line in samurai fruit there is a line limit of in which you swipe 50 pixels on the screen until it plays a random sound. It looks like it works perfectly, the problem is the line limit only works when you swipe it fast across the screen. If you swipe it slowly you can have as much line as you want, if you try it out you can see the effects. What i want is 50 pixels no matter how fast or how slow you draw on the screen, but right now it’s not a set number because it depends on how you swipe it. Thanks for all your help. I’ve been working on this for a long time and just can’t figure it out. If you want to see the original its here : http://developer.anscamobile.com/code/samurai-fruit
ONCE IT HITS 50 PIXELS BALL WILL REMOVE SELF. SO YOU KNOW WHEN IT DOES.
The code for the dissected samurai fruit. Copy past into a main.lua, you dont need anything to use this code. Can anyone help me make it so it’s 50 pixels no matter the speed?
(Try it out and you will see the effects)
Thanks again!
[code]
– CODE:
require (“physics”)
local ui = require(“ui”)
physics.start()
–physics.setDrawMode ( “hybrid” ) – Uncomment in order to show in hybrid mode
physics.setGravity( 0, 9.8 * 2)
physics.start()
— THIS IS WHAT IS USED FOR THE LINE LIMIT
– Audio for slash sound (sound you hear when user swipes his/her finger across the screen)
local slashSounds = {slash1 = audio.loadSound(“slash1.wav”), slash2 = audio.loadSound(“slash2.wav”), slash3 = audio.loadSound(“slash3.wav”)}
local slashSoundEnabled = true – sound should be enabled by default on startup
local minTimeBetweenSlashesLimit = 150-- Minimum amount of time in between each slash sound
local minDistanceForSlashSoundLimit = 50-- Amount of pixels the users finger needs to travel in one frame in order to play a slash sound
local ball = display.newCircle( 0, 0, 18)
ball:setFillColor(0, 255, 0)
ball.x = display.contentHeight/7
ball.y = display.contentWidth/7
– Will contain all fruits available in the game
local avalFruit = {}
– Slash line properties (line that shows up when you move finger across the screen)
local maxPoints = 5
local lineThickness = 20
local endPoints = {}
– Whole Fruit physics properties
local minVelocityY = 850
local maxVelocityY = 1100
local minVelocityX = -200
local maxVelocityX = 200
local minAngularVelocity = 100
local maxAngularVelocity = 200
– Contains all the available splash images
local splashImgs = {}
– Timer references
local bombTimer
local fruitTimer
function main()
display.setStatusBar( display.HiddenStatusBar )
setUpBackground()
setUpCatchPlatform()
initGroups()
initFruitAndSplash()
Runtime:addEventListener(“touch”, drawSlashLine)
startGame()
end
function initGroups()
end
function setUpBackground()
end
– Populates avalFruit with all the fruit images and thier widths and heights
function initFruitAndSplash()
end
– Creates a platform at the bottom of the game “catch” the fruit and remove it
function setUpCatchPlatform()
end
– THIS IS THE FUNCTION FOR THE LINE LIMIT. THIS IS WHERE THE PROBLEM IS, I THINK ITS THE “LOCAL DISTANCE”.
– Draws the slash line that appears when the user swipes his/her finger across the screen
function drawSlashLine(event)
– Play a slash sound
if(endPoints and endPoints[1]) then
local distance = math.sqrt(math.pow(event.x - endPoints[1].x, 2) + math.pow(event.y - endPoints[1].y, 2))
if(distance > minDistanceForSlashSoundLimit and slashSoundEnabled == true) then
slashSoundEnabled = false
ball:removeSelf()
timer.performWithDelay(minTimeBetweenSlashesLimit, function(event) slashSoundEnabled = true end)
end
end
– Most of the code for the swiping
– Insert a new point into the front of the array
table.insert(endPoints, 1, {x = event.x, y = event.y, line= nil})
– Remove any excessed points
if(#endPoints > maxPoints) then
table.remove(endPoints)
end
for i,v in ipairs(endPoints) do
local line = display.newLine(v.x, v.y, event.x, event.y)
line.width = lineThickness
transition.to(line, { alpha = 0, width = 0, onComplete = function(event) line:removeSelf() end})
end
if(event.phase == “ended”) then
while(#endPoints > 0) do
table.remove(endPoints)
end
end
end
main() [import]uid: 23689 topic_id: 12916 reply_id: 312916[/import]