Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating sprite mask
#1
Hi trying to create a mask for a sprite . this is what I found
sprite.mask = pygame.mask.from_surface(sprite.image)

My question is what do I put here (sprite.image)?
And sprite.mask at the beginning can it be changed to say image3.mask?
Reply
#2
Try testing it out, then come back if you need help
Reply
#3
Hi decided to try doing the collision just using rect for now this is my code for it . It runs but does not detect a hit when the two sprites collide . Any help would be much appreciated .
Quote:image1=pygame.sprite.Sprite()
image1.image = pygame.image.load("picy.png").convert_alpha()
image2 = pygame.sprite.Sprite()
image2.image = pygame.image.load("picy1.png").convert_alpha()
title = pygame.image.load("aba2 title.png")
image1_rect = image1.image.get_rect(topleft=(x,y))
image2_rect = image2.image.get_rect(topleft=(x1,y1))
image1.mask = pygame.mask.from_surface(image1.image)
image2.mask = pygame.mask.from_surface(image2.image)
screen.blit(title,(0,0))
screen.blit(image2.image,(x1,y1))
screen.blit(image1.image,(x,y))
pygame.display.update()


I have edited this post to include the mask code . If I replace .image with _rect or .mask
the code will not run . Help needed please .
Reply
#4
For the colliding -
https://www.pygame.org/project-Rect+Coll...1061-.html


One more thing - Any errors?
Reply
#5
(May-16-2019, 07:13 PM)pfaber11 Wrote: My question is what do I put here (sprite.image)?
And sprite.mask at the beginning can it be changed to say image3.mask?
replace sprite.image with what is returned by pygame.image.load('image_name.png')

it doesnt have to be sprite.mask. You can just do mask.

They are just informing that what is returned is a sprite.mask / sprite.image (not that you have to name them anything like that).

(May-17-2019, 05:31 PM)pfaber11 Wrote: It runs but does not detect a hit when the two sprites collide .
You do not show any code referring to your collision detection, so we could not know.
Recommended Tutorials:
Reply
#6
Thanks for all the replies got it sorted now I am new to python but am learning as I go .
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Sprite image.get_rect() moves sprite to 0, 0 michael1789 2 4,552 Dec-13-2019, 08:37 PM
Last Post: michael1789
  Sprite not rendering Clunk_Head 2 2,095 Oct-03-2019, 11:27 AM
Last Post: Clunk_Head
  Need help making a sprite GalaxyCoyote 4 3,186 Aug-11-2019, 09:12 PM
Last Post: metulburr
  moving a sprite pfaber11 3 2,548 May-15-2019, 12:52 PM
Last Post: pfaber11
  [PyGame] Need Help With Sprite ghost0fkarma 2 3,252 Jan-09-2018, 02:14 PM
Last Post: ghost0fkarma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020