Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 234 235 [236] 237 238 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 883297 times)

Fayrik

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3525 on: November 19, 2012, 09:46:37 pm »

So I've just spent several days programming my (C#) project to use SDLDotNet to render sprites in a way I'm hoping will be cross platform compatible. Unfortunately however, I've hit a snag. I can't find functionality to change a sprite's base colour in the SDLDotNet documentation... Or on google. Or anywhere! And now I have a program that's rendering an identical bunch of white sprites everywhere!
And, as a footnote, I have actually written the code to change a sprite's colour myself. The issue is the fact that code is so very slow, as it has to recolour each pixel one by one. Not nice when put up against 32x32 sprites then placed in an array of many many sprites.

If anyone's got experience with SDLDotNet, or even just SDL, then I'd love to hear what I can do with this problem.
And everyone else, well, you're more than welcome to laugh at my terrible predicament.
Logged
So THIS is how migrations start.
"Hey, dude, there's this crazy bastard digging in the ground for stuff. Let's go watch."

Berserker

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3526 on: November 20, 2012, 02:24:40 am »

Make a new surface, fill it with desired color, make it transparent and put it on the sprite with Blit. I've never used SDLDotNet, but after looking at the docs, I think you can do it with something like this:
Code: [Select]
Surface overlay = new Surface(32,32);
overlay.Fill(color);
overlay.AlphaBlending = true;
overlay.Alpha = 128;

sprite.Blit(overlay, new Point(0,0));
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3527 on: November 20, 2012, 06:52:47 am »

How do assign classes/variables in a loop using Python?
I tried doing this:
Code: [Select]
for i in range(100):
     'id' + str(i) = person()
But instead of
Code: [Select]
id1 = person() that, obviously,  does
Code: [Select]
'id1' = person()
Logged

mendonca

  • Bay Watcher
  • [CLIVE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3528 on: November 20, 2012, 07:11:44 am »

Could you do it by putting those id's as indexes in a dictionary?

Code: [Select]
dictionary = {}

for i in range(100):
    index = 'id' + str(i)
    dictionary[index] = person()

Then refer back to the dictionary?
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3529 on: November 20, 2012, 07:15:40 am »

Dutchling, what you want to use is a collection of some sort. Would you like a quick lesson, or are you good to find something on your own. A list is the most primitive collection in Python I think, as its arrays are weird.

Berserker

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3530 on: November 20, 2012, 10:00:08 am »

Dictionary or a list would be a good way to do that like mendonca and Max said, but if you want variables for some reason, you could do this:

Code: [Select]
for i in range(100):
    globals()['id' + str(i)] = person()

now you have global variables from id0 to id99 that contain persons. You could use locals() instead of globals(), but modifying local variables like that is not a good idea according to Python documentation.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3531 on: November 20, 2012, 10:09:02 am »

Python can just do that?
Creepy mutant scripting language...

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3532 on: November 20, 2012, 11:19:41 am »

Thank all!

Python can just do that?
Creepy mutant scripting language...

Be afraid, be very afraid!

edit: I can call classes / names that way too :3. Awesome, Berserker!
« Last Edit: November 20, 2012, 11:40:07 am by Dutchling »
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3533 on: November 20, 2012, 12:15:42 pm »

I dont what the what what is wrong with cmath.

cos(Angle) works just fine.
sin(Angle) does not work.

cos(Angle*PI/180) does not work.
sin(Angle*PI/180) works just fine.

What does it want from me?!
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3534 on: November 20, 2012, 12:30:08 pm »

Could you provide some sample input/output detailing the problem?
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3535 on: November 20, 2012, 12:43:32 pm »

Ah, nevermind.

Seems I was expecting the wrong result, and multiplying only the cos with something.
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3536 on: November 20, 2012, 03:58:48 pm »

Python can just do that?
Creepy mutant scripting language...

It's coming for you!

Fayrik

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3537 on: November 20, 2012, 07:47:09 pm »

Make a new surface, fill it with desired color, make it transparent and put it on the sprite with Blit. I've never used SDLDotNet, but after looking at the docs, I think you can do it with something like this:
Code: [Select]
Surface overlay = new Surface(32,32);
overlay.Fill(color);
overlay.AlphaBlending = true;
overlay.Alpha = 128;

sprite.Blit(overlay, new Point(0,0));
Well, it nearly worked. Unfortunately it's destroyed Sprite's transparency layer, and despite a few of what I thought were clever workarounds, I've still not found a way to return it.
Oh. And now the render loop is leaking memory, despite both overlay and sprite having their dispose methods used appropriately.
I'm starting to worry about SDL now. Just a little.
Logged
So THIS is how migrations start.
"Hey, dude, there's this crazy bastard digging in the ground for stuff. Let's go watch."

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3538 on: November 22, 2012, 06:11:39 pm »

Are global variables only global in the module in which they were created?

edit: Apparently the answer is yes. This is quite unfortunate.
I do wonder though, why are global variables so bad, if they aren't actually global?
« Last Edit: November 22, 2012, 06:25:32 pm by Dutchling »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3539 on: November 22, 2012, 06:27:47 pm »

The better question is why they're global if they aren't global.
Pages: 1 ... 234 235 [236] 237 238 ... 796