Help: Code to flip Views

Started by accidentalrebel, Mon 23/05/2011 00:11:06

Previous topic - Next topic

accidentalrebel

Hi guys,

Under the appearance section of a view item, there is one that says "Flipped", in which you could toggle to true of false. This option flips the view image.

What I would like to know is how can I do this through my scripts? I'm trying to flip a view depending on a situation. I tried looking at the manual but coudn't find the answer.

I'm thinking it would be something like:
vPlayer.Flipped = false; ?

Can anybody help?

Thanks!

Khris

It's Viewframe.Flipped, you can not change it during the game though.

You have to resort to
a) creating a flipped view in the editor and switching the view
b) reading Viewframe.Graphic, drawing that to a DynamicSprite, flip it, then assign it back to .Graphic.

accidentalrebel

Thank you for reply.

I already did option a but might change it to option b in the future. I still haven't looked into DynamicSprites yet. I feel that it is too advanced for me to tackle at my current level.

Again, thanks!

monkey0506

The actual code is pretty simple:

Code: ags
ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(frame.Graphic);
sprite.Flip(eFlipLeftToRight);
frame.Graphic = sprite.Graphic;


The pitfall of that method though is that you then have to keep a DynamicSprite pointer valid (one for every frame you want to flip) for as long as you want the frame to remain flipped. DynamicSprites don't necessarily consume more memory than other sprites at run-time (AFAIK), but the reason you have to be careful with them is because if there are no pointers for a given DynamicSprite, AGS's garbage collection will delete the sprite from memory. Then, if you try to display a deleted sprite, you'll run into problems.

Besides, it's simpler to just have a separate view. I think that the Flipped property could potentially be made writable so long as it was made clear that it would not immediately effect any currently displayed frames, and would only be applied the next time the frame was displayed.

SMF spam blocked by CleanTalk