我无法弄清楚如何排序的问题是,当我将一块放在另一块上时,第二块也会与第一块一起拖动。我已经尝试了几种方法将鼠标选择限制为一件,但都失败了。任何人都可以帮忙 - 毫无疑问有一个简单的方法!我所有失败尝试的代码如下:
# In main loop:
# Watch for keyboard and mouse events
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_held = True
if event.type == pygame.MOUSEBUTTONUP:
mouse_held = False
# Update pieces that are in a sprite.Group()
pieces.update(mouse_held)
# In sprite class:
def update(self, mouse_held):
if mouse_held == True:
self.mouse_coordinates = pygame.mouse.get_pos()
if self.rect.collidepoint(self.mouse_coordinates) == True:
self.rect.centerx = self.mouse_coordinates[0]
self.rect.centery = self.mouse_coordinates[1]
答案 0 :(得分:1)
你的问题相当困难,但通过这一切,你应该能够实现你想要的目标。
您应该更改<script>
function EditClick(id, pg) {
var model = {
CurrentPage: pg,
SortColumn: '@Model.SortColumn',
SortStatus: '@Model.SortStatus',
id: id,
};
var formDiv = $("#rplaceInsert");
$.ajax({
cache: false,
type: "Post",
url: "@Url.Action("EditSurgeryType", "SurgeryType")",
contentType: 'application/json',
data: JSON.stringify(model)
,
success: function (data) {
formDiv.html(data);
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
}
类,使其具有名为sprite
的int类型的新变量(&#39;更深的&#39;值)越高。
考虑到你有一个所有精灵对象的列表,你要检查点击depth
的点击,你应该添加:
spriteList
然后改变这些行:
from operator import attrgetter
为:
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_held = True
您应该将if event.type == pygame.MOUSEBUTTONDOWN:
sprites = []
for sprite in spriteList:
if sprite.rect.collidepoint(event.pos) == True:
sprites.append(sprite)
active = min(lists, key=attrgetter('depth'))
mouse_held = True
的{{1}}功能替换为:
sprite
最后,当你想要更新精灵的位置时,只需输入:
update