Page 1 of 1
Walking cycle animation glitch [SOLVED]
Posted: Tue Mar 19, 2019 9:26 pm
by lacticacid
Hi! I'm planning my game to be a mix of a visual novel and a point-and-click adventure style game, so I'm trying to figure out methods to put in the player controlled walk segments. I'm using a slightly modified version of
Per K Grok's
code (Method 3) - I disliked the fact that the character would continuously walk after the player pressed the arrow key and the player would have to press the key a second time in order to make the character stop, as I felt it would be a bit confusing for the player, so I changed it in order to be more similar to the walking mechanics of a regular game (player holds down the key and the character walks, and stops when the player isn't holding down the key anymore). However, that made me run into a small problem: when a cycle is completed, the character disappears off the screen for a brief moment. I'd sincerely appreciate it if someone was willing to help me solve this issue!
Code: Select all
define sX= 440
define sY=130
default rX= -1000.0
default kdir=2
screen checkKey():
if kdir==1:
add "j walkr" xpos sX ypos sY
timer 0.501 action SetVariable("kdir",2)
elif kdir==-1:
add "j walkl" xpos sX ypos sY
timer 0.501 action SetVariable("kdir",-2)
key "K_RIGHT" action [SetVariable("kdir",+1), Jump("t2")]
key "repeat_K_RIGHT" action [SetVariable("kdir",+1), Jump("t2")]
key "K_LEFT" action [SetVariable("kdir",-1), Jump("t2")]
key "repeat_K_LEFT" action [SetVariable("kdir",-1), Jump("t2")]
# The game starts here.
label walk:
scene bg room:
xpos int(rX)
show screen checkKey
label stand:
if kdir==2:
show j right:
xpos sX
ypos sY
else:
show j left:
xpos sX
ypos sY
$ kdir=0
$ renpy.pause(hard=True)
label wtimer:
if rX>-351:
$ rX=-351
$ kdir=-2
jump stand
if rX<-4067:
$ rX=-4067
$ kdir=2
jump stand
$ renpy.pause(delay=0.002, hard=True)
label t2:
if kdir>1:
$ kdir=2
if kdir<-1:
$ kdir=-2
if kdir==1:
jump walkRight
elif kdir==-1:
jump walkLeft
else:
jump stand
label walkRight:
$ rX -= 4.0
scene bg panorama:
xpos int(rX)
jump wtimer
label walkLeft:
$ rX += 4.0
scene bg panorama:
xpos int(rX)
jump wtimer
Re: Walking cycle animation glitch
Posted: Wed Mar 20, 2019 2:29 am
by Per K Grok
lacticacid wrote: ↑Tue Mar 19, 2019 9:26 pm
Hi! I'm planning my game to be a mix of a visual novel and a point-and-click adventure style game, so I'm trying to figure out methods to put in the player controlled walk segments. I'm using a slightly modified version of
Per K Grok's
code (Method 3) - I disliked the fact that the character would continuously walk after the player pressed the arrow key and the player would have to press the key a second time in order to make the character stop, as I felt it would be a bit confusing for the player, so I changed it in order to be more similar to the walking mechanics of a regular game (player holds down the key and the character walks, and stops when the player isn't holding down the key anymore). However, that made me run into a small problem: when a cycle is completed, the character disappears off the screen for a brief moment. I'd sincerely appreciate it if someone was willing to help me solve this issue!
----
I do have one more method to add to my cock book thread that I've not yet come around to do a video on, that is addressing checking if the key is pressed down using the pygame library.
https://www.pygame.org
Below a piece of code using that. That is probably a better path to go down to get what you are looking for.
Code: Select all
image bg sky = "sky.png"
image sem1 = "sem1.png"
image sem2 = "sem2.png"
image sem3 = "sem3.png"
image sem4 = "sem4.png"
image sem5 = "sem5.png"
image sem6 = "sem6.png"
image sem7 = "sem1b.png"
image sem8 = "sem2b.png"
image sem9 = "sem3b.png"
image sem10 = "sem4b.png"
image sem11 = "sem5b.png"
image sem12 = "sem6b.png"
image walk_left:
"sem1"
0.2
"sem2"
0.2
"sem3"
0.2
"sem4"
0.2
"sem5"
0.2
"sem6"
0.2
repeat
image walk_right:
"sem7"
0.2
"sem8"
0.2
"sem9"
0.2
"sem10"
0.2
"sem11"
0.2
"sem12"
0.2
repeat
default semX = 200
default dirt = 0
default dir2 = 1
default mx=0
default my=0
# The game starts here.
init python:
import math
import pygame, os
from pygame.locals import *
def fUpDate(sx):
sx +=1
return sx
def keys():
kdir=0
pressed_key=pygame.key.get_pressed()
if pressed_key[K_RIGHT]:
kdir=1
if pressed_key[K_LEFT]:
kdir=-1
return kdir
label start:
scene bg sky
show screen keyCheck
jump walk
label walk:
$ renpy.pause(delay=0.02, hard=True)
label upDate:
$ dirt = keys()
if dirt==-1:
$ semX -= 2.3
elif dirt==1:
$ semX += 2.3
if semX<20:
$semX=20
elif semX>560:
$semX=560
$ mx = pygame.mouse.get_pos()[0]
$ my = pygame.mouse.get_pos()[1]
jump walk
screen keyCheck:
if dirt==-1:
$ dir2=-1
elif dirt==1:
$ dir2=1
text str(dirt) + ":" + str(dir2)
text str(semX) ypos 20
text str(mx) + ":" + str(my) ypos 10
if dirt==-1:
add "walk_left" xpos int(round(semX)) ypos 200
elif dirt==1:
add "walk_right" xpos int(round(semX)) ypos 200
else:
if dir2==1:
add "sem12" xpos int(round(semX)) ypos 200
elif dir2==-1:
add "sem6" xpos int(round(semX)) ypos 200
[code]
Re: Walking cycle animation glitch
Posted: Wed Mar 20, 2019 3:10 am
by Imperf3kt
While looking through the documentation last week, I needed to browse a section regarding the keymap and in it there was a section about the mouse buttons.
https://www.renpy.org/doc/html/keymap.html
According to it, mousedown_1 is a variable set True while the left mouse button is held down, and mouseup_1 is True when it is released.
Similarly, it has key down and keyup for keyboard presses.
keydown
Matches when the key is being pressed down (the default).
keyup
Matches when the key is being released.
Maybe that could be used?
Re: Walking cycle animation glitch
Posted: Wed Mar 20, 2019 7:06 am
by lacticacid
Per K Grok wrote: ↑Wed Mar 20, 2019 2:29 am
I do have one more method to add to my cock book thread that I've not yet come around to do a video on, that is addressing checking if the key is pressed down using the pygame library.
https://www.pygame.org
Below a piece of code using that. That is probably a better path to go down to get what you are looking for.
Code: Select all
image bg sky = "sky.png"
image sem1 = "sem1.png"
image sem2 = "sem2.png"
image sem3 = "sem3.png"
image sem4 = "sem4.png"
image sem5 = "sem5.png"
image sem6 = "sem6.png"
image sem7 = "sem1b.png"
image sem8 = "sem2b.png"
image sem9 = "sem3b.png"
image sem10 = "sem4b.png"
image sem11 = "sem5b.png"
image sem12 = "sem6b.png"
image walk_left:
"sem1"
0.2
"sem2"
0.2
"sem3"
0.2
"sem4"
0.2
"sem5"
0.2
"sem6"
0.2
repeat
image walk_right:
"sem7"
0.2
"sem8"
0.2
"sem9"
0.2
"sem10"
0.2
"sem11"
0.2
"sem12"
0.2
repeat
default semX = 200
default dirt = 0
default dir2 = 1
default mx=0
default my=0
# The game starts here.
init python:
import math
import pygame, os
from pygame.locals import *
def fUpDate(sx):
sx +=1
return sx
def keys():
kdir=0
pressed_key=pygame.key.get_pressed()
if pressed_key[K_RIGHT]:
kdir=1
if pressed_key[K_LEFT]:
kdir=-1
return kdir
label start:
scene bg sky
show screen keyCheck
jump walk
label walk:
$ renpy.pause(delay=0.02, hard=True)
label upDate:
$ dirt = keys()
if dirt==-1:
$ semX -= 2.3
elif dirt==1:
$ semX += 2.3
if semX<20:
$semX=20
elif semX>560:
$semX=560
$ mx = pygame.mouse.get_pos()[0]
$ my = pygame.mouse.get_pos()[1]
jump walk
screen keyCheck:
if dirt==-1:
$ dir2=-1
elif dirt==1:
$ dir2=1
text str(dirt) + ":" + str(dir2)
text str(semX) ypos 20
text str(mx) + ":" + str(my) ypos 10
if dirt==-1:
add "walk_left" xpos int(round(semX)) ypos 200
elif dirt==1:
add "walk_right" xpos int(round(semX)) ypos 200
else:
if dir2==1:
add "sem12" xpos int(round(semX)) ypos 200
elif dir2==-1:
add "sem6" xpos int(round(semX)) ypos 200
Thank you! I combined this code with the other one so that the background moves instead of the character, so what I ended up with was:
Code: Select all
image bg panorama = "images/panorama.jpg"
image j right = "images/jright1.png"
image j left = "images/jleft1.png"
image j walkr:
"images/jright1.png"
0.25
"images/jright2.png"
0.25
repeat
image j walkl:
"images/jleft1.png"
0.25
"images/jleft2.png"
0.25
repeat
default dirt = 0
default dir2 = 1
default mx=0
default my=0
define jX= 440
define jY=130
default rX= -1000.0
init python:
import math
import pygame, os
from pygame.locals import *
def fUpDate(sx):
sx +=1
return sx
def keys():
kdir=0
pressed_key=pygame.key.get_pressed()
if pressed_key[K_RIGHT]:
kdir=1
if pressed_key[K_LEFT]:
kdir=-1
return kdir
label walklabel:
scene bg panorama
show screen keyCheck
jump walk
label walk:
$ renpy.pause(delay=0.02, hard=True)
scene bg panorama:
xpos int(rX)
label upDate:
$ dirt = keys()
if dirt==-1:
$ rX += 3.3
elif dirt==1:
$ rX -= 3.3
if rX>-351:
$ rX=-351
$ dirt=0
$ dir2=1
if rX<-4067:
$ rX=-4067
$ dirt=0
$ dir2=-1
$ mx = pygame.mouse.get_pos()[0]
$ my = pygame.mouse.get_pos()[1]
jump walk
screen keyCheck:
if dirt==-1:
$ dir2=-1
elif dirt==1:
$ dir2=1
if dirt==-1:
add "j walkl" xpos jX ypos jY
elif dirt==1:
add "j walkr" xpos jX ypos jY
else:
if dir2==1:
add "j right" xpos jX ypos jY
elif dir2==-1:
add "j left" xpos jX ypos jY
It works perfectly now! Thank you!