使用Raycast函数显示图像时,我无法使python工作,该如何解决?
我尝试移动一些变量并使用该函数,但是似乎无法正常工作。
import pygame
pygame.init()
Screen = "Title"
DB = 0
Width = 800
Height = 600
Frame = pygame.display.set_mode((Width,Height))
pygame.display.set_caption("GAME")
FPS = pygame.time.Clock()
def Raycast(RayXPos, RayYPos):
RaycastThis = pygame.image.load(TTR)
Frame.blit(RaycastThis, (RayXPos, RayYPos))
Loop = True
while Loop == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
pygame.display.update()
FPS.tick(60)
while Screen == "Title" and DB == 0:
TTR = 'TitleScreenSmall.png'
Raycast(0, 0)
我希望框架显示图像(与窗口大小相同),但它崩溃了,并且我无法运行程序
答案 0 :(得分:1)
您的问题是无限循环:
<button id="button" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="Add a recipe">Add a recipe</button>
<!-- end of button -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New Recipe</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form class="recipe-form" action="/pizza" method="POST">
<a id="userId" data-id="1"></a>
<input type="text" id="pizza-title" name="pizza-title" placeholder="title"><br>
<input type="text" id="pizza-recipe" name="pizza-recipe" placeholder="recipe"><br>
<label for="vegy1">Cucumber</label>
<input type="number" class="quant" name="vegy1" data-name="cucumber" min="0" max="3" value="0">
<label for="vegy2">Tomato</label>
<input type="number" class="quant" name="vegy2" data-name="tomato" min="0" max="3" value="0">
<label for="vegy3">Pineapple</label>
<input type="number" class="quant" name="vegy3" data-name="pineapple" min="0" max="3" value="0">
<label for="vegy4">Avocado</label>
<input type="number" class="quant" name="vegy4" data-name="avocado" min="0" max="3" value="0"><br>
<label for="vegy5">Eggplant</label>
<input type="number" class="quant" name="vegy5" data-name="eggplant" min="0" max="3" value="0">
<label for="vegy6">Olive</label>
<input type="number" class="quant" name="vegy6" data-name="olive" min="0" max="3" value="0">
<label for="vegy7">Onion</label>
<input type="number" class="quant" name="vegy7" data-name="onion" min="0" max="3" value="0">
<label for="vegy8">Mushroom</label>
<input type="number" class="quant" name="vegy8" data-name="mushroom" min="0" max="3" value="0"><br>
<label for="vegy9">Garlic</label>
<input type="number" class="quant" name="vegy9" data-name="garlic" min="0" max="3" value="0">
<label for="vegy10">Spinach</label>
<input type="number" class="quant" name="vegy10" data-name="spinach" min="0" max="3" value="0">
<label for="vegy11">Cilantro</label>
<input type="number" class="quant" name="vegy11" data-name="cilantro" min="0" max="3" value="0">
<label for="vegy12">Chicken</label>
<input type="number" class="quant" name="vegy12" data-name="chicken" min="0" max="3" value="0"><br>
<label for="vegy13">Anchovy</label>
<input type="number" class="quant" name="vegy13" data-name="anchovy" min="0" max="3" value="0">
<label for="vegy14">Bacon</label>
<input type="number" class="quant" name="vegy14" data-name="bacon" min="0" max="3" value="0">
<label for="vegy15">Sausage</label>
<input type="number" class="quant" name="vegy15" data-name="sausage" min="0" max="3" value="0">
<label for="vegy16">Beef</label>
<input type="number" class="quant" name="vegy16" data-name="beef" min="0" max="3" value="0"><br>
<label for="vegy17">Ham</label>
<input type="number" class="quant" name="vegy17" data-name="ham" min="0" max="3" value="0">
<label for="vegy18">Pepperoni</label>
<input type="number" class="quant" name="vegy18" data-name="pepperoni" min="0" max="3" value="0">
<label for="vegy19">Salami</label>
<input type="number" class="quant" name="vegy19" data-name="salami" min="0" max="3" value="0">
<label for="vegy20">Banana</label>
<input type="number" class="quant" name="vegy20" data-name="banana" min="0" max="3" value="0"><br>
<p id="totalCal"></p>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary addPizza">Add Recipe</button>
</div>
</form>
</div>
</div>
</div>
</div>
由于循环控制变量while Screen == "Title" and DB == 0:
TTR = 'TitleScreenSmall.png'
Raycast(0, 0)
和Screen
永不改变,因此您无法退出循环。您被困在这里,永远重复执行一项功能,几乎没有任何变化,并且无需观察任何变化。
请参阅这个可爱的debug博客以获取帮助。