How ground rotated but hero and backdrop not ( like in this game)


(icemedia) #1

Hi There,

I searched topics about this kind of rotation/collision but didn’t find good answer, so please could anyone here advise how this be achieved like in this game ?

http://www.mostfungames.com/climbo.htm

we can see ground rotated but hero and backdrop not, however collision works fine:

setp1: hero is moving left to the edge of the ground:


step 2: if hero move more leftwards, will cause ground turn 90 degree clock wise like below so it can go on walking.


(Martí Angelats i Ribera) #2

You can use a trick becouse it is OOP.

In the World class (the one you want this) you can do this:

[embed (source ...)]
private const BG:Class;

private var bg:BitmapData;
private var background:BitmapData;
private var matrix:Matrix;

public function myWorld()
{
	bg = FP.getBitmap(BG);
	var s:uint = Math.sqrt(bg.width*bg.width + bg.height*bg.height);
	background = new BitmapData(s, s, true, 0);
	matrix = new Matrix();
	
	//create the backdrop this way and use it for anything you want
	//new Backdrop(background, true, false);
	
	setBGRotation(0);
}
public function setBGRotation(angle:Number):void //the angle is in Radiants
{
	matrix.identity();
	matrix.rotate(angle);
	background.fillRect(background.rect, 0);
	background.draw(bg, matrix);
}

It works based that background is the BitmapData that the Backdrop uses when rendering. Becouse if an instance of the same object, if you modify it, you will also modify the other.


(icemedia) #3

Thank you, I tried your code but seems it only rotate image. it seems in that game it rotate image as well as hitbox. are there anyway that hitbox/pixelmask can bind to image so they can always rotate together ?


(Martí Angelats i Ribera) #4

Hmm… so you actually use the backdrop mask? You can rotate everything except the player but i think it’s better to do this:

  1. Set a custom BitmapData wich is a square its size is the biggest value between width and heigh of the screen.
  2. Change the render function of the world so the target is your is your Bitmap.
  3. Draw that bitmap to the screen using draw (aplying the rotation using a matrix).

(icemedia) #5

thanks but will hitbox be rotated this way?

you can see in that game, real background is not moved/rotated , player not moved/rotated, only ground moved/rotated and no matter how ground rotated, player still stand on right place(ground is not just rectangle ), means hitbox still works. I thought it be simple to do with flashpunk but seems not~~ :slight_smile:


(Martí Angelats i Ribera) #6

You basically don’t rotate anything (well, only the player). What you are making is like a camera and you are rotation it. Then you make that camera be relative to the player so you rotate it with him.

It is a visual effect. You rotate the entire world and cordinate system, if you understand it better this way.


(icemedia) #7

Oh!!! I suddenly understand what you mean, that should be the solution, will try. thanks a lot.