Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How can i rotate the view?

Author
Message
Brny
9
Years of Service
User Offline
Joined: 12th Oct 2015
Location:
Posted: 11th Jan 2016 16:48
Hi, so... now i have my game, is a 2D top-down, and i have the camera fixed on the player, now the challenge is to make that when the player turns to left or right, the camera/view rotates with the player (on the Z axis, as it should be)...

Something like rotatecameraglobalZ (1, 90) supposing that the player turns 90ª to the right, but i think that command is for the physical camera of the device, not for the screen.

Also setorientationallowed is not what i want.

Since i made a somewhat big map with things and you will be able to play along with another players on the same map, i cannot use the resource of just moving all the sprites on the screen but the player.... it would be a titanic work...


¿how can i do that, to easely rotate the view?


Thanks...
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Jan 2016 17:16
The easiest way is to draw everything to a Render Image, and display the Render Image on the screen with a Sprite. Then, all you have to do is rotate one sprite. In basic Form it looks like this....

+ Create a Render Image
+ Create a Display Sprite
+ Set Render Image as Sprite Texture
---
Loop:
+ Render To Image
+ Draw Everything
+ Render To Screen
+ Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 11th Jan 2016 18:32
Yep, there is no 2D rotation command yet

You could set it up using the 3 D commands.
Brny
9
Years of Service
User Offline
Joined: 12th Oct 2015
Location:
Posted: 11th Jan 2016 19:59 Edited at: 11th Jan 2016 20:20
Hello BatVink, there's only one problem... that i have sprites with collisions (houses)...


EDIT ---> Now i thinked, then i can re-write the collisions on the render.... mmmmm................


//Ok, i'll try the 3D commands then....

It could be possible to have the 2d rotation command....?

Thanks!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Jan 2016 20:27
Rendering to an image doesn't affect collisions, as far as I know.
The tricky part is that the Render Image is always square, so you have to do some calculations to stretch the screen in one direction.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 12th Jan 2016 13:53
Using render image is a pain. Works fine on windows but can be a mess on Android (and possible other formats). You can get it to work but might not be full resolution and you eat up extra fillrate by first rendering and then drawing the rendered image to the screen. I too wish there was a rotate view command.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Jan 2016 14:05
Quote: "I too wish there was a rotate view command."
Me too. It's been on my wish list for ages. We can zoom (setviewzoom) and scroll (setviewoffset) but can't rotate.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Jan 2016 14:56 Edited at: 12th Jan 2016 15:06
hmm, u need to transform/rotate the new position around a axis (position) and set the new angle of all sprites.
means first move that the axis is 0,0 rotate it and push it back.
https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm

should be this for rotate a point
xnew = x*cos(q) - y*sin(q)
ynew = x*sin(q) + y*cos(q)
znew = z
AGK (Steam) V2.0.16 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Jan 2016 15:03 Edited at: 12th Jan 2016 15:26
Quote: "hmm, u need to transform/rotate the new position around a axis (position) and set the new angle of all sprites."
Yeah, it's possible to do it yourself by repositioning and rotating every sprite, but a simple "SetViewAngle" command would be SWEET!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Jan 2016 15:08
@CJB
agree, me wrote a direct solution until paul include this
AGK (Steam) V2.0.16 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Jan 2016 17:20
I suppose you *could* use all that math, making all sorts of calculations and what not. I find it easier to just let AppGameKit do the heavy lifting for me. Now I don't know what your 2D game looks like, but if it's a tilemap you're rotating, then set the sprite's offset according to where it lies from the middle coords of the screen. Subtracting its position from the center of the screen to find each tile's offset. For instance, a tile at [3,2] at 32px in size would normally be positioned at [96,64] in the world. So set it's offset; [320-96, 240-64] (assuming a 640x480 resolution) Then rotating is a simple matter of rotating every sprite by the same amount with no re-positioning needed. Same principle for scrolling the map, just position every tile by the same offset values. Since technically every sprite is positioned at the same coordinates, the center of the screen, they're just offset from the center.

Quick demo, easier to see than explain. The only somewhat complicated part is where I commented // update new rows. When scrolling your map, this is where you determine which outer row or column needs updated with new tiles. Unless you don't want to use the viewport method and just display the entire map, then you don't even need to worry about this at all.



"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Attachments

Login to view attachments
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Jan 2016 10:50 Edited at: 13th Jan 2016 10:50
Great example Phaelax! Thanks for sharing
V2 T1 (Mostly)
Phone Tap!
Uzmadesign

Login to post a reply

Server time is: 2024-11-17 02:39:15
Your offset time is: 2024-11-17 02:39:15