示例#1
0
 def update(self):
     self._render_texture = sf.RenderTexture(self.width, self.height)
     self._render_texture.clear(sf.Color.TRANSPARENT)
     for spr in self._glyphs_sprites:
         self._render_texture.draw(spr)
     self._render_texture.display()
     self._sprite.texture = self._render_texture.texture
示例#2
0
    def __init__(self, tiledmap, xml: ElementTree.Element):
        super().__init__()
        self.xml = xml
        self.map = tiledmap

        self.id = int(self.xml.get('id'))
        self.name = self.xml.get('name')

        color = self.xml.get('color')
        if color:
            if len(color) == 9:
                self.color = sf.Color(int(color[3:5], 16), int(color[5:7], 16),
                                      int(color[7:9], 16), int(color[1:3], 16))
            else:
                self.color = sf.Color(int(color[1:3], 16), int(color[3:5], 16),
                                      int(color[5:7], 16), 255)
        else:
            self.color = sf.Color(100, 100, 100, 160)

        self.rectangles = []
        self.points = []
        self.ellipses = []
        self.polygons = []
        self.lines = []

        self._render_texture = sf.RenderTexture(
            tiledmap.width * tiledmap.tile_width,
            tiledmap.height * tiledmap.tile_height)
        self.sprite = sf.Sprite(self._render_texture.texture)
示例#3
0
    def on_load(self):
        # create the off-screen surface
        self.surface = sf.RenderTexture(800, 600)
        self.surface.smooth = True

        # load the textures
        self.background_texture = sf.Texture.from_file("data/sfml.png")
        self.background_texture.smooth = True

        self.entity_texture = sf.Texture.from_file("data/devices.png")
        self.entity_texture.smooth = True

        # initialize the background sprite
        self.background_sprite = sf.Sprite(self.background_texture)
        self.background_sprite.position = (135, 100)

        # load the moving entities
        self.entities = []

        for i in range(6):
            sprite = sf.Sprite(self.entity_texture, (96 * i, 0, 96, 96))
            self.entities.append(sprite)

        # load the shader
        self.shader = sf.Shader.from_file(fragment="data/edge.frag")
        self.shader.set_parameter("texture")

        return True
示例#4
0
 def reset(self):
     self.render_texture = sf.RenderTexture(self.game.window.ui_view.size.x, self.game.window.ui_view.size.y)
     self.r = self.g = self.b = 0
     self.a = 255
     self.blend_mode = sf.BLEND_NONE
     self.shapes = []
     self.sprite = sf.Sprite(self.render_texture.texture)
     self.ended = False
     self.started = False
示例#5
0
 def __init__(self, text: str, font: BitmapFont = None):
     super().__init__()
     self._font: Optional[BitmapFont] = None
     self._text = text
     self._render_texture = sf.RenderTexture(1, 1)
     self._sprite = sf.Sprite(self._render_texture.texture)
     self._glyphs_sprites = []
     if font is not None:
         self.font = font
     self.position = (0, 0)
示例#6
0
文件: view.py 项目: ltouroumov/yarl
    def build(self, registry):
        self.render = sf.RenderTexture(self.size.x * self.order,
                                       self.size.y * self.order)
        self.render.clear()

        for name, block in registry.blocks.items():
            print("Registering icons for %s" % name)
            block.register_icons(self)

        self.render.display()
        self.texture = self.render.texture
示例#7
0
文件: layers.py 项目: Madour/pyNasNas
 def update(self):
     self.render_texture.clear(self.fill_color)
     temp_texture = sf.RenderTexture(self.render_texture.size.x,
                                     self.render_texture.size.y)
     temp_texture.clear(self.fill_color)
     for drawable in self._drawables:
         temp_texture.draw(drawable, sf.RenderStates(sf.BLEND_MULTIPLY))
     temp_texture.display()
     self.render_texture.draw(sf.Sprite(temp_texture.texture),
                              sf.RenderStates(sf.BLEND_MULTIPLY))
     self.render_texture.display()
     self.sprite = sf.Sprite(self.render_texture.texture)
示例#8
0
 def __init__(self):
     if self.__class__.__name__ == __class__.__name__:
         raise NotImplementedError("Transition class is not instantiable. Please use inheritance to create a Transition.")
     super().__init__()
     self.render_texture = sf.RenderTexture(self.game.window.ui_view.size.x, self.game.window.ui_view.size.y)
     self.r = self.g = self.b = 0
     self.a = 255
     self.blend_mode = sf.BLEND_NONE
     self.shapes = []
     self.sprite = sf.Sprite(self.render_texture.texture)
     self.ended = False
     self.started = False
示例#9
0
文件: layers.py 项目: Madour/pyNasNas
 def __init__(self, name: str, width: int, height: int,
              fill_color: sf.Color, *args: sf.Drawable):
     super().__init__()
     self.name = name
     self.fill_color = fill_color
     self.render_texture = sf.RenderTexture(width, height)
     self.sprite = sf.Sprite(self.render_texture.texture)
     self._drawables = []
     for arg in args:
         if isinstance(arg, sf.Drawable):
             self._drawables.append(arg)
         else:
             raise TypeError("Mask can only contain Drawables.")
示例#10
0
 def __init__(self, x=0, y=0, sizex=32, sizey=32, text=""):
     """
     Create a EditBox object.
     Parameters:
         x (int) : position of left corner
         y (int) : position of upper corner
         sizex (int) : width of EditBox
         sizey (int) : height of EditBox
         text (str) : text in button
     """
     super().__init__(text, x, y)
     self.__canvas = sf.RenderTexture(sizex, sizey)
     self.__sprite = 0
     self._text.position = (5, 0)
示例#11
0
    def __init__(self,
                 text: str,
                 style: ButtonStyle = ButtonStyle(),
                 position: Union[Tuple[float, float], sf.Vector2] = (0, 0)):
        super().__init__()
        self._text = text
        self._position = to_Vector2(position)
        self._style = style
        self._render_texture = sf.RenderTexture(self._style.width,
                                                self._style.height)
        self.anim_player = AnimPlayer(self._style.anim)
        self._hovered = False

        self._create()
示例#12
0
    def __init__(self, tiledmap, xml: ElementTree.Element):
        super().__init__()
        self.xml = xml
        self.map = tiledmap

        self.id: int = int(self.xml.get('id'))
        self.name: str = self.xml.get('name')
        self.width: int = int(self.xml.get('width'))
        self.height: int = int(self.xml.get('height'))
        self.visible: bool = not bool(self.xml.get('visible'))

        self.tiles: List[List[Optional[Tile]]] = []
        self.properties: Dict[str, Union[int, float, str, bool, sf.Color]] = {}
        self.animated_tiles: Dict[tuple, Tile] = {}

        self.render_texture: sf.RenderTexture = sf.RenderTexture(
            self.width * self.map.tile_width,
            self.height * self.map.tile_height)
        self.sprite: sf.Sprite = sf.Sprite(self.render_texture.texture)
示例#13
0
 def __init__(self, controller, mode=sf.VideoMode(800, 800), bg=sf.Color.WHITE, algorithm=line_filling):
     self._state = self.PENCIL_STATE
     self._interface = FillApplicationInterface(controller)
     self._bg = bg
     self._mode = mode
     self._algorithm = algorithm
     self._draw_color = sf.Color.GREEN
     self._draw_area = sf.RenderTexture(mode.width, mode.height)
     self._dynamic_screen_objects = []
     self._draw_area.clear(self._bg)
     self._draw_scope = {}
     self._draw_states = {
         self.PENCIL_STATE: self._pencil_handler,
         self.FILL_STATE: self._fill_handler,
         self.CIRCLE_STATE: self._circle_handler,
         self.RECTANGLE_STATE: self._rectangle_handler,
         self.POLYGONAL_STATE: self._polygonal_handler,
         self.ERASER_STATE: self._eraser_handler
     }
示例#14
0
文件: styles.py 项目: Madour/pyNasNas
    def generate_texture(self, width: int, height: int) -> sf.Texture:
        w = width // self._tile_size.x * self._tile_size.x
        h = height // self._tile_size.y * self._tile_size.y
        if (w, h) in self._render_textures:
            return self._render_textures[(w, h)].texture

        self.corners['top_left'].position = (0, 0)
        self.corners['top_right'].position = (w - self._tile_size.x, 0)
        self.corners['bot_left'].position = (0, h - self._tile_size.y)
        self.corners['bot_right'].position = (w - self._tile_size.x,
                                              h - self._tile_size.y)

        horizontal_size = (
            (w - 2 * self._tile_size.x) // self._tile_size.x) * 4
        vertical_size = ((h - 2 * self._tile_size.y) // self._tile_size.y) * 4
        fill_size = (((w - 2 * self._tile_size.x) // self._tile_size.x) *
                     (h - 2 * self._tile_size.y) // self._tile_size.y) * 4
        sizes = {
            'top': horizontal_size,
            'right': vertical_size,
            'bot': horizontal_size,
            'left': vertical_size,
            'center': fill_size
        }
        offset = {
            'top': sf.Vector2(self._tile_size.x, 0),
            'right': sf.Vector2(w - self._tile_size.x, self._tile_size.y),
            'bot': sf.Vector2(self._tile_size.x, h - self._tile_size.y),
            'left': sf.Vector2(0, self._tile_size.y),
            'center': self._tile_size,
        }
        increment = {
            'top': sf.Vector2(self._tile_size.x / 4, 0),
            'right': sf.Vector2(0, self._tile_size.y / 4),
            'bot': sf.Vector2(self._tile_size.x / 4, 0),
            'left': sf.Vector2(0, self._tile_size.y / 4),
            'center': sf.Vector2(self._tile_size.x / 4, self._tile_size.y / 4)
        }

        vertices = []

        for side in self.tex_coords:
            vert = sf.VertexArray(sf.PrimitiveType.QUADS)
            vert.resize(sizes[side])
            for i in range(0, sizes[side], 4):
                for j in range(4):
                    vert[i + j].tex_coords = self.tex_coords[side][j]
                    if side == 'center':
                        center_offset = sf.Vector2(
                            (increment[side].x * i) %
                            (w - 2 * self._tile_size.x),
                            (increment[side].y * i) //
                            (w - 2 * self._tile_size.x) * self._tile_size.y)
                        vert[i + j].position = self.vertex_pos[j] + offset[
                            side] + center_offset
                    else:
                        vert[i + j].position = self.vertex_pos[j] + offset[
                            side] + increment[side] * i
            vertices.append(vert)

        render_texture = sf.RenderTexture(w, h)
        render_texture.clear(sf.Color.TRANSPARENT)

        render_texture.draw(self.corners['top_left'])
        render_texture.draw(self.corners['top_right'])
        render_texture.draw(self.corners['bot_left'])
        render_texture.draw(self.corners['bot_right'])

        for vert in vertices:
            render_texture.draw(vert, sf.RenderStates(texture=self._texture))
        render_texture.display()

        self._render_textures[(w, h)] = render_texture
        return render_texture.texture
示例#15
0
 def __init__(self, width: int, height: int):
     super().__init__()
     self.render_texture: sf.RenderTexture = sf.RenderTexture(width, height)
     self.sprite: sf.Sprite = sf.Sprite(self.render_texture.texture)
     self.layers: Dict[int, layers.Layer] = {}
     self.masks: Dict[int, layers.Mask] = {}