当前位置: 首页>>代码示例>>Python>>正文


Python SpriteSheet.get_image方法代码示例

本文整理汇总了Python中spritesheet_functions.SpriteSheet.get_image方法的典型用法代码示例。如果您正苦于以下问题:Python SpriteSheet.get_image方法的具体用法?Python SpriteSheet.get_image怎么用?Python SpriteSheet.get_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spritesheet_functions.SpriteSheet的用法示例。


在下文中一共展示了SpriteSheet.get_image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
    def __init__(self, x, y):
        """
        Initializes the image at the given location.
        
        Args:
            x (int): the x coordinate to place the Sprite.
            y (int): the y coordinate to place the Sprite.
        """
        pygame.sprite.Sprite.__init__(self)

        #Get the ghost images from the Sprites folder
        script_dir = sys.path[0]
        image_directory = os.path.join(script_dir, 'Sprites/ghost2.bmp')
        
        # Get the 2 images for the sprite sheet. 
        sprite_sheet = SpriteSheet(image_directory)
        image = sprite_sheet.get_image(0, 0, 62, 75)
        self.__movement_frames.append(image)
        image = sprite_sheet.get_image(64 , 0, 62, 75)
        self.__movement_frames.append(image)
        
        
        # set the Player to the first sprite
        self.image = self.__movement_frames[self.__current_frame_reference]
        
        self.rect = self.image.get_rect()
        
        # Setting the location of rectangle
        self.rect.x = x
        self.rect.y = y
开发者ID:habahnow,项目名称:332L,代码行数:32,代码来源:Ghost.py

示例2: Platform

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
class Platform(pygame.sprite.Sprite):
    """
    Class for basic platforms. Uses sprite_sheet.get
    to get the appropriate sprite according to defined values above
    """
    def __init__(self, sprite_sheet_data, x, y):
        super(Platform, self).__init__()

        self.sprite_sheet = SpriteSheet(path.join(img_dir, "tiles_spritesheet.png"))
        self.image = self.sprite_sheet.get_image(sprite_sheet_data[0],
                                                 sprite_sheet_data[1],
                                                 sprite_sheet_data[2],
                                                 sprite_sheet_data[3])

        self.sprite_sheet_data = sprite_sheet_data

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        self.x_pos = x
        self.y_pos = y

    def collide(self):
        pass

    def update(self, dt):
        pass

    def set_image(self, block):
        self.image = self.sprite_sheet.get_image(block[0],
                                                 block[1],
                                                 block[2],
                                                 block[3])
开发者ID:ToBaer94,项目名称:pygame_platformer,代码行数:35,代码来源:platforms.py

示例3: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
 def __init__(self):
     super().__init__()
     #Motion variables
     self.change_x = 0
     self.change_y = 0
     self.boundary_top = 0
     self.boundary_bottom = 0
     self.boundary_left = 0
     self.boundary_right = 0
     #Level information
     self.level = None
     self.player = None
     #How fast this sprite attacks, in number of frames. 5 = every 5 frames
     self.attack_speed = 10
     #How many times updated has been called. reset to zero when it = attack speed
     self.updates = 0
     self.firing = False
     self.fired_ticks = 0
     sheet = SpriteSheet("enemy_sheet.png")
     self.frames_l = []
     self.frames_r = []
     image = sheet.get_image(0, 48, 64, 132)
     self.frames_l.append(image)
     image = sheet.get_image(68, 48, 64, 132)
     self.frames_l.append(image)
     image = pygame.transform.flip(self.frames_l[0], True, False)
     self.frames_r.append(image)
     image = pygame.transform.flip(self.frames_l[1], True, False)
     self.frames_r.append(image)
     self.direction = 'L'
     if self.direction == 'R':
         self.image = self.frames_r[0]
     if self.direction == 'L':
         self.image = self.frames_l[0]
     self.rect = self.image.get_rect()
开发者ID:tkdberger,项目名称:pygame-fun,代码行数:37,代码来源:collectables.py

示例4: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
    def __init__(self):
        super().__init__()

        sprite_sheet = SpriteSheet("spritesheet.png")
        # Grab the image for this platform
        self.image = sprite_sheet.get_image(32, 128, 32, 32)

        self.imagesAndDurations = [(sprite_sheet.get_image(32, 96, 32, 32), 0.1),
                                   (sprite_sheet.get_image(63, 96, 32, 32), 0.5)]
开发者ID:Allyrax,项目名称:Bomberman,代码行数:11,代码来源:level.py

示例5: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
	def __init__(self):
		super().__init__()
		
		sprite_sheet = SpriteSheet("slime.png")
		
		scale = 5
		
		# Load right facing images
		image = sprite_sheet.get_image(0,0,32,24, scale)
		self.r_walking_frames.append(image)
		
		image = sprite_sheet.get_image(32,0,32,24, scale)
		self.r_walking_frames.append(image)
		
		image = sprite_sheet.get_image(64,0,32,24, scale)
		self.r_walking_frames.append(image)
		
		image = sprite_sheet.get_image(96,0,32,24, scale)
		self.r_walking_frames.append(image)
		
		image = sprite_sheet.get_image(128,0,32,24, scale)
		self.r_walking_frames.append(image)
		
		# Load right facing images, then flip
		# to face left.
		image = sprite_sheet.get_image(0,0,32,24,scale)
		image = pygame.transform.flip(image, True, False)
		self.l_walking_frames.append(image)
		
		image = sprite_sheet.get_image(32,0,32,24,scale)
		image = pygame.transform.flip(image, True, False)
		self.l_walking_frames.append(image)
		
		image = sprite_sheet.get_image(64,0,32,24,scale)
		image = pygame.transform.flip(image, True, False)
		self.l_walking_frames.append(image)
		
		image = sprite_sheet.get_image(96,0,32,24,scale)
		image = pygame.transform.flip(image, True, False)
		self.l_walking_frames.append(image)
		
		image = sprite_sheet.get_image(128,0,32,24,scale)
		image = pygame.transform.flip(image, True, False)
		self.l_walking_frames.append(image)
		
		# Set the image the player starts with
		self.image = self.r_walking_frames[0]
		
		# Set rect
		self.rect = self.image.get_rect()
开发者ID:Zhulhian,项目名称:slime-arena,代码行数:52,代码来源:player.py

示例6: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
 def __init__(self, x, y, floor_locations):
     """
     Initializes the player class using a passes x and y coordinate
     
     Args:
         x (int): the horizontal location of where the sprite will appear.
         y (int): the vertical location of where the sprite will appear.
         floor_locations(list): Contains the y coordinates of the different 
             floors. This reduces the amount of hard coding necessary, and 
             is used in to set the ground for the Player at different 
             floors.
         
     Note:
         This init function is very reliant on the image mario_edited.png 
             being saved in a directory name Sprites.
             
         This function is also relies on a specific the specific sprite 
             sheet mario_edited.png in order to display the correct sprite.
     """
     pygame.sprite.Sprite.__init__(self)
     
     #get the player images from the Sprites folder
     script_dir = sys.path[0]
     image_directory = os.path.join(script_dir, 'Sprites/mario_edited.bmp')
     
     # get the four images for the sprite sheet. the first 3 images are 
     # walking animations while the last is the jumping sprite
     sprite_sheet = SpriteSheet(image_directory)
     image = sprite_sheet.get_image(0, 0, 50, 81)
     self.__movement_frames.append(image)
     image = sprite_sheet.get_image(50, 0, 50, 81)
     self.__movement_frames.append(image)
     image = sprite_sheet.get_image(107, 0, 50, 81)
     self.__movement_frames.append(image)
     image = sprite_sheet.get_image(162  , 0, 50, 81)
     self.__movement_frames.append(image)
     
     # set the Player to the first sprite
     self.image = self.__movement_frames[self.__current_frame_reference]
     
     self.rect = self.image.get_rect()
     
     #setting the location of rectangle
     self.rect.x = x
     self.rect.y = y
     
     # Set the boundaries for the floors.
     self.__floor_boundaries = floor_locations
开发者ID:habahnow,项目名称:332L,代码行数:50,代码来源:Player.py

示例7: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
    def __init__(self, sprite_sheet_data):
        """ Platform constructor. Assumes constructed with user passing in
            an array of 5 numbers like what's defined at the top of this
            code. """
        super().__init__()

        #sprite_sheet = SpriteSheet("tiles_spritesheet.png")
        sprite_sheet = SpriteSheet( \
                "images/green-hill-zone/level-fragments/27190.png")

        self.x0 = sprite_sheet_data[0];
        self.y0 = sprite_sheet_data[1];
        self.x1 = sprite_sheet_data[2];
        self.y1 = sprite_sheet_data[3];

        self.image = sprite_sheet.get_image(self.x0, \
                self.y0, self.x1-self.x0, self.y1-self.y0)

        if (len(sprite_sheet_data) > 4):
            a = sprite_sheet_data[4]
            b = sprite_sheet_data[5]
            self.image = pygame.transform.scale(self.image, (a,b))
        
        colorkey = self.image.get_at((0,0))
        self.image.set_colorkey(colorkey)

        self.rect = self.image.get_rect()
开发者ID:HaraldNordgren,项目名称:sanic-the-hedgehog,代码行数:29,代码来源:platforms.py

示例8: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
    def __init__(self):
        super(WallSprite, self).__init__()

        sprite_sheet = SpriteSheet('images/tilesets/walls.png')#3 x 4
        horiz = [0, 32, 64]
        vert= [0, 32, 64, 96]
        self.image = sprite_sheet.get_image(random.choice(horiz),random.choice(vert),32,32)
开发者ID:IanOlin,项目名称:InteractiveProgramming,代码行数:9,代码来源:level.py

示例9: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
    def __init__(self, player):
        """ Create level 1. """

        # Call the parent constructor
        Level.__init__(self, player)

        sprite_sheet = SpriteSheet("backgrounds.png")
        self.background = sprite_sheet.get_image(0, 63, 231, 63)
        self.background = pygame.transform.scale(self.background, (constants.SCREEN_WIDTH,
                                                                 constants.SCREEN_HEIGHT))
        self.background.set_colorkey(constants.WHITE)
        self.level_limit = -2500

        # Array with type of platform, and x, y location of the platform.
        level = [ [platforms.STONE_WALL, 30, 650]
                  ]

        

        # Go through the array above and add platforms
        for platform in level:
            block = platforms.Platform(platform[0])
            block.rect.x = platform[1]
            block.rect.y = platform[2]
            block.player = self.player
            self.platform_list.add(block)
开发者ID:Waveharp,项目名称:Pygame-experiments,代码行数:28,代码来源:levels.py

示例10: load_sprite

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
 def load_sprite(self):    
     # Load sword sprite
     sprite_sheet = SpriteSheet("resources/attacks/Sword_Update1.png")
     image = sprite_sheet.get_image(0, 0, 103, 32)
     self.sword_frame_r.append(image)
     image = pygame.transform.flip(image, True, False)
     self.sword_frame_l.append(image)
开发者ID:jwj9627,项目名称:platform-fighting,代码行数:9,代码来源:weapon.py

示例11: Basic_Enemy

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
class Basic_Enemy(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()

        self.change_x = 0
        self.change_y = 0
        self.frames = []

        self.level = None
        self.player = None
        self.called_times = 0
        self.sheet = SpriteSheet("platform_sheet.png")
        image = self.sheet.get_image(8, 85, 48, 48)
        self.frames.append(image)
        image = pygame.transform.flip(self.frames[0], True, False)
        self.frames.append(image)
        self.image = self.frames[0]
        self.rect = self.image.get_rect()

    def update(self):
        self.calc_grav()
        self.rect.x += self.change_x
        pos = self.rect.x + self.level.world_shift
        frame = (pos // 30) % len(self.frames)
        self.image = self.frames[frame]
        block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False)
        for block in block_hit_list:
            # If we are moving right,
            # set our right side to the left side of the item we hit
            if self.change_x > 0:
                self.rect.right = block.rect.left
                self.change_x = 1
            elif self.change_x < 0:
                # Otherwise if we are moving left, do the opposite.
                self.rect.left = block.rect.right
                self.change_x = -1
        self.rect.y += self.change_y
        # Check and see if we hit anything
        block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False)
        for block in block_hit_list:
            # Reset our position based on the top/bottom of the object.
            if self.change_y > 0:
                self.rect.bottom = block.rect.top
            elif self.change_y < 0:
                self.rect.top = block.rect.bottom
            # Stop our vertical movement
            self.change_y = 0
            if isinstance(block, platforms.MovingPlatform):
                self.rect.x += block.change_x

    def calc_grav(self):
        if self.change_y == 0:
            self.change_y = 1
        else:
            self.change_y += .35

        #see if we are on the bottom of the screen.
        if self.rect.y >= constants.SCREEN_HEIGHT - self.rect.height and self.change_y >= 0:
            self.change_y = 0
            self.rect.y = constants.SCREEN_HEIGHT - self.rect.height
开发者ID:tkdberger,项目名称:pygame-fun,代码行数:62,代码来源:collectables.py

示例12: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.walking_frames_d = [] # Images for animated walking.

        sprite_sheet = SpriteSheet("spritesheet.png")
        image = sprite_sheet.get_image(19, 0, 54, 96)
        self.walking_frames_d.append(image)

        image = sprite_sheet.get_image(169, 0, 54, 96) # Adds up by 150 everytime
        self.walking_frames_d.append(image)

        image = sprite_sheet.get_image(319, 0, 54, 96)
        self.walking_frames_d.append(image)

        image = sprite_sheet.get_image(469, 0, 54, 96)
        self.walking_frames_d.append(image)

        image = sprite_sheet.get_image(619, 0, 54, 96)
        self.walking_frames_d.append(image)

        image = sprite_sheet.get_image(769, 0, 54, 96)
        self.walking_frames_d.append(image)

        image = sprite_sheet.get_image(919, 0, 54, 96)
        self.walking_frames_d.append(image)

        self.image = self.walking_frames_d[0]
        self.rect = self.image.get_rect()
        self.rect.center = (WIDTH / 2, HEIGHT / 2)
        self.speedx = 0
        self.speedy = 0

        self.last_update = pygame.time.get_ticks()
        self.frame = 0
开发者ID:BadassBanana,项目名称:Top_Down,代码行数:36,代码来源:player.py

示例13: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
	def __init__(self, blockers):
		super(Player, self).__init__()
		# sprite processing, probably need to move this
		# to a separate module
		
		sprite_sheet = SpriteSheet("spritesheet.png")
		# Load all right facing images into a list
		image = sprite_sheet.get_image(441, 2, 17, 21)
		self.initial_r.append(image)
		image = sprite_sheet.get_image(464, 2, 16, 21)
		self.initial_r.append(image)
		image = sprite_sheet.get_image(648, 2, 16, 21)
		self.initial_r.append(image)
		image = sprite_sheet.get_image(671, 2, 16, 21)
		self.initial_r.append(image)
		
		# Load all the right facing images, then flip them
		# to face left.
		for image in self.initial_r:
			image = pg.transform.flip(image, True, False)
			self.initial_l.append(image)

		for image in self.initial_r:
			image.set_colorkey(c.SPRITESHEET_BACKGROUND)
			size = image.get_size()
			bigger_img = pg.transform.scale(image, (int(size[0]*self.factor),
														int(size[1]*self.factor)))
			self.walking_frames_r.append(bigger_img)

		for image in self.initial_l:
			image.set_colorkey(c.SPRITESHEET_BACKGROUND)
			size = image.get_size()
			bigger_img = pg.transform.scale(image, (int(size[0]*self.factor),
														int(size[1]*self.factor)))
			self.walking_frames_l.append(bigger_img)

		# set starting player image
		self.image = self.walking_frames_r[0]

		# set reference to image rect
		# spawn location:
		self.rect = self.image.get_rect(x = 200, y = 200)
		self.x_vel = 0
		self.y_vel = 0
		self.blockers = blockers
开发者ID:Waveharp,项目名称:Pygame-experiments,代码行数:47,代码来源:player.py

示例14: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
 def __init__(self, sprite_sheet_data, x=0, y=0):
     super().__init__()
     sprite_sheet = SpriteSheet("platform_sheet.png")
     # Grab the image for this platform
     self.image = sprite_sheet.get_image(sprite_sheet_data[0], sprite_sheet_data[1], sprite_sheet_data[2], sprite_sheet_data[3])
     # This platform can set its own position based on passed-in args
     self.rect = self.image.get_rect()
     self.x = x
     self.y = y
开发者ID:tkdberger,项目名称:pygame-fun,代码行数:11,代码来源:platforms.py

示例15: __init__

# 需要导入模块: from spritesheet_functions import SpriteSheet [as 别名]
# 或者: from spritesheet_functions.SpriteSheet import get_image [as 别名]
 def __init__(self, sprite_sheet_data):
   pygame.sprite.Sprite.__init__(self)
   sprite_sheet = SpriteSheet("elevator.png")
   # grab the image for the elevator
   self.image = sprite_sheet.get_image(sprite_sheet_data[0], sprite_sheet_data[1], sprite_sheet_data[2], sprite_sheet_data[3])
   self.rect = self.image.get_rect()
   self.router = ElevatorData(FLOORS)
   self.path = []
   self.wait = 0
开发者ID:jacooob,项目名称:Cs415Elevator,代码行数:11,代码来源:Building.py


注:本文中的spritesheet_functions.SpriteSheet.get_image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。