bit-masks

How to define category bit mask enumeration for SpriteKit in Swift?

萝らか妹 提交于 2019-11-29 22:18:28
To define a category bit mask enum in Objective-C I used to type: typedef NS_OPTIONS(NSUInteger, CollisionCategory) { CollisionCategoryPlayerSpaceship = 0, CollisionCategoryEnemySpaceship = 1 << 0, CollisionCategoryChickenSpaceship = 1 << 1, }; How can I achieve the same using Swift ? I experimented with enumerations but can't get it working. Here is what I tried so far. nschum What you could do is use the binary literals: 0b1 , 0b10 , 0b100 , etc. However, in Swift you cannot bitwise-OR enums, so there is really no point in using bitmasks in enums. Check out this question for a replacement

Pygame - is there any way to only blit or update in a mask

∥☆過路亽.° 提交于 2019-11-27 14:32:49
Is there any way in pygame to blit something to the screen inside a mask. Eg: if you had a mask where all the bits were set to 1 except for the topleft corner and a fully black image, without changing the image, could you keep the top left corner (same as the mask) clear? Only updating a mask (rather than a rect) would help to. Ok, if I'm understanding your question properly, the trick is the BLEND_RGBA_MULT flag. I decided to test this for myself because I was curious. I started with this image: I made an image with white where I wanted the image to show, and transparency where I wanted it

Pygame - is there any way to only blit or update in a mask

萝らか妹 提交于 2019-11-26 16:48:01
问题 Is there any way in pygame to blit something to the screen inside a mask. Eg: if you had a mask where all the bits were set to 1 except for the topleft corner and a fully black image, without changing the image, could you keep the top left corner (same as the mask) clear? Only updating a mask (rather than a rect) would help to. 回答1: Ok, if I'm understanding your question properly, the trick is the BLEND_RGBA_MULT flag. I decided to test this for myself because I was curious. I started with