本文整理汇总了Python中pandac.PandaModules.PNMImage.alphaFill方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.alphaFill方法的具体用法?Python PNMImage.alphaFill怎么用?Python PNMImage.alphaFill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.PNMImage
的用法示例。
在下文中一共展示了PNMImage.alphaFill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pandac.PandaModules import PNMImage [as 别名]
# 或者: from pandac.PandaModules.PNMImage import alphaFill [as 别名]
class Sprite2d:
class Cell:
def __init__(self, col, row):
self.col = col
self.row = row
def __str__(self):
return "Cell - Col %d, Row %d" % (self.col, self.row)
class Animation:
def __init__(self, cells, fps):
self.cells = cells
self.fps = fps
self.playhead = 0
ALIGN_CENTER = "Center"
ALIGN_LEFT = "Left"
ALIGN_RIGHT = "Right"
ALIGN_BOTTOM = "Bottom"
ALIGN_TOP = "Top"
TRANS_ALPHA = TransparencyAttrib.MAlpha
TRANS_DUAL = TransparencyAttrib.MDual
# One pixel is divided by this much. If you load a 100x50 image with PIXEL_SCALE of 10.0
# you get a card that is 1 unit wide, 0.5 units high
PIXEL_SCALE = 20.0
def __init__(self, image_path, rowPerFace, name=None,\
rows=1, cols=1, scale=1.0,\
twoSided=False, alpha=TRANS_ALPHA,\
repeatX=1, repeatY=1,\
anchorX=ALIGN_CENTER, anchorY=ALIGN_BOTTOM):
"""
Create a card textured with an image. The card is sized so that the ratio between the
card and image is the same.
"""
global SpriteId
self.spriteNum = str(SpriteId)
SpriteId += 1
scale *= self.PIXEL_SCALE
self.animations = {}
self.scale = scale
self.repeatX = repeatX
self.repeatY = repeatY
self.flip = {'x':False,'y':False}
self.rows = rows
self.cols = cols
self.currentFrame = 0
self.currentAnim = None
self.loopAnim = False
self.frameInterrupt = True
# Create the NodePath
if name:
self.node = NodePath("Sprite2d:%s" % name)
else:
self.node = NodePath("Sprite2d:%s" % image_path)
# Set the attribute for transparency/twosided
self.node.node().setAttrib(TransparencyAttrib.make(alpha))
if twoSided:
self.node.setTwoSided(True)
# Make a filepath
self.imgFile = Filename(image_path)
if self.imgFile.empty():
raise IOError, "File not found"
# Instead of loading it outright, check with the PNMImageHeader if we can open
# the file.
imgHead = PNMImageHeader()
if not imgHead.readHeader(self.imgFile):
raise IOError, "PNMImageHeader could not read file. Try using absolute filepaths"
# Load the image with a PNMImage
image = PNMImage()
image.read(self.imgFile)
self.sizeX = image.getXSize()
self.sizeY = image.getYSize()
# We need to find the power of two size for the another PNMImage
# so that the texture thats loaded on the geometry won't have artifacts
textureSizeX = self.nextsize(self.sizeX)
textureSizeY = self.nextsize(self.sizeY)
# The actual size of the texture in memory
self.realSizeX = textureSizeX
self.realSizeY = textureSizeY
self.paddedImg = PNMImage(textureSizeX, textureSizeY)
if image.hasAlpha():
self.paddedImg.alphaFill(0)
# Copy the source image to the image we're actually using
#.........这里部分代码省略.........