KINGx - Das inoffizielle PlayStation Forum & News Portal

Normale Version: Lua Animation Problem
Sie sehen gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hi,
hab seit heute angefangen ein wenig mit Lua rumzubasteln. (kaum bis gar keine programmirkenntnisse vorhanden)
Habe mir dazu dem Hintergundbild aus PSPokemon genommen
und versucht die figur darauf ein wenig laufen zu lassen bzw. ein paar aktionen durchführen zu lassen.
nu würd ich gerne eine animation beim laufen hinbekommen, nur komme ich da nicht sonderlich weiter...hier: http://www.pspking.de/forum/showthread.php?tid=35775&pid=408441#pid408441
hat neuro schon den richtigen denkanstoß gegeben, nur fnd ich nirgents ne richtige umsetzung dafür....

also: ich würde gerne aus diesem sprite:
nach tastendruck padBig Grinown() das bild ein stück nach rechts fahren lassen...also 3 mal und dann von vorne...immer in 32x32 stücken...

das gleiche natürlich auch für rechts, oben und links...müsste also auch die png auf tastendruck erneuern...nur wie?

hier mal mein bisheriger code:

Code:
weiss = Color.new(255,255,255)
schwarz = Color.new(0,0,0)
hinterg = Image.load("zone1.png")
ash = Image.load("ash.png")
ash2 = Image.load("ashlinks.png")
ash3 = Image.load("ashrechts.png")
ash4 = Image.load("ashoben.png")
cursor_x = 200
cursor_y = 150
pic=0
timer=0
animation=0
--Mp3.load("a.mp3")
--Mp3.play()

while true do
screen:clear()

--Zone1
--Wand rechts
if cursor_x >443 then
cursor_x=443
end
--Wand oben
if cursor_y <-10 then
cursor_y=-10
end
--Wand unten
if cursor_y >225 then
    cursor_y=225
end
--Wand links
if cursor_x <8 then
cursor_x=8
end

--Haus unten rechts
--horizontale ebene
if cursor_x <444 and cursor_x >362 and cursor_y >150 and cursor_y <152 then
cursor_y=150
end
if cursor_x <444 and cursor_x >362 and cursor_y >208 and cursor_y <210 then
cursor_y=210
end
--vertikale ebene
if cursor_x >360 and cursor_y <210 and cursor_y >155 then
cursor_x=360
end
--Haus oben
--horizontale ebene
if cursor_x <170 and cursor_x >80 and cursor_y <28 then
cursor_y=28
end
--vertikale ebene
if cursor_x <173 and cursor_x >170 and cursor_y <30 and cursor_y >-15 then
cursor_x=173
end
if cursor_x >77 and cursor_x <80 and cursor_y <30 and cursor_y >-15 then
cursor_x=77
end
-- Bus
--horizontale ebene
if cursor_x >0 and cursor_x <48 and cursor_y <132 and cursor_y>130 then
cursor_y=132
end
if cursor_x >0 and cursor_x <48 and cursor_y >85 and cursor_y<87 then
cursor_y=85
end
--vertikale ebene
if cursor_x <50 and cursor_y <132 and cursor_y >85 then
cursor_x=50
end
--Baeme links
--vertikale ebene
if cursor_x <30 and cursor_y <130 and cursor_y >-15 then
cursor_x=30
end
--Baeme unten
--horizontale ebene
if cursor_x >0 and cursor_x <270 and cursor_y >200 then
cursor_y=200
end
--vertikale ebene
if cursor_x <272 and cursor_y <250 and cursor_y >200 then
cursor_x=272
end

pad = Controls.read()
function Ashbew ()
if pad:right() then
    cursor_x = cursor_x + 1.5
end
if pad:left() then
    cursor_x = cursor_x - 1.5
end

if pad:down() then
    cursor_y = cursor_y + 1.5
end
if pad:up() then
    cursor_y = cursor_y - 1.5
end
end

if pad:down() then
timer = timer + 1
end
if timer > 10 then
    animation = animation + 1
    timer = 0
        if animation > 3 then
        animation = 0
        end
end



if animation == 0 then
pic = 0
elseif animation == 1 then
pic = 32
elseif animation == 2 then
pic = 64
elseif animation == 3 then
pic = 96
end



Ashbew()

screen:blit(0,0,hinterg,true)

screen:blit(cursor_x, cursor_y, ash, pic, 0, 32, 32)

screen.flip()
screen.waitVblankStart()
end


die animation ist halt nur eine durchgehende bei tastendruck und auch nur eine...brache das ganze natürlich auch für alle anderen richtungen...

nutze Lua Hm7 ;D
und bitte keine antworten wie: nimm pge oder c oder ka Tongue
ich würde das gerne mit hm7 lösen...

über hilfe würd ich mich freuen Tongue

morgen Cool
BIG EDIT:
ich hab heute noch ein wenig was probiert und langsam wirds Tongue

folgendes bild verwende ich für die animation:


und den code für die animation habe ich mir mal überlegt:

soweit läuft mein kerlchen auch in die richtige richtungs-animation, jedoch:

Code:
pic=0
timerup=0
timerdown=0
timerright=0
timerleft=0
animation=1

-------------------------------------
if pad:down() then
timerdown = timerdown + 0.125
end
if timerdown == 0.125 then
    animation = 1
elseif timerdown == 1 then
    animation = 2
elseif timerdown == 2 then
    animation = 3

      
        if timerdown == 3 then
        timerdown = 0
        end
end
---------------------------------------
if pad:up() then
timerup = timerup + 0.125
end
if timerup == 0.125 then
    animation = 7
elseif timerup == 1 then
    animation = 8
elseif timerup == 2 then
    animation = 9

      
        if timerup == 3 then
        timerup = 0
        end
end
------------------------------------
if pad:right() then
timerright = timerright + 0.125
end
if timerright == 0.125 then
    animation = 4
elseif timerright == 1 then
    animation = 5
elseif timerright == 2 then
    animation = 6

      
        if timerright == 3 then
        timerright = 0
        end
end
------------------------------------

if animation == 0 then
pic = 0
elseif animation == 1 then
pic = 32
elseif animation == 2 then
pic = 64
elseif animation == 3 then
pic = 96
elseif animation == 4 then
pic = 128
elseif animation == 5 then
pic = 160
elseif animation == 6 then
pic = 192
elseif animation == 7 then
pic = 224
elseif animation == 8 then
pic = 256
elseif animation == 9 then
pic = 288
end

screen:blit(cursor_x, cursor_y, ash, pic, 0, 32, 32)


das problem ist jetzt, dass bei

Code:
if timerxxxx == 3 then
        timerxxx = 0
        end

wird die variable "timerxxx" nicht auf 0 stellt, sondern einfach weiterzält(schätze ich mal) Oo d.h die animation beginnt nicht von vorne, sonder stoppt mit dem letzten bild
hat jemand ne idee was ich falsch mache?

EDIT: omg habs endlich geschafft
bei:

Code:
------------------------------------
if pad:xxx() then
timerxxx = timerxxx + 0.125
end
if timerxxx == 0.125 then
    animation = 4
elseif timerxxx == 1 then
    animation = 5
elseif timerxxx == 2 then
    animation = 6

      
        if timerxxx == 3 then
        timerxxx = 0
        end
end
------------------------------------


gehörte das end nicht mit in den haupt-if befehl...-_-

so sollte das aussehen:

Code:
------------------------------------
if pad:xxx() then
timerxxx = timerxxx + 0.125
end
if timerxxx == 0.125 then
    animation = 4
elseif timerxxx == 1 then
    animation = 5
elseif timerxxx == 2 then
    animation = 6
end
      
        if timerxxx == 3 then
        timerxxx = 0
        end

------------------------------------

Referenz-URLs