Pygame 中自上而下的运动

2024-01-10

如果这个问题之前已经被问过,我很抱歉,但我到处都检查过,但找不到答案。

如何在 pygame 中进行自上而下的移动?

如果我只使用矩形,这会很容易,但我将使用单个字符精灵(例如,如果我按d为了让玩家向右走,它会向我显示他向右走的角色精灵并将角色向右移动)。

我的意思的示例图片:

这是我的代码:

import pygame # imports pygame
import random # imports the random module
import time
from pygame import mixer # import mixer from pygame
"1) If you see a button(...) or text(...), those are functions I've made.
They don't come with Pygame. But, the stuff inside functions is from Pygame.

2) ... """
pygame.init() # initialises the window. Without this, pygame won't work.

window = pygame.display.set_mode((800, 600)) # window size

running = False 
intro = True # intro value set to true for intro loop

# title of game window
pygame.display.set_caption("Castle Kräftig - Pygame Edition")

# screen sizes in var
screenWidth = 800
screenHeight = 600

background = pygame.image.load('bg.png')  # this stores background in var (actual background is in mainloop)

sprite = pygame.image.load('characterUp.png')

rect = sprite.get_rect()


### rgb for white
##white = (255, 255, 255)
### rgb for green
##green = (0, 200, 0)
### rgb for red
##red = (200, 0, 0)
### rgb for bright green
##brightGreen = (0,255,0)
### rgb for bright red
##brightRed = (255,0,0)

# ----------- CLASSES -------------------------------------

# player class
class player:
    def __init__(self, x, y, w, h, xChange, yChange, vel):
        self.x = x # plater x value
        self.y = y # player y value
        self.w = w # player w (width)
        self.h = h # player h (height)
        self.xChange = xChange # player xChange (to add to x value to move player horizontally)
        self.yChange = yChange # player yChange (to aad to y value to move player vertically)
        self.vel = vel # velocity of player (needed for collision)

    #def draw(self, window):
    #    if self.left:
    #           window.blit(characterAssets[2]

# enemy class
class enemy:
    def __init__(self, x, y, w, h):
        self.x = x # enemy x value
        self.y = y # enemy y value 
        self.w = w # enemy w (width) value
        self.h = h # enemy h (height) value

# ----------------------------------------------------------------

"""enemy's x value (random value) (we pick 750 because the enemy width is 50 and
the screen width is 800. If we set the random value to 800, then the enemy has a
chance of spawning outside of the screen.)"""
enemyX = random.randint(0, 700)

"""enemy's y value (random value) (we pick 540 because the enemy height is 60
and the screen height is 600. If we set the random value to 600, the enemy has a
chance of spawning outside of the screen.)"""
enemyY = random.randint(0, 540) # enemy's y value

score = 0 # score set to 0. Will update in while loop.

rec = player(50, 50, 24, 32, 0, 0, 5) # the player's values (x, y, w, h, xChange, yChange, vel)
redRec = enemy(enemyX, enemyY, 24, 32) # the enemy's values (x, y, w, h)
#---------------------- FUNCTIONS ------------------------

# https://youtu.be/jeZkAKtDIX0 Explination
# collision system function
def detCollision(x, y, w, h, x2, y2, w2, h2):
    if (x2 + w2 >= x >= x2 and y2 + h2 >= y >= y2):
        return True
    elif (x2 + w2 >= x + w >= x2 and y2 + h2 >= y >= y2):
        return True
    elif (x2 + w2 >= x >= x2 and y2 + h2 >= y + h >= y2):
        return True
    elif (x2 + w2 >= x + w >= x2 and y2 + h2 >= y + h >= y2):
        return True
    else:
        return False

"""In case if exiting Pygame for like the window or a button isn't working
properly"""
# quit game function
def quitGame():
    pygame.quit() # quit's pygame
    """SystemExit is here so Pygame doesn't through initialization errors"""
    raise SystemExit # raises a SystemExit so python won't keep running it.

# button function
# message to display,x,y,width,height,colour,colour when mouse is on button,
# locationX of text, locationY of text, and what the button should do
def button(msg,x,y,w,h,locX,locY,action):
    global intro, running, pause, score
    mouse = pygame.mouse.get_pos() # saves mouse position in var
    click = pygame.mouse.get_pressed() # saves if clicked positon in var
    # mouse[0] means no click. mouse[1] means left click. 
    # if the x coordinate + width > x value of mouse > x coordinate and y location + 50 (bottom of box) > y of mouse > then top and bottom of y
    if x + w > mouse[0] > x and y + h > mouse[1] > y:
        # if mouse is on button, make the button brighter
        pygame.draw.rect(window, (124,124,124), (x, y, w, h)) 
        if click[0] == 1: # if mouse click is now left click
            mixer.music.load('click.wav')
            mixer.music.play()
            if action == "start": # if the action is "start"
                """The next 2 lines were added because if u started the game
                then paused, then clicked the main menu, then click start,
                the player would keep moving if you held down any of WASD buttons
                while hitting pause menu button"""
                rec.xChange = 0 # resets player's x change so the player doesn't keep moving without player hitting any key
                rec.yChange = 0 # resets player's y change so the player doesn't keep moving without player hitting any key
                running=True # set running to True
                mainloop() # call mainloop to start game

            elif action == "quit": # if action is "quit"
                quitGame() # call quitGame function

            elif action == "mainMenu": # if action is "mainMenu"
                pause = False # pause var will be set to False
                intro = True # intro var will be set to True to have menu work
                score = 0 # reset score
                rec.x = 50 # put player's x back in starting pos
                rec.y = 50 # put player's y back in starting pos
                mainMenu() # call mainMenu function to start menu

            elif action == "restart": # if action is "restart"
                pause = False # set to false so pausemenu won't keep running
                running = True # set's running to True 
                score = 0 # restart's score
                rec.x = 50 # resets player's x value
                rec.y = 50 # reset player's y value
                rec.xChange = 0 # resets player's x change so player doesn't keep moving without player hitting any key
                rec.yChange = 0 # resets player's y change so player doesn't keep moving without player hitting any key
                mainloop() # starts mainloop to restart the game

            elif action == "resume": # if action is "resume"
                running = True # set running to True again
                rec.xChange = 0 # resets player's x change so player doesn't keep moving without player hitting any key
                rec.yChange = 0 # resets player's y change so player doesn't keep moving without player hitting any key
                mainloop() # start the game once more

            elif action == "direct": # if action is direct
                intro = False # stop showing intro screen
                dMenu() # show the directionsMenu

    else: # other wise
        # if mouse is not on button, don't change colour
        pygame.draw.rect(window, (94,94,94), (x,y,w,h)) 

    # msg = is the message locX is text x pos and locY is text y pos
    text(msg, (0,0,0), locX, locY, 20, True) # the text on the button

# text function which will make text with parameters
""" msg is the message to display. Colour is the colour of text. textX is text's
x pos and textY is text's y pos. size is text size and bold is if we want text
to be bold"""
def text(msg, colour, textX, textY, size, bold):
    font = pygame.font.SysFont('times-new-roman', size, bold)
    window.blit(font.render(msg, 1, colour), (textX, textY))

# redraw game window 
def redrawWin(collisions):
    global score, sprite
    # draws the enemy
    pygame.draw.rect(window, (255,0,0), (redRec.x, redRec.y, redRec.w, redRec.h))
    # draws the player

    pygame.draw.rect(window, (0,255,0), (rec.x, rec.y, rec.w, rec.h))
    # renders Score
    text("Score: " + str(score), (255,0,0), 5, 10, 30, True) 
    # updates screen

    pygame.display.update()
    if collisions == True: # if collisions happen
        score += 1 # add one to score
        redRec.x = random.randint(0, 750) # set a new enemy x value
        redRec.y = random.randint(0, 540) # set a new enemy y value



# mainMenu function
def mainMenu():
    global running, largeText, intro

    while intro:
        for event in pygame.event.get(): # for every event in game
            #print(event)
            if event.type == pygame.QUIT: # if tries to quit
                quitGame()

            if event.type == pygame.KEYDOWN: # if any key is pressed
                if event.key == pygame.K_F4:
                    quitGame()




        # fills window with white
        window.fill((0,0,0))
        # Text for main menu (one is there cuz it has to be)

        # title
        text("Castle Kräftig", (255,0,0), (screenWidth / 2 - 230), (screenHeight - (screenHeight / 2 + 150)), 75, True)
        # where to place the text above
        # directions text
        button("Directions", 350, 290, 100, 50, 353, 300, "direct") 
        #text('Controls: WASD to move', (0,0,0), (screenWidth / 2 - 200), (screenHeight - (screenHeight / 2)), 30, True)

        # buttons for main menu

        button("Start", 150, 450, 100, 50, 175, 465, "start")
        button("Quit", 550, 450, 100, 50, 580, 465, "quit")


        pygame.display.update() # updates screen
        pygame.time.delay(15) # delays by 15 ticks

    pygame.quit()   

def pauseMenu():
    global running, largeText 
    intro = False # intro set to false and...
    running = False # running set to false so mainlooop & mainmenu won't run 
    pause = True # to start the Pause sreen
    while pause: # while pause is true
        for event in pygame.event.get(): # for all events in pygame
            if event.type == pygame.QUIT: # if tries to quit window
                quitGame() # call quitGame() function

            if event.type == pygame.KEYDOWN: # if any key is pressed
                if event.key == pygame.K_F4: # if F4 is pressed 
                    quitGame() # call quitGame() function

        # keep filling window with white (so no weirdness and also have
        # background white)
        window.fill((0,0,0))
        # Pause menu text display
        text("PAUSED", (255,0,0), (screenWidth / 2 - 150), (screenHeight - (screenHeight / 2 + 150)), 75, True)
        # Button for Main Menu
        button("Main Menu", 345, 450, 110, 50, 350, 465, "mainMenu")
        # button for restarting game 
        button("Restart", 350, 375, 100, 50, 365, 390, "restart")
        # button for resuming game
        button("Resume", 350, 300, 100, 50, 365, 315, "resume")
        # button for quitting game
        button("Quit", 350, 525, 100, 50, 380, 540, "quit")
        pygame.display.update() # updates screen
        pygame.time.delay(15) # delays by 15 ticks

# directions menu
def dMenu(): 
    insMenu = True # set loop to true
    while insMenu: # whiles insMenu is True
        for event in pygame.event.get(): # for all events that happen
            if event.type == pygame.QUIT: # if player tries to quit
                quitGame() # call quitGame()

            if event.type == pygame.KEYDOWN: # if any key is pressed
                if event.key == pygame.K_F4: # if F4 is pressed
                    quitGame() # call quitGame()

        window.fill((0,0,0)) # fill screen with white
        """ALL TEXT FOR DIRECTIONS/CONTROLS MENU WITH PLACEMENT"""
        text("DIRECTIONS/CONTROLS", (255,0,0), (screenWidth / 2 - 300), (screenHeight - (screenHeight / 2 + 250)), 50, True)
        text("W = Move Up", (140,140,140), (screenWidth / 2 - 75), (screenHeight - (screenHeight / 2 + 150)), 25, False)
        text("A = Move Left", (140,140,140), (screenWidth / 2 - 75), (screenHeight - (screenHeight / 2 + 125)), 25, False)
        text("S = Move Down", (140,140,140), (screenWidth / 2 - 75), (screenHeight - (screenHeight / 2 + 100)), 25, False)
        text("D = Move Right", (140,140,140), (screenWidth / 2 - 75), (screenHeight - (screenHeight / 2 + 75)), 25, False)
        text("F4 = Exit Game", (140,140,140), (screenWidth / 2 - 75), (screenHeight - (screenHeight / 2 + 50)), 25, False)
        text("O = Pause Game", (140,140,140), (screenWidth / 2 - 75), (screenHeight - (screenHeight / 2 + 25)), 25, False)
        text("Your goal in this game is to kill all ", (140,140,140), (screenWidth / 2 - 175), (screenHeight - (screenHeight / 2 - 75)), 25, False)
        text("the Nazis in Castle Kräftig. This game ", (140,140,140), (screenWidth / 2 - 175), (screenHeight - (screenHeight / 2 - 100)), 25, False)
        text("does NOT end. Play until you want to  ", (140,140,140), (screenWidth / 2 - 175), (screenHeight - (screenHeight / 2 - 125)), 25, False)      
        text("stop.", (140,140,140), (screenWidth / 2  - 175), (screenHeight - (screenHeight / 2 - 150)), 25, False)

        # Main Menu button to go back to main menu
        button("Main Menu", 345, 525, 110, 50, 350, 540, "mainMenu")

        pygame.display.update() # update python
        pygame.time.delay(15) # delay by 15 ticks

############################## mainloop #############################
def mainloop():
    global running, score, intro, sprite, degrees

    while running:
        """keeps filling window with the colour of choice. without this, the
        rectangle will "paint" the screen."""
        window.blit(background, (0, 0))

        #window.blit(background, (0, 0))
        pygame.time.delay(25) # delay
        for event in pygame.event.get(): # for every event in game
            if event.type == pygame.QUIT: # if I exit the game
                pygame.quit()

            if event.type == pygame.KEYUP: # if any keys are let go
                if event.key == pygame.K_a: # if key a
                    rec.xChange = 0 # set xChange to 0 (stop moving rec)

                if event.key == pygame.K_d: # if key d
                    rec.xChange = 0 # set xChange to 0 (stop moving rec)

                if event.key == pygame.K_w: # if key w
                    rec.yChange = 0 # set xChange to 0 (stop moving rec)

                if event.key == pygame.K_s: # if key s
                    rec.yChange = 0 # set xChange to 0 (stop moving rec)

                # pause key to pause game
                if event.key == pygame.K_o: # if key o
                    running = False # set running to false
                    intro = False # intro set to False
                    pauseMenu() # pauseMenu is called

            if event.type == pygame.KEYDOWN: # if any keys are pressed
                if event.key == pygame.K_F4: # if key F4
                    """(when set to false, the game will exit because of the
                    pygame.quit() command below mainloop)"""
                    pygame.quit() # set running to false

                if event.key == pygame.K_a: # if key a
                    rec.xChange += -5 # add -5 to xChange (move rec left)

                if event.key == pygame.K_d: # if key a
                    rec.xChange += 5 # adds 5 to xChange (move rec right)

                if event.key == pygame.K_w: # if key a
                    #adds -5 to yChange (moves rec up). Yes, this is supposed to say up.
                    rec.yChange += -5 # 

                if event.key == pygame.K_s: # if key a
                    # adds 5 to yChange (moves rec down). Yes, this is supposed to say down.
                    rec.yChange += 5 


        rec.x += rec.xChange # add rec's xChange to x (to do the moving)
        rec.y += rec.yChange # adds rec's yChange to y (to do the moving)



        # ----------------BOUNDARIES------------------------------
        if rec.x <= 0: # if rec's x is less than or equal to 0 (if tries to escape screen)
            rec.x  = 0 # rec's x is set to 0 so it won't go off screen.

        """(we pick 750 because the player width is 50 and the screen width is 800.
        If we set it to 800, then the player can go outside of screen."""   
        if rec.x  >= 750: # if rec's x is greater than or equal to 750 (if tries to escape screen)
            rec.x  = 750  # set rec's x to 750 so it won't go off screen

        if rec.y <= 0: # if rec's y is less than or equal to 0 (if tries to escape screen)
            rec.y = 0 # set rec's y to 0 so it won't go off screen
        """we pick 540 because the player height is 60 and the screen height is 600.
            If we set it to 600, then the player can go outside of screen"""
        if rec.y >= 540: # if rec'y is greater than or equal to 540 (if tries to escape screen) 
            rec.y = 540 # set rec's y to 540 so it won't go off screen  

        collisions = detCollision(rec.x, rec.y, rec.w, rec.h, redRec.x, redRec.y, redRec.w, redRec.h)
        # activate the redrawWin function
        redrawWin(collisions)


mainMenu() # call mainMenu first
mainloop() # call mainloop if can
pygame.quit() # activates if nothing else is now running

我知道这段代码可以改进,但我真的只想知道如何移动精灵。


加载 4 个不同的精灵,用于 4 个方向:

spriteUp    = pygame.image.load('characterUp.png')
spriteDown  = pygame.image.load('characterDown.png')
spriteLeft  = pygame.image.load('characterLeft.png')
spriteRight = pygame.image.load('characterRight.png')

Init sprite通过其中的图像,例如:

sprite = spriteUp

当按下某个键时(pygame.KEYDOWN事件),然后更改sprite:

for event in pygame.event.get():
    # [...]

    if event.type == pygame.KEYDOWN: # if any keys are pressed
        # [...]

       if event.key == pygame.K_a: # if key a
           rec.xChange += -5 # add -5 to xChange (move rec left)
           sprite = spriteLeft

       if event.key == pygame.K_d: # if key a
           rec.xChange += 5 # adds 5 to xChange (move rec right)
           sprite = spriteRight

       if event.key == pygame.K_w: # if key a
           #adds -5 to yChange (moves rec up). Yes, this is supposed to say up.
           rec.yChange += -5 #
           sprite = spriteUp 

       if event.key == pygame.K_s: # if key a
           # adds 5 to yChange (moves rec down). Yes, this is supposed to say down.
           rec.yChange += 5 
           sprite = spriteDown

blit https://www.pygame.org/docs/ref/surface.html#pygame.Surface.blit the sprite表面,而不是绘制矩形:

pygame.draw.rect(window, (0,255,0), (rec.x, rec.y, rec.w, rec.h))

window.blit(sprite, (rec.x, rec.y))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Pygame 中自上而下的运动 的相关文章

  • 下载 PyQt6 的 Qt Designer 并使用 pyuic6 将 .ui 文件转换为 .py 文件

    如何下载 PyQt6 的 QtDesigner 如果没有适用于 PyQt6 的 QtDesigner 我也可以使用 PyQt5 的 QtDesigner 但是如何将此 ui 文件转换为使用 PyQt6 库而不是 PyQt5 的 py 文件
  • 如何在刻度标签和轴之间添加空间

    我已成功增加刻度标签的字体 但现在它们距离轴太近了 我想在刻度标签和轴之间添加一点呼吸空间 如果您不想全局更改间距 通过编辑 rcParams 并且想要更简洁的方法 请尝试以下操作 ax tick params axis both whic
  • 使用 openCV 对图像中的子图像进行通用检测

    免责声明 我是计算机视觉菜鸟 我看过很多关于如何在较大图像中查找特定子图像的堆栈溢出帖子 我的用例有点不同 因为我不希望它是具体的 而且我不确定如何做到这一点 如果可能的话 但我感觉应该如此 我有大量图像数据集 有时 其中一些图像是数据集的
  • Pycharm Python 控制台不打印输出

    我有一个从 Pycharm python 控制台调用的函数 但没有显示输出 In 2 def problem1 6 for i in range 1 101 2 print i end In 3 problem1 6 In 4 另一方面 像
  • DreamPie 不适用于 Python 3.2

    我最喜欢的 Python shell 是DreamPie http dreampie sourceforge net 我想将它与 Python 3 2 一起使用 我使用了 添加解释器 DreamPie 应用程序并添加了 Python 3 2
  • 如何打印没有类型的defaultdict变量?

    在下面的代码中 from collections import defaultdict confusion proba dict defaultdict float for i in xrange 10 confusion proba di
  • 如何在Windows上模拟socket.socketpair

    标准Python函数套接字 套接字对 https docs python org 3 library socket html socket socketpair不幸的是 它在 Windows 上不可用 从 Python 3 4 1 开始 我
  • Python tcl 未正确安装

    我刚刚为 python 安装了graphics py 但是当我尝试运行以下代码时 from graphics import def main win GraphWin My Circle 100 100 c Circle Point 50
  • 从 scikit-learn 导入 make_blobs [重复]

    这个问题在这里已经有答案了 我收到下一个警告 D Programming Python ML venv lib site packages sklearn utils deprecation py 77 DeprecationWarning
  • keras加载模型错误尝试将包含17层的权重文件加载到0层的模型中

    我目前正在使用 keras 开发 vgg16 模型 我用我的一些图层微调 vgg 模型 拟合我的模型 训练 后 我保存我的模型model save name h5 可以毫无问题地保存 但是 当我尝试使用以下命令重新加载模型时load mod
  • Geopandas 设置几何图形:MultiPolygon“等于 len 键和值”的 ValueError

    我有 2 个带有几何列的地理数据框 我将一些几何图形从 1 个复制到另一个 这对于多边形效果很好 但对于任何 有效 多多边形都会返回 ValueError 请指教如何解决这个问题 我不知道是否 如何 为什么应该更改 MultiPolygon
  • 表达式中的 Python 'in' 关键字与 for 循环中的比较 [重复]

    这个问题在这里已经有答案了 我明白什么是in运算符在此代码中执行的操作 some list 1 2 3 4 5 print 2 in some list 我也明白i将采用此代码中列表的每个值 for i in 1 2 3 4 5 print
  • Python - 在窗口最小化或隐藏时使用 pywinauto 控制窗口

    我正在尝试做的事情 我正在尝试使用 pywinauto 在 python 中创建一个脚本 以在后台自动安装 notepad 隐藏或最小化 notepad 只是一个示例 因为我将编辑它以与其他软件一起使用 Problem 问题是我想在安装程序
  • Numpy 优化

    我有一个根据条件分配值的函数 我的数据集大小通常在 30 50k 范围内 我不确定这是否是使用 numpy 的正确方法 但是当数字超过 5k 时 它会变得非常慢 有没有更好的方法让它更快 import numpy as np N 5000
  • 如何改变Python中特定打印字母的颜色?

    我正在尝试做一个简短的测验 并且想将错误答案显示为红色 欢迎来到我的测验 您想开始吗 是的 祝你好运 法国的首都是哪里 法国 随机答案不正确的答案 我正在尝试将其显示为红色 我的代码是 print Welcome to my Quiz be
  • Python:计算字典的重复值

    我有一本字典如下 dictA unit1 test1 alpha unit1 test2 beta unit2 test1 alpha unit2 test2 gamma unit3 test1 delta unit3 test2 gamm
  • 用于运行可执行文件的python多线程进程

    我正在尝试将一个在 Windows 上运行可执行文件并管理文本输出文件的 python 脚本升级到使用多线程进程的版本 以便我可以利用多个核心 我有四个独立版本的可执行文件 每个线程都知道要访问它们 这部分工作正常 我遇到问题的地方是当它们
  • 从 Python 中的类元信息对 __init__ 函数进行类型提示

    我想做的是复制什么SQLAlchemy确实 以其DeclarativeMeta班级 有了这段代码 from sqlalchemy import Column Integer String from sqlalchemy ext declar
  • 在python中,如何仅搜索所选子字符串之前的一个单词

    给定文本文件中的长行列表 我只想返回紧邻其前面的子字符串 例如单词狗 描述狗的单词 例如 假设有这些行包含狗 hotdog big dog is dogged dog spy with my dog brown dogs 在这种情况下 期望
  • Spark.read 在 Databricks 中给出 KrbException

    我正在尝试从 databricks 笔记本连接到 SQL 数据库 以下是我的代码 jdbcDF spark read format com microsoft sqlserver jdbc spark option url jdbc sql

随机推荐

  • 概括 python 脚本以在目录中的所有文件上运行

    我有以下 python 脚本 with open ein csv r as istr with open aus csv w as ostr for line in istr line line rstrip n 1 print line
  • 这是一个指针吗? (如果是的话,它是如何初始化的?)

    有一个头文件 esUtil h 其中定义了一个名为 ESContext 的结构 其成员之一是 userData userData 是一个指向 void 的指针 使用它的程序主体如下 include esUtil h typedef stru
  • Facebook Connect for iOS:dialogDidComplete 响应区分

    我想知道如何区分用户在内联后流 FBDialog 中点击 提交 或 跳过 有谁知道要测试什么吗 我在 iOS 4 2 环境中使用最新的 iOS Facebook Connect Called when a UIServer Dialog s
  • 再次重新处理/读取Kafka记录/消息 - Consumer Group Offset Reset的目的是什么?

    我的 kafka 主题总共有 10 条记录 消息 2 个分区 每个分区有 5 条消息 我的消费者组有 2 个消费者 每个消费者已经分别从其分配的分区读取了 5 条消息 现在 我想从开始 开始 偏移量 0 重新处理 读取我的主题中的消息 我停
  • 带注释的收藏袋

    我正在观看一个由 制作的精彩视频伯特 贝克威斯 http www infoq com presentations GORM Performance http www infoq com presentations GORM Performa
  • 无法检索 Eclipse 插件中选定的 java 文件名/路径

    我正在开发一个插件 需要 检索 java 文件的路径 文件名 我编写的代码成功检索了 xml 或清单文件的文件名 路径 但无法检索包中 Java 文件的路径 我使用的代码是 if IStructuredSelection 的选择实例 Obj
  • 如何在Vue JS中动态渲染组件?

    我正在制作一个表单生成器 它使用其中的组件作为输入字段 按钮等 我希望能够根据我传递给它的选项来生成表单 但我无法让它渲染组件 我尝试返回纯 HTML 但这不会渲染组件 我从 Home vue 模板中调用表单生成器 我希望表单具有如下所示的
  • 线程池并行处理消息,但保留对话中的顺序

    我需要并行处理消息 但保留具有相同会话 ID 的消息的处理顺序 Example 让我们像这样定义一个消息 class Message Message long id long conversationId String someData 假
  • iOS 7.1 删除超级视图崩溃

    我的应用程序没有发生任何崩溃 直到iOS 7 1出来 现在在任何removeFromSuperview方法 崩溃 例如 我有视图控制器 当我想删除视图控制器时 我删除它的所有子视图 然后从堆栈中删除 堆栈 我在其中存储视图控制器 用于加载新
  • 如何在 AngularJS 中交换 div 元素的顺序?

    如何使用 Angular 的数据绑定更改包含文本框和下拉列表的 div 元素的顺序 div 的顺序应相应更改用户登录意味着如果用户类型为 A 则 div A 应位于顶部 如果用户类型为 B 则 div B 应位于顶部 其他 div 元素将位
  • 无法使用 Firebase CLI 登录

    当我尝试使用 CLI 登录 Firebase 时遇到问题 我安装了firebase tools using npm g install firebase tools具有管理员权限 我执行的步骤是 从 Windows 10 Professio
  • 删除第一页的页眉和页脚

    class MyDocTemplate BaseDocTemplate def init self filename kw self allowSplitting 0 apply BaseDocTemplate init self file
  • 如何借助 FFMPEG 和 PHP 代码连接两个 mp4 视频? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 有人可以帮助我使用 FFMPEG 的 php 代码来连接两个 mp4 视频并将连接的文件作为 mp4 存储在服务器中的任何文件夹中吗
  • jQuery 仅序列化 div 中的元素

    我想得到同样的效果jQuery serialize 但我只想返回给定的子元素div 结果示例 single Single2 multiple Multiple radio radio1 没问题 只需使用以下内容即可 这将与序列化表单完全相同
  • js中能获取之前的历史状态对象吗?

    当我点击后退或前进按钮并且 popstate 事件触发时 我可以获得前一个状态的状态对象吗 因为不是 e state 提供的状态对象 而是我刚刚后退 转发的状态对象 或者 我可以检测按下的是后退按钮还是前进按钮 我需要这个 因为我有多个子系
  • 匹配点集的算法

    我有两组点A and B 而点可以是 2D 或 3D 两套尺寸相同n 相当低 5 20 我想知道这些集合的一致性如何 也就是说 理想情况下 我会找到点之间的配对 使得所有欧几里得对距离的总和d A B 是最小的 所以 d A B sum i
  • PhoneGap FileReader/readAsDataURL 不触发回调

    我正在使用 PhoneGap Build 构建 iOS v7 1 应用程序并使用weinre http people apache org pmuellr weinre docs latest 进行调试 我正在使用媒体捕获插件和文件 API
  • 获取中间件中的路由定义

    有谁知道是否可以获取用于触发路线的路径 例如 假设我有这个 app get user id function req res 使用以下简单的中间件 function req res next req 我希望能够得到 user id在中间件中
  • Instagram Streaming API 的 Logstash 输入插件

    我想阅读 Instagram 上的活动 我想知道我是否可以使用 Logstash 来做到这一点 类似于使用 Twitter 输入插件从 Twitter 读取事件 但 Instagram 没有输入插件 还有其他方法可以使用 Logstash
  • Pygame 中自上而下的运动

    如果这个问题之前已经被问过 我很抱歉 但我到处都检查过 但找不到答案 如何在 pygame 中进行自上而下的移动 如果我只使用矩形 这会很容易 但我将使用单个字符精灵 例如 如果我按d为了让玩家向右走 它会向我显示他向右走的角色精灵并将角色