Scale units in RUBE

General discussion about the R.U.B.E editor
Post Reply
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Scale units in RUBE

Post by Eddy8555 »

I'm not sure I understand the scale units, a.k.a. PTM_RATIO in RUBE. iforce, could you please clarify it?

The specific reason I'm asking is that I implemented a scrolling mechanism based on the movement of one body, and took into account the PTM_RATIO basically at every step. But now, when moving into the RUBEScene paradigm I'm not sure how to resolve this.

The scrolling I'm doing in my previous layer goes like this:

In tick:

Code: Select all

    if(traveler != NULL) { // traveler is the body that, when moving, the layer scrolls with it
        [self setScrollingPoint:traveler->GetPosition()];
        [self setPosition:CGPointMake(difference.x*PTM_RATIO, difference.y*PTM_RATIO)];
    }
The setScrollingPoint method:

Code: Select all

- (void) setScrollingPoint:(b2Vec2)vec {
    CGSize screen = [[CCDirector sharedDirector] winSize];       
    float x = vec.x * PTM_RATIO; 
    float y = vec.y * PTM_RATIO;
    
    CGPoint goodPoint = ccp(x,y);
    CGPoint centerOfScreen = ccp(screen.width/2, screen.height/2);
    CGPoint diff = ccpSub(centerOfScreen, goodPoint);
    
    difference = CGPointMake(diff.x/*/PTM_RATIO*/, 0); // difference is an instance variable, used for offsetting the background position, and the mouseJoint target. 
}
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Scale units in RUBE

Post by iforce2d »

RUBE doesn't really have any notion of pixels, or a PTM ratio. The scale works on the vertical height of an image, and a scale of 1 means that the image is 1 unit high in the physics world. This is not the same as a PTM ratio, which only becomes necessary on some platforms.
Eddy8555 wrote:... not sure how to resolve this.
You'll have to tell us what you're trying to resolve before we can help :)
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: Scale units in RUBE

Post by Eddy8555 »

Basically I'd like to "hide" several objects outside of the screen, and allow the user to scroll there, and find them. Most likely I'll have them pay to unlock these items.

I'd love to have the scrolling done by touch, and not buttons.

I know the cocos2d sample project has scrolling with buttons, so unless someone has a self contained code sample I'll take a look there tomorrow morning :P
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: Scale units in RUBE

Post by Eddy8555 »

What is the best way to put a background image in a rube scene? I'm seeing that I can only attach it to a body, otherwise it's not showing on the screen? Would you just attach the bg image to a body, and put the body out of the screen? Or is there a better way?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Scale units in RUBE

Post by iforce2d »

You should not need to attach images to a body, perhaps there is something wrong with the import method. All images would be set at the correct position once upon loading, and then all images with a body will need to be repositioned every frame. Perhaps you are just missing the "set position once upon loading" part? Images with no body can be assumed to be on a body at 0,0. I guess if it makes things easier, you could just put those images to a static body with no fixtures.

About scrolling the screen around, this would require some coding using the touchesBegan, touchesMoved, touchesEnded etc methods to track the user's finger movements and alter the position of the layer accordingly. It's not really something that RUBE can know about or help you with I'm afraid.
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: Scale units in RUBE

Post by Eddy8555 »

Well, nothing I do works. All I'm trying now is just to place my background image, which size is screenSize.width*2, screenSize.height*2, so that the bottom of if aligns with the bottom of the screen, and the middle of the width is in the middle of the screen width. When working with a regular scene, this just worked:

Code: Select all

- (void) setBackgroungImage {
    CCSprite* background = [CCSprite spriteWithFile:@"redbg.png"];
    background.tag = BG_TAG;
    // zero is middle point width, contentSize/2 is bottom of image heigh:
    background.position = CGPointMake(0,background.contentSize.height/2);
    [self addChild:background z:-100];
}
I could also move the image around by playing with the values of the position point. But when trying this on my Rube Scene, values like zero, or contentSize.height/2 seem to have no influence on the placing of the image, or they just remove it entirely, or move it wildly with no rules that I can see.

Maybe it's related to the [self setAnchorPoint:CGPointMake(0,0)]; in BasicRubeLayer init?

This is frustrating. I need to do the basic stuff and move on, but something with the scale, or coordinates, or maybe something else is blocking me. Any concrete help would be really appreciated.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Scale units in RUBE

Post by iforce2d »

Are you using the sample loader still? You seem to be jumping around between not using it, then using it, then using it with your own tweaks, I'm losing track of what's going on. It could very well be related to the setAnchorPoint call you mention. One simple way to find out would be to comment it out and see... you could also look up the documentation for that function to see what it does... ;)
http://www.qcmat.com/understanding-anch ... n-cocos2d/
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: Scale units in RUBE

Post by Eddy8555 »

Yes, I am using the sample loader -- the saving and reloading part of it is working and doing good for me. So I'm subclassing from RubeLayer. And I did try to comment out the anchor point. Seems like it has no effect.
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: Scale units in RUBE

Post by Eddy8555 »

The issue was scaling. Once I scaled down my background image it started responding. Thanks.
Post Reply