Let him move

I have in lua

1
2
3
4
5
6
7
8
9
10
11
12
13
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

Are you using a Runtime listener to call przesuwaj?

Yes it's look like:
Runtime:addEventListener("enterFrame",przesuwaj)

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 :)

You're talking about this:

1
2
3
4
5
6
7
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

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 :)

platform is 'schodek', 'tlo' is backgroud
http://www.youtube.com/watch?v=Vv9sd7g9mT4
I just want to move a platform.

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;

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

I expect it may only be getting called once but a print will confirm.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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)
views:1713 update:2012/2/7 8:40:54
corona forums © 2003-2011