Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Adding PNG to Object

Hey everyone,

Just coding a game at the moment and was wondering how I would add a png to this object I have created:

cars = []
car_count = 2
for i in range(car_count):
x = random.randrange(0, 340)
car = Car(x, random.randrange(-150, -50), 0, random.randint(5, 10), 60, 60, CAR_COLOR)
cars.append(car)

For example instead of it just showing up as a box how would I be able to make it show up as a png image of my own choice. Thank you :)
Is this for Pygame? I think more information is needed before we can help you.
Need a bot scripted? PM me
(May 9, 2018 12:33 PM)Raphant Wrote:  Is this for Pygame? I think more information is needed before we can help you.

Yes this is for pygame, Python3 , what other information would you require? :) p.s thanks for taking the time to reply and help out
Well to insert the car without a class would be something like:

Code
# initialize display
game_display = pygame.display.set_mode((display_width, display_height))

# create car image
carImg = pygame.image.load('images/racecar.png')

# add car image to game
game_display.blit(carImg, (x, y))

So with a car class:
Code
# pseudo-code
game_display.blit(car.image, (car.x, car.y))
I have only dealt with custom classes in PyGame minimally, so that is as much as I can help.
Need a bot scripted? PM me
(May 9, 2018 01:06 PM)Raphant Wrote:  Well to insert the car without a class would be something like:

Code
# initialize display
game_display = pygame.display.set_mode((display_width, display_height))

# create car image
carImg = pygame.image.load('images/racecar.png')

# add car image to game
game_display.blit(carImg, (x, y))

So with a car class:
Code
# pseudo-code
game_display.blit(car.image, (car.x, car.y))
I have only dealt with custom classes in PyGame minimally, so that is as much as I can help.

Thank you so much for your reply, Ill have a mess around with your feedback and will see if I can get something working :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Anon ScripterFeb 3, 2019 06:02 PM 10 325 Feb 3, 2019 06:02 PM
Last Post: gigajew
[Java] by deadsh0tJan 10, 2019 07:30 AM 2 171 Jan 10, 2019 07:30 AM
Last Post: deadsh0t
[C#] by NarwinSep 19, 2018 03:34 AM 4 277 Sep 19, 2018 03:34 AM
Last Post: lovnee