Could someone help me code something? Because I have already looked at links and like I usually say, I need help from an actual person.
EDIT: Don’t need help anymore.
Could someone help me code something? Because I have already looked at links and like I usually say, I need help from an actual person.
EDIT: Don’t need help anymore.
Can you post a video or something showing the effect you want to emulate? I ask because I saw a similarly worded question here and figured this must be a new game I’m missing out on or something:
Or if this is emulating a game you saw can you give the name? I can look it up and see what you’re looking for.
If you’re not getting this idea from something you saw, that does leave many options, but maybe my theory is right. That is, I tell people frequently,
“If you think you’ve got a good game idea, odds are someone, somewhere, is having the same idea right now. So, you better act on it.”
Maybe this is actual proof of my theory?
Well, no. It’s not a trend or anything. I was just curios about how I would do that. So here is what I am saying. I’m saying I want, for example, “arrows” To fall from not only the top, but also bottom, left, right, the corners as well, but not literally from the corners and stuff. I mean they spawn in those types of areas, but everywhere. So they spawn off screen and at a certain speed they come towards the center of the screen, but keep in mind the “arrow” need to be point first. Just think of Radial Gravity. But different. But once one of the “arrows” touch the center object the scene changes.
Hi Josh
Here’s a bit of code to get you started.
First off you need the arrows to point toward the center of the screen, there’s a basic formula for this which we will use later.
local function angleBetween( srcX, srcY, dstX, dstY ) local angle = ( math.deg( math.atan2( dstY-srcY, dstX-srcX ) )+90 ) return angle % 360 end
Because you are going to have lots of arrows, create a table of arrows…
local arrow = {} local arrowCount = 1
Set up some screen variables…
local \_H=display.contentHeight local \_W=display.contentWidth
Create a function to spawn the arrows in random places around the screen…
local myTransition = {} local transCount = 1 local spawnArrows = function() arrow[arrowCount] = display.newImageRect("arrow.png", 100, 100) mainGroup:insert(arrow[arrowCount]) local startPos = math.random(1,4) if startPos == 1 then arrow[arrowCount].x = math.random(\_W) arrow[arrowCount].y = -200 end if startPos == 2 then arrow[arrowCount].x = \_W+200 arrow[arrowCount].y = math.random(\_H) end if startPos == 3 then arrow[arrowCount].x = math.random(\_W) arrow[arrowCount].y = \_H+200 end if startPos == 4 then arrow[arrowCount].x = -200 arrow[arrowCount].y = math.random(\_H) end local arrowRotation = angleBetween( arrow[arrowCount].x, arrow[arrowCount].y, \_W\*0.5, \_H\*0.5 ) arrow[arrowCount].rotation = arrowRotation myTransition[transCount] = transition.to( arrow[arrowCount], {x = \_W\*0.5, y=\_H\*0.5, time=2000} ) transCount = transCount + 1 arrowCount = arrowCount + 1 end
The above bit of code starts the arrow in a random position off screen either top, right, bottom or left.
Then it rotates the arrow toward the center of the screen by calling the angleBetween function then applying the math to rotate the arrow. Then it moves (transitions) the arrow to the center in 2 seconds.
All you need to do then is spawn arrows using a random timer.
local myTimer = {} local timerCount = 1 myTimer[timerCount] = timer.performWithDelay(math.random(2000),spawnArrows,-1) timerCount = timerCount + 1
By the way, you will need to make your arrow graphic pointing up for the rotation to point it in the right direction.
I haven’t tested this code, I just typed it here off the top of my head so excuse any mistakes but you get the idea now of how to do what you want.
Can you post a video or something showing the effect you want to emulate? I ask because I saw a similarly worded question here and figured this must be a new game I’m missing out on or something:
Or if this is emulating a game you saw can you give the name? I can look it up and see what you’re looking for.
If you’re not getting this idea from something you saw, that does leave many options, but maybe my theory is right. That is, I tell people frequently,
“If you think you’ve got a good game idea, odds are someone, somewhere, is having the same idea right now. So, you better act on it.”
Maybe this is actual proof of my theory?
Well, no. It’s not a trend or anything. I was just curios about how I would do that. So here is what I am saying. I’m saying I want, for example, “arrows” To fall from not only the top, but also bottom, left, right, the corners as well, but not literally from the corners and stuff. I mean they spawn in those types of areas, but everywhere. So they spawn off screen and at a certain speed they come towards the center of the screen, but keep in mind the “arrow” need to be point first. Just think of Radial Gravity. But different. But once one of the “arrows” touch the center object the scene changes.
Hi Josh
Here’s a bit of code to get you started.
First off you need the arrows to point toward the center of the screen, there’s a basic formula for this which we will use later.
local function angleBetween( srcX, srcY, dstX, dstY ) local angle = ( math.deg( math.atan2( dstY-srcY, dstX-srcX ) )+90 ) return angle % 360 end
Because you are going to have lots of arrows, create a table of arrows…
local arrow = {} local arrowCount = 1
Set up some screen variables…
local \_H=display.contentHeight local \_W=display.contentWidth
Create a function to spawn the arrows in random places around the screen…
local myTransition = {} local transCount = 1 local spawnArrows = function() arrow[arrowCount] = display.newImageRect("arrow.png", 100, 100) mainGroup:insert(arrow[arrowCount]) local startPos = math.random(1,4) if startPos == 1 then arrow[arrowCount].x = math.random(\_W) arrow[arrowCount].y = -200 end if startPos == 2 then arrow[arrowCount].x = \_W+200 arrow[arrowCount].y = math.random(\_H) end if startPos == 3 then arrow[arrowCount].x = math.random(\_W) arrow[arrowCount].y = \_H+200 end if startPos == 4 then arrow[arrowCount].x = -200 arrow[arrowCount].y = math.random(\_H) end local arrowRotation = angleBetween( arrow[arrowCount].x, arrow[arrowCount].y, \_W\*0.5, \_H\*0.5 ) arrow[arrowCount].rotation = arrowRotation myTransition[transCount] = transition.to( arrow[arrowCount], {x = \_W\*0.5, y=\_H\*0.5, time=2000} ) transCount = transCount + 1 arrowCount = arrowCount + 1 end
The above bit of code starts the arrow in a random position off screen either top, right, bottom or left.
Then it rotates the arrow toward the center of the screen by calling the angleBetween function then applying the math to rotate the arrow. Then it moves (transitions) the arrow to the center in 2 seconds.
All you need to do then is spawn arrows using a random timer.
local myTimer = {} local timerCount = 1 myTimer[timerCount] = timer.performWithDelay(math.random(2000),spawnArrows,-1) timerCount = timerCount + 1
By the way, you will need to make your arrow graphic pointing up for the rotation to point it in the right direction.
I haven’t tested this code, I just typed it here off the top of my head so excuse any mistakes but you get the idea now of how to do what you want.