Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Colour Cycling
#1
Hi,
I got Colour Cycling to work on my background and it is great to be able to use this unique effect.
Is it possible to have Colour Cycling in sprites and if so can it be independent to the background palette?
If this is possible, could you explain how to achieve it using the Python binding.
Also, could you, or anyone for that matter post some simple sprite and other examples using the Python binding as your  python platformer WIP is a little too advanced for me.
Thank your help in advance, and for letting me post this, and possibly many more simplistic questions
Reply
#2
Yes, you can have color cycling in sprites too

The Sprite object has the get_palette() method that returns its current palette. One you have it, you can setup a color cycle animation in the same way you already do with your background layer:

Code:
palette = sprite.get_palette()
animation.set_palette_animation(palette, sequence, False)

Keep in mind that by default all sprites that share the same Spriteset, also share the same Palette, so if you setup a palette animation on a sprite, all sprites that are associated to the smae Spriteset will have the palette animation effect. If you want the animation effect on a single sprite, the you first have to clone() the palette of the sprite, assign the cloned palette to the sprite with its set_palette() method, and attach the animation effect to the cloned palette too:

Code:
palette = sprite.get_palette()

cloned_palette = palette.clone()
sprite.set_palette(cloned_palette)
animation.set_palette_animation(cloned_palette, sequence, False)

There aren't specific tutorials about many features. There are some examples and the complete API reference. So feel free to ask specific questions about how to do things if you can't find a suitable example or the documentation is not clear
Reply
#3
Hi, I got a sprite Colour Cycling (have not tried cloning it’s palette yet) but now I was wondering if one can change a sprites blend mode using set_blend_mode(mode)? Or does this only work on background pictures?
Reply
#4
Blending is supported on both backgrounds and sprites, so you can use set_blend_mode in sprites too, with the same features.
(04-28-2018, 06:08 AM)PerspexSphinx Wrote: Hi, I got a sprite Colour Cycling (have not tried cloning it’s palette yet) but now I was wondering if one can change a sprites blend mode using set_blend_mode(mode)? Or does this only work on background pictures?
Reply
#5
Hi again, sorry, I see that this is mentioned in chapter 07 of the docs, but then it says please refer to Chapter 09 - Blending, which doesn’t seem to have be written yet. But I am having trouble getting it to work, I’m afraid...

dragonSprite.set_blend_mode(0, BLEND_MIX, 0)

...I guess is not correct.
Could you just give an example of it using within the Python binding, and with different blend modes.
Reply
#6
Don't worry about posting questions, I appreciate your interest!

Short cause:
you found a bug in the python binding. I'll fix it on GitHub, meanwhile you can fix it yourself to proceed with your tests: Open tilengine.py file, and change line 1858 from

Code:
ok = _tln.TLN_SetSpriteBlendMode(self, mode)

to

Code:
ok = _tln.TLN_SetSpriteBlendMode(self, mode, 0)
(add the last , 0 parameter to the end of the call)

Long cause:
I know the documentation may be incomplete and confusing sometimes. You told that you're using Python binding, but the documentation chapters (incomplete) are for the C API, and the syntax you're using in set_blend_mode() is an invalid mix of C and Python.

Please note that the C# and Python bindings are NOT a direct 1:1 translation from the original C API. The functionality is the same, but they use features of the target languages (classes instead of plain functions, properties, etc) that are expected by C# and Python programmers. It makes difficult to maintain a consistent documentation.
The Python binding has full docstrings, and you can find online reference here:
http://www.tilengine.org/doc_python/index.html

In regard to blending modes, in Python you must call set_blend_mode() method on a Sprite or Layer instance, you access them in the sprites[] and layers[] lists inside the Engine instance. This method accepts a single parameter, the blending mode:
http://www.tilengine.org/doc_python/tile...blend_mode

It would be something like this, the blending itself is on 6th line:

Code:
import tilengine as tln
engine = tln.Engine.create(400, 240, 0, 1, 0)
engine.set_load_path("../assets/smw")
spriteset = tln.Spriteset.fromfile("smw_sprite")
engine.sprites[0].setup(spriteset)
engine.sprites[0].set_blend_mode(tln.Blend.MIX)
window = tln.Window.create()
while window.process():
    window.draw_frame()

I hope it helps!

(04-29-2018, 02:53 AM)PerspexSphinx Wrote: Hi again, sorry, I see that this is mentioned in chapter 07 of the docs, but then it says please refer to Chapter 09 - Blending, which doesn’t seem to have be written yet. But I am having trouble getting it to work, I’m afraid...

dragonSprite.set_blend_mode(0, BLEND_MIX, 0)

...I guess is not correct.
Could you just give an example of it using within the Python binding, and with different blend modes.
Reply
#7
Hi again,
changed line 1858 in tilengine.py and now call set_blend_mode() method works with the various blend modes, which is great. I was just wondering though, why for MIX, there is just set values... MIX, MIX25, MIX50 & MIX75, why can’t one just enter any amount of MIX like MIX15 or MIX45? And why couldn’t one do that for the amount of ADD, SUB or MOD or is this done with the CUSTOM mode?

Also started playing with sound... got a “wave” sound effect to work but can one use other formats?  And can one add a sound track? If so how and in what format?
Reply
#8
(05-06-2018, 03:33 AM)PerspexSphinx Wrote: I was just wondering though, why for MIX, there is just set values... MIX, MIX25, MIX50 & MIX75, why can’t one just enter any amount of MIX like MIX15 or MIX45? And why couldn’t one do that for the amount of ADD, SUB or MOD or is this done with the CUSTOM mode?
The MIXxx, ADD, SUB (etc) identifiers map to a set of precalculated look-up tables (LUTs) that encode the required math and clamping in just one memory access to speed-up rendering. Very few 2D classic systems had transparency (the SNES) and they were predefined modes. Tilengine uses this concept with some extra modes, and the CUSTOM mode where you can provide your own blending function with Engine :: set_custom_blend_function()

(05-06-2018, 03:33 AM)PerspexSphinx Wrote: Also started playing with sound... got a “wave” sound effect to work but can one use other formats?  And can one add a sound track? If so how and in what format?
Tilengine itself doesn't provide any sound capability, this is left to external libraries. If you want an open source, cross-platform and cross-language, then check out SDL and its companion SDL_Mixer that supports many formats for sound and music. This is the library I use in the python platformer example, with a python binding called PySDL2
Reply
#9
Hi again,
I have managed to use aiff, ogg for sound effects using...
sounds = Sound(number of channels, path)
sounds.load(name, file)
and
sounds.play(name, channel)
...with the python binding and was pleasantly supprised that I could use a mod from MilkyTracker v1.02 for some background music.
However I was wondering though, how do I use other SDL_mixer commands through the PySDL2 python binding?

Also a version of Tilengine with “bitmap-based background layers” sounds interesting.

If you release a version with “bitmap layers” could you also add a few more Keyboard Inputs for the python binding ie/ “SPACE”, “TAB” possidly “W,A, S,D” for people who have no Joystick or game controller pluged in? This would allow for coding “tln.Input.TAB” to switch Colour Cycling on & off (like many paint programs on the Amiga) and “tln.Input.SPACE” (Spacebar) for Jumps or Fire and “W,A,S,D” keys for another player. I’m afraid I don’t know how to do this through SDL2 & PySDL2 due to the same reason I don’t know how to use the PySDL2 python binding to add more SDL_mixer commands.
I hope this makes sense.
Reply
#10
Tilengine uses a virtual input scheme that simulates the setup of an arcade or console game: 4 directions and 6 action buttons. You can assign keys with Window.define_input_key() and gamepad buttons Window.define_input_button() 

Release 1.21 introduced the ability to get direct access to underlying SDL2 events, so you can bypass the built-in input method and react to any key or device (joystick for example) using SDL events. This feature is implemented inside the core library, but the python binding isn't yet updated to reflect this through a binding to PySDL2.

I can't help you learning PySDL2, but there are lots of resources and examples on SDL2 because it's a very used library, and PySDL2 is just a thin binding with some added features. Your best sources are the official SDL2 and PySDL2 documentation.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)