Let him move

I have in lua
[lua]local function poziom()
for i = 1, kLevelCols do
for j = 1, kLevelRows do
if tab[i][j] == 1 then
schodek[i][j] = display.newImage(“schodek.png”)
physics.addBody(schodek[i][j], “static”, {bounce = 0.3, friction = 10})
schodek[i][j].y = (_W/12) * i
schodek[i][j].x = 75 * j
end
end
end

end[/lua]
This function print obstacles in my game.
How i can move this object?
I try:
[lua]local tPrevious = system.getTimer()
local function przesuwaj(event)
–animacja tla
local tDelta = event.time - tPrevious
tPrevious = event.time
local xOffset = ( 0.2 * tDelta )
tlo.x = tlo.x - xOffset
tlo2.x = tlo2.x - xOffset
for i = 1, kLevelCols do
for j = 1, kLevelRows do
if tab[i][j] == 1 then
schodek[i][j].x = schodek[i][j].x + xOffset
end
end
end
if (tlo.x + tlo.contentWidth) < 0 then
tlo:translate( 959 * 2, 0)
end
if (tlo2.x + tlo2.contentWidth) < 0 then
tlo2:translate( 959 * 2, 0)
end

end[/lua]
It’s move only one time.
I tried to do it using while, but still not working
Thanks for answers, and sorry for language. [import]uid: 117910 topic_id: 21266 reply_id: 321266[/import]

Are you using a Runtime listener to call przesuwaj? [import]uid: 52491 topic_id: 21266 reply_id: 84381[/import]

Yes it’s look like:
[lua]Runtime:addEventListener(“enterFrame”,przesuwaj)[/lua] [import]uid: 117910 topic_id: 21266 reply_id: 84387[/import]

Hrm, you may wish to view the samplecode located in;

CoronaSDK > SampleCode > Sprites > JungleScene

There you can observe the different objects moving - they are set to different speeds but that is easily adjustable.

Peach :slight_smile: [import]uid: 52491 topic_id: 21266 reply_id: 84398[/import]

You’re talking about this:
[lua]local i
for i = 1, #tree, 1 do
tree[i].x = tree[i].x - tree[i].dx * tDelta * 0.2
if (tree[i].x + tree[i].contentWidth) < 0 then
tree[i]:translate( 480 + tree[i].contentWidth * 2, 0 )
end
end[/lua]
In my source it’s look like
[lua]for i = 1, kLevelCols, 1 do
for j = 1, kLevelRows, 1 do
if tab[i][j] == 1 then
schodek[i][j].x = schodek[i][j].x - poziom1
end
end
end[/lua]
My ‘schodek’ move only one time about ‘poziom1’
[import]uid: 117910 topic_id: 21266 reply_id: 84437[/import]

Can you upload a sample somewhere? It’s kind of hard for me to follow this because I can’t picture your scene setup and it is made a tad trickier by the language differences.

If you could upload anything or provide plug and play I’d be happy to run it and see if I can advise you from there.

Peach :slight_smile: [import]uid: 52491 topic_id: 21266 reply_id: 84489[/import]

platform is ‘schodek’, ‘tlo’ is backgroud
http://www.youtube.com/watch?v=Vv9sd7g9mT4
I just want to move a platform. [import]uid: 117910 topic_id: 21266 reply_id: 84497[/import]

I still can’t do much with this without plug and play/sample but would suggest you try a print statement immediately before this line in your code;

[lua]schodek[i][j].x = schodek[i][j].x + xOffset[/lua]

I expect it may only be getting called once but a print will confirm. [import]uid: 52491 topic_id: 21266 reply_id: 84595[/import]

[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0, 9.8)
–usuni?cie paska statusu
display.setStatusBar(display.HiddenStatusBar)
–poziom
local kLevelRows = 7
local kLevelCols = 9
schodek = {}
schodek[1] = {}
schodek[2] = {}
schodek[3] = {}
schodek[4] = {}
schodek[5] = {}
schodek[6] = {}
schodek[7] = {}
schodek[8] = {}
schodek[9] = {}
tab = {}
tab[1] = {0,1,0,0,1,0,0}
tab[2] = {0,0,0,0,0,0,0}
tab[3] = {0,0,0,0,0,0,0}
tab[4] = {0,0,0,1,0,0,0}
tab[5] = {1,0,0,0,0,0,0}
tab[6] = {0,0,0,0,1,0,0}
tab[7] = {0,0,0,0,0,0,0}
tab[8] = {0,0,0,0,0,0,0}
tab[9] = {0,0,0,0,0,0,0}
–poziomy trudno?ci
poziom1 = 1
poziom2 = 5
poziom3 = 10
– obramowanie ekranu
–local leftWall = display.newRect(0, 0, 1, display.contentHeight)
–local rightWall = display.newRect(display.contentWidth, 0, 1, display.contentHeight)
local ceiling = display.newRect(0, 0, display.contentWidth, 1)
–dodanie boy dla obramowania
–physics.addBody(leftWall, “static”, {bounce = 0.1})
–physics.addBody(rightWall, “static”, {bounce = 0.1})
physics.addBody(ceiling, “static”, {bounce = 0.1})
–tlo
local tlo = display.newImage(“tlo.png”)
local tlo2 = display.newImage(“tlo.png”)
tlo:setReferencePoint( display.CenterLeftReferencePoint )
tlo2:setReferencePoint( display.CenterLeftReferencePoint )
–pilka
local pilka = display.newImage(“pilka.png”)
pilka.x = 100
pilka.y = 150
physics.addBody(pilka, {bounce = 0.5, radius = 17})
–rysowanie poziomu
local function poziom()
for i = 1, kLevelCols do
for j = 1, kLevelRows do
if tab[i][j] == 1 then
schodek[i][j] = display.newImage(“schodek.png”)
physics.addBody(schodek[i][j], “static”, {bounce = 0.3, friction = 10})
schodek[i][j].y = (_W/12) * i
schodek[i][j].x = 75 * j
end
end
end

end

Runtime:addEventListener( “enterFrame”, poziom )
function movePilka(event)
local pilka = event.target
pilka:applyLinearImpulse(0, -0.2, pilka.x, pilka.y)
end
pilka:addEventListener(“touch”, movePilka)
local tPrevious = system.getTimer()
–ruch elementów
tlo.x = 0
tlo2.x = 959
local tPrevious = system.getTimer()
local function przesuwaj(event)
–animacja tla
for i = 1, kLevelCols, 1 do
for j = 1, kLevelRows, 1 do
if tab[i][j] == 1 then
schodek[i][j].x = schodek[i][j].x - 10
end
end
end
local tDelta = event.time - tPrevious
tPrevious = event.time
local xOffset = ( 0.2 * tDelta )
tlo.x = tlo.x - xOffset
tlo2.x = tlo2.x - xOffset
if (tlo.x + tlo.contentWidth) < 0 then
tlo:translate( 959 * 2, 0)
end
if (tlo2.x + tlo2.contentWidth) < 0 then
tlo2:translate( 959 * 2, 0)
end
end
Runtime:addEventListener(“enterFrame”,przesuwaj)[/lua]
function poziom responsible for drawing platforms function przesuwaj is my animation [import]uid: 117910 topic_id: 21266 reply_id: 84618[/import]

even
schodek[1][1].x = schodek[1][1].x - 50
move only one time my platform [import]uid: 117910 topic_id: 21266 reply_id: 85232[/import]

Print after lines 79, 80, 81 - see what prints continuously and what only prints once - the one that prints once will indicate the above line is the issue. [import]uid: 52491 topic_id: 21266 reply_id: 85281[/import]

[lua]for i = 1, kLevelCols do
(1)schodek[i][4].x = schodek[i][4].x - 100
for j = 1, kLevelRows do
(2) --schodek[i][j].x = schodek[i][j].x - 100
if tab[i][j] == 1 then
(3)-- schodek[i][j].x = schodek[i][j].x - 100
end
end
end[/lua]

  1. Move only one time but background don’t moving
  2. Nothing happens
  3. Moving once background moving too :frowning: [import]uid: 117910 topic_id: 21266 reply_id: 85298[/import]

[lua]for i = 1, kLevelCols do
print “kLevelCols”
schodek[i][4].x = schodek[i][4].x - 100
for j = 1, kLevelRows do
print “kLevelRows”
schodek[i][j].x = schodek[i][j].x - 100
if tab[i][j] == 1 then
print “tab”
schodek[i][j].x = schodek[i][j].x - 100
end
end
end[/lua]

So in this scenario kLevelCols prints once, then nothing else? [import]uid: 52491 topic_id: 21266 reply_id: 85453[/import]

Corona Simulation Output give me
http://imageshack.us/f/215/beztytuudjr.png/ [import]uid: 117910 topic_id: 21266 reply_id: 85488[/import]

If i statically insert value i and j the platform move only one time [import]uid: 117910 topic_id: 21266 reply_id: 85559[/import]

Then it’s;
if tab[i][j] == 1 then
that you need to focus on - if it’s only being called once (or twice, according to your log) then that’s where the issue lies.

That said, if you can upload a sample somewhere I can try to take a closer look if I have some time tonight. [import]uid: 52491 topic_id: 21266 reply_id: 85588[/import]

Source you have few post upper you want apk
http://www.sendspace.pl/file/fa7bc2a91a79a81fbd597fd
to play you must click ‘Graj’ -> ‘1’ [import]uid: 117910 topic_id: 21266 reply_id: 85602[/import]

Source meaning code+images to run it - or alter to plug and play? [import]uid: 52491 topic_id: 21266 reply_id: 85744[/import]

I back to home at sunday then i will give you source and images :slight_smile: thanks for patience [import]uid: 117910 topic_id: 21266 reply_id: 85823[/import]

No worries; I’m afraid sometimes just looking at code isn’t quite enough for me to figure out what is wrong and I admit I stumble over words I don’t know. (Although “schodek” sounds kind of cool to me.)

Will check back in then and see what I can do for you :slight_smile: [import]uid: 52491 topic_id: 21266 reply_id: 86036[/import]