Problems moving a rectangle in Pygame.
Posted
by
Yann Core
on Game Development
See other posts from Game Development
or by Yann Core
Published on 2011-01-11T19:34:08Z
Indexed on
2011/01/11
21:59 UTC
Read the original article
Hit count: 198
Hi guys! I'm making a game in Pygame and I want to be able to target enemy unit. I made it so when I click on them a variable "targeted" becomes true, and stays true until I click somewhere else on the screen. I also want targeted units to have a small green circle around them, so I made it in GEDIT. I have made a function that draws everything on the screen (the background, the player, objects, etc) and in the part where it draws the units it checks if the variable "targeted" is true and if it is it should move that little green circle over the enemy units.
here is the code that does that:
screen.blit(enemy_unit.pic, enemy_unit.rect) #draw the unit
if enemy_unit.targeted == True: #if the unit has been targeted then draw a circle over it
target_rect.move_ip(enemy_unit.pos) #move the circle to the unit
target_rect.fit(enemy_unit.rect) #there are some bigger units and some smaller ones, so we have to "scale" the circle
screen.blit(target_pic, target_rect) #actually draw the circle
This doesn't work, when I target the unit the circle just appears for a 1/5 of second next (not on, but just next) to the unit and then disappears. I am sure that I am keeping a good track of "enemy_unit.pos" because I tested it (I added a piece of code that would print one units position and mouse's position every time i clicked the mouse and when i was near him the numbers were same).
If you could give me a hint about what I'm doing wrong. I think its in move_ip function, but I tried just move and it didn't work either (the circle didn't even show at all)!
© Game Development or respective owner