[Fun] Rotate / Scale the entire game

Hectate

  • *
  • Posts: 4643
As an extension most likely.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Jon

  • *
  • Posts: 17524
If someone figures out a convincing solution, I can add it in the core block set, likely Scene > View. For sure, this is interesting to use for zoom in/out effects and for games that use a rotation mechanic. Something like a game where you hit switches, it rotates the whole stage 90 degrees are fairly practical.

caimomile

  • Posts: 199
how do you use this?

i've only been working with normal blocks. do you use custom blocks to use this? or do you go into code mode?

saulochina

  • Posts: 214
what you mean by a convincing solution? are you still willing to put that feature as a block?

i think you could put this block under scene/view/effects

and could be just like the turn actor block "turn [cw/ccw] scene by [field] degrees"

i dont know if rotate the scene around something beyond the center of the scene is required. but if that is the case maybe a "turn around [actor]" block can do the trick, you can place this block and the scene will use the actor as a pinpoint. If you not use the block it will rotate around its center.

i have a lot of ideas on how to use this, but i just dont know how to use code directly... will be great if you implement that, but i know that there's a lot of work on other areas.

tks anyway, and keep up the good work  ;)
Finding the fun!
Squib Wars. Now complete, and avaible for free on App Store! http://bit.ly/LxJ62L
https://www.facebook.com/twoheadedgames
Twitter: @saulochina
MSN: sauloj.china@hotmail.com

bigleaphr

  • Posts: 188
I see a use where it could be used for pinch to zoom. By say x% zoom in and reset on zoom out. Drag n Drop when zoomed.

Even i cnt code this myself. I run away from any type of code  :D

Jon

  • *
  • Posts: 17524
saulochina: I'm leaving this as a community-driven exercise. If someone figures out a good implementation, I'm happy to make it official blocks.

scubapk01

  • Posts: 38
Just wondering if anyone has made any progress on the zoom and rotate functions?

Dom818

  • *
  • Posts: 1292
If somebody can give me the code that you would put in a code block for these, I will make them into blocks. For some reason, I am failing to get these to work...

P01

  • Posts: 155
To anyone else who gets lost when code comes up, I've gotten scaling to work through this method dependably.

Say you want to zoom out your game to 50% scale. You can accomplish this using 2 code blocks, one in a "when created" event within the behavior responsible for zooming, and another to be used where ever the zooming will be triggered (ex. in a "when touched" event)

In the when created event, you'll define two variables that are rectangles. These control how much of the screen is shown at once. The first variable (which I've called _ScaleStandard) is the default size, and the second (which I've called _ScaleSmall) is bigger to accommodate the smaller game scale. You can copy and paste this into a code block.
Code: [Select]
var _ScaleStandard = new nme.geom.Rectangle(0, 0, (scripts.MyAssets.stageWidth * Engine.SCALE), (scripts.MyAssets.stageHeight * Engine.SCALE));
var _ScaleSmall = new nme.geom.Rectangle(0, 0, ((scripts.MyAssets.stageWidth * Engine.SCALE) * 2), ((scripts.MyAssets.stageHeight * Engine.SCALE) * 2));
NOTE: Multiplying stageWidth/stageHeight by Engine.SCALE makes scaling work on different devices with different resolutions. If you don't multiply by Engine.SCALE, this zooming method will not work on iPhone 4/S/5 or new iPads.

Now you can use those two rectangles in the code block used to zoom the game. Say you want the game to zoom in when the player touches the screen. Create a when mouse is pressed event or an always event which acts as a switch to determine if the game should zoom. In that event, place a code block like this:
Code: [Select]
Engine.engine.root.scrollRect = _ScaleSmall;
Engine.engine.root.scaleX = 0.5;
Engine.engine.root.scaleY = 0.5;
Engine.screenScaleX = 0.5;
Engine.screenScaleY = 0.5;
Engine.screenWidth = (2 times whatever your screen width is, for example, the screen width of an iPhone in landscape is normally 480, so put 960);
Engine.screenHeight = (2 x screen height);
This block will shrink all graphics on screen to 50% scale. The screenScaleX and screenScaleY lines are necessary to update things like mouse coordinates to the new scale. Updating the screenWidth and screenHeight makes it so that the tileset is not clipped inappropriately. The dimensions are doubled because when you shrink everything by 50%, twice as much stuff can fit on the screen.

Whenever you want to return the game back to standard scale, use this block:
Code: [Select]
Engine.engine.root.scrollRect = _ScaleStandard;
Engine.engine.root.scaleX = 1.0;
Engine.engine.root.scaleY = 1.0;
Engine.screenScaleX = 1.0;
Engine.screenScaleY = 1.0;
Engine.screenWidth = (whatever the screen width is);
Engine.screenHeight = (whatever the screen height is);

You can modify these blocks to zoom at any scale, not just 50%. Replacing the scaleX/Y and screenScaleX/Y values with 2 and reducing screenWidth/Height to 1/2 will zoom in to 200%, etc.

Hope this helps. One issue I haven't yet been able to resolve is scaling backgrounds to match the zoom amount. If anyone else knows how that can be accomplished please post the solution.

« Last Edit: December 04, 2012, 02:03:51 pm by P01 »

coleislazy

  • *
  • Posts: 2607
Nice work! I took the liberty of expanding on this and wrapping it into a behavior. I also figured out how to expand a color background to fill out the screen when zoomed, though I could only test it on Flash.

The behavior is on StencylForge, as well as attached here.

P01

  • Posts: 155
Thanks cole, the background scaling works perfectly! However, to get them to scale appropriately on my iPhone/iPad, I had to replace all Engine.screenWidth/Height to (Engine.screenWidth/Height * Engine.SCALE).

In the Forge description you said the background scaling doesn't work with gradient backgrounds, but it seems to work as expected for me.

Dom818

  • *
  • Posts: 1292
I've got a rotation block working. Only thing is is that it always rotates about the point 0,0. Does anybody know any way to adjust that?

zawrot13

  • Posts: 783
I used The scaling in my game and it works OK. I also saw 2 problems:

1. After I create an actor and anchor him to the screen and If I use the zoom, the actor cannot keep his posstion even If the coordinaties used the screewidth block. THe same works perfect If I use DRAW.

2. THe zoom behavior cannot recognize x2 game scale. After run the game, scene in x2 works good and If I use the zoom, it automatically jumps to x1 but the whole graphics stay in x.

Do You know the solution (specsially for second problem) ?


zawrot13

  • Posts: 783
I forgot about last issue. Do You know how to stop some actors to stay away from the zoom efect?
It is important for the menu icons and score etc.

zawrot13

  • Posts: 783
I made the tests on android and If the sclale game is not x1 and If the game resolution and obiects are not imported as x1, the same error appeares.

My game has resolution 400x240 and everything is imported as x2 (actors, backgrounds).

It is a little bit strange because on the phone the game has automatically 800x480 if I compile this one as x1. On the desktop has thru 400x240 (only here zoom works well).

So, on the mobile x1 it looks like it happens the same as on the desktop x2 ( the resolution of game shrink 2 times after I used the zoom.

« Last Edit: January 14, 2013, 04:58:42 am by zawrot13 »