[SOLVED] Distance (in X) for incrementing score

Hi, I’m using Ice to add my score, and what I want to do is make it so the farther I get in the +X direction the higher the score gets. What I have in mind is making a function that creates objects a set distance apart, and when my character collides with them, it would increment the score. What I need to know is how to add these objects without making each individually, so (I think) a function would be perfect. Thanks in advance!

[import]uid: 66329 topic_id: 25761 reply_id: 325761[/import]

Is this a side scrolling game where the character moves continuously or does the player control the X movement with a dpad or the like? [import]uid: 52491 topic_id: 25761 reply_id: 104167[/import]

there are many ways to dynamically spawn and manipulate objects.
I usually have a table that holds all objects that I create in a function:

local objectsTable = {}  
  
function spawnObject()  
 local ball = display.newCircle( 100, 100, 10)  
 objectsTable[#objectsTable + 1] = ball   
 -- #objectsTable -\> number of objects in table   
end  
  
-- spawn 10 objects, 1 per second  
timer.performWithDelay( 1000, spawnObject, 10 )  

now you can iterate through the table and manipulate parameters of each object

function enterFrameFunction ()  
 for i,val in pairs(objectsTable) do   
 val.x = val.x - 1  
 val.alpha = val.alpha - 1  
 val.xScale = val.xScale + 0.1  
 -- etc...  
 end  
end  
Runtime:addEventListener( "enterFrame", enterFrameFunction )  

hope I understood your question right :wink:

-finefin [import]uid: 70635 topic_id: 25761 reply_id: 104211[/import]

That’s exactly what I was looking for finefin (not canupa?)! I made a few slight mods to it and works perfectly.

[code]
local distScoreSensorsTable = {}

function spawnDistScoreSensors()
distScoreSensors = display.newRect(700, 0, 20, 12000)
physics.addBody( distScoreSensors, { density = 1.0, friction = 0.3, bounce = 0.2, isSensor = true} )
distScoreSensors.bodyType = “static”
distScoreSensors.type = “distSensor”
distScoreSensorsTable[#distScoreSensorsTable + 1] = distScoreSensors
localGroup:insert(distScoreSensors)

for i,val in pairs(distScoreSensorsTable) do

val.alpha = 1
val.x = val.x + 250

end
end

timer.performWithDelay( 0, spawnDistScoreSensors, 50)

[import]uid: 66329 topic_id: 25761 reply_id: 104530[/import]

glad I could help :slight_smile:

as for the finefin/canupa confusion:
Hi! I’m finefin, working with and under the name canupa, which is a conglomerate of freelance designers, programmers and artists from Berlin. [import]uid: 70635 topic_id: 25761 reply_id: 104667[/import]

Ah, Ok. Thanks again finefin! [import]uid: 66329 topic_id: 25761 reply_id: 104712[/import]