Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Rotating the view around the center of the screen — Gideros Forum

Rotating the view around the center of the screen

KarrizKarriz Member
edited June 2013 in General questions
Hi, I'm trying to find a good way to rotate the screen around it's center, no matter where in the stage it's focused.
The screen follows the player character "ball", as I followed this tutorial:

http://appcodingeasy.com/Gideros-Mobile/Gideros-Camera-Move

Now, I tried to implement the camera rotating feature like this:
self:setRotation(-self.ball:getRotation())

Which does work fine, but the axis of the rotation is obviously not in the center of screen. I tried to set the anchorpoint to "self", but that gives me an error:main.lua:275: attempt to call method 'setAnchorPoint' (a nil value).

What would be the best way to implement this?

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited June 2013 Accepted Answer
    Hello @Karriz

    You can try downloading GiderosCodingEasy from here: https://github.com/ar2rsawseen/GiderosCodingEasy

    include init.lua and GiderosCodingEasy.lua in your project, and exclude GiderosCodingEasy.lua from execution, by right clicking on it and selecting Exclude from Execution.

    Now you will be able to use anchorpoints on any Sprite and Sprite inherited element.

    So go to function scene:onEnterFrame() in Camera Move example project and comment the lines, that set the offset there, because you will need to set your own values
    --apply offset so scene
    --self:setX(offsetX)
     
    --apply offset so scene
    --self:setY(offsetY)
    Now set the anchopoint to balls position like this:
    self:setAnchorPoint(math.abs(self.ball:getX()/self.worldW), math.abs(self.ball:getY()/self.worldH))
    Since we want the ball to be in the middle, it makes sense to set X and Y offset as half of the screens like
    self:setPosition(screenW/2, screenH/2)
    And the last part is your code to rotate the screen accordingly to ball:
    self:setRotation(-self.ball:getRotation())
    And tada :)

    I've attached the modified example project here ;)

    P.S just don't look too long on the example, it'll make you feel dizzy :)
    zip
    zip
    Box2D_camera_move_mod.zip
    51K

    Likes: Karriz

    +1 -1 (+1 / -0 )Share on Facebook
  • KarrizKarriz Member
    Thanks! I'll take a look into it.
  • I had a quick go with it, but didn't run 'stand alone'. Do I need to add other files/libraries/classes to this project?
  • ar2rsawseenar2rsawseen Maintainer
    @loucsam it should run as it is, what error do you get?
  • KarrizKarriz Member
    Now there's a weird issue: when an object moves slowly, it may stop for a while, as if no force is acting upon it. Movement speed changes in intervals and not smoothly.

    This doesn't seem to happen in the example you added, only in my project, but it has more stuff in it so maybe it's a performance issue? Could changing the self.world:step values help?
  • I haven't had a chance to get back to it yet.

    I don't suppose it would be an issue with using 2012.09.9 ?
Sign In or Register to comment.