imagemap hold or something like that

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
luat1995
Newbie
Posts: 24
Joined: Mon Nov 07, 2016 8:27 am
Completed: Home Alone
Github: https://github.com/luatsenpai
itch: https://luatsenpai.i
Location: vietnamese
Contact:

imagemap hold or something like that

#1 Post by luat1995 »

Hello there. I try make game like that:
Image
when i try imagemap for left and right arrow
example:

Code: Select all

image bg="room.png"

image stand = "1.png"

image walk:
    "1.png"
    0.3
    "2.png"
    0.3
    "3.png"
    0.3
    "4.png"
    0.3
    "5.png"
    0.3
    repeat

default sX= 310
default sY=260
default mX=0
default dist=0
default standWalk=0
default test=50

screen check():
    imagebutton auto "images/left_%s.png" xpos 35 ypos 581 action [SetVariable('mX', mX - 1), jump("walkLeft")
    imagebutton auto "images/right_%s.png" xpos 134 ypos 581 action [SetVariable('mX', mX + 1), jump("walkRight")

label start:
    scene bg
    show screen check
 label standRight:
    $ standWalk=0

    show semi stand:
        xpos sX
        ypos sY
        xzoom 1.0

    $ renpy.pause(hard=True)

label standLeft:
    $ standWalk=0

    show semi stand:
        xpos sX
        ypos sY
        xzoom -1.0

    $ renpy.pause(hard=True)

label walkRight:
    $ standWalk=1

    show semi walk:
        xpos sX
        ypos sY
        xzoom 1.0
        linear dist/100.0 xpos mX

    $ renpy.pause(delay=dist/100.0, hard=True)
    $ sX=mX
    jump standRight

label walkLeft:
    $ standWalk=1

    show semi walk:
        xpos sX
        ypos sY
        xzoom -1.0
        linear dist/100.0 xpos mX

    $ renpy.pause(delay=dist/100.0, hard=True)
    $ sX=mX
    jump standLeft
and character only move when tap imagemap and it so slow, i want some thing like hold of tap to move
Somebody help me, Thank :D
p/s: sorry my bad english

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: imagemap hold or something like that

#2 Post by Per K Grok »

luat1995 wrote: Sat Aug 31, 2019 4:37 am Hello there. I try make game like that:
Image
when i try imagemap for left and right arrow

------

OK. I see that your using my "walking character" code that is in the cook book.

I have a couple of different examples in that post for different situations. Most examples are based on the player indicating the endpoint of the walk. It is that kind of code you have in your example.

What you want to do is however to have a character walking while a button is pressed. That needs a different approach. For this you need a loop that keep checking if the button is pressed and adding to the walk while that is true.

My example 3 is that kind of code.

It is different from what you want to do in that it moves the background rather than the player character and the buttons are keyboard buttons not screen buttons. Those things can be changed.

The thing that makes this work is the loop that starts with label wtimer.

Also note that the walk animation need to be in the screen.

Code: Select all

image bg room="longroom.png"

image semi stand = "sem6b.png"


image semi walk:
    "sem1b.png"
    0.3
    "sem2b.png"
    0.3
    "sem3b.png"
    0.3
    "sem4b.png"
    0.3
    "sem5b.png"
    0.3
    "sem6b.png"
    0.3
    repeat

define sX= 310
define sY=335
default rX= -1000.0

default kdir=2

screen checkKey():
    if kdir==1:
        add "semi walk" xpos sX ypos sY xzoom 1.0
    elif kdir==-1:
        add "semi walk" xpos sX ypos sY xzoom -1.0

    key "K_RIGHT" action [SetVariable("kdir",kdir+1), Jump("t2")]
    key "K_LEFT" action [SetVariable("kdir",kdir-1), Jump("t2")]


# The game starts here.
label start:
    scene bg room:
        xpos int(rX)
    show screen checkKey


label stand:
    if kdir==2:
        show semi stand:
            xpos sX
            ypos sY
            xzoom 1.0
    else:
        show semi stand:
            xpos sX
            ypos sY
            xzoom -1.0

    $ 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.02, 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 -= 2.3
    scene bg room:
        xpos int(rX)
    jump wtimer

label walkLeft:
    $ rX += 2.3
    scene bg room:
        xpos int(rX)
    jump wtimer


User avatar
luat1995
Newbie
Posts: 24
Joined: Mon Nov 07, 2016 8:27 am
Completed: Home Alone
Github: https://github.com/luatsenpai
itch: https://luatsenpai.i
Location: vietnamese
Contact:

Re: imagemap hold or something like that

#3 Post by luat1995 »

Thank, i just want made some game for android :D

Post Reply

Who is online

Users browsing this forum: Google [Bot]