Parallax Scrolling in 1.0

Discussion about the PushButton Engine. Get the Open Beta now at http://pushbuttonengine.googlecode.com/ !

Parallax Scrolling in 1.0

Postby brock555 on Fri Mar 12, 2010 5:29 am

I found a tutorial on parallax scrolling, but it wasn't in 1.0 and i'm trying to figure out how to get it to work in 1.0. Flex is giving me to errors. One error on the import IDrawable2D and then later on renderPosition. How do I modify this class to work in 1.0? Thank you for the help.

Code: Select all
package
{
   import com.pblabs.engine.components.TickedComponent;
   import com.pblabs.engine.entity.PropertyReference;
   import com.pblabs.rendering2D.IDrawable2D;
   
   import flash.geom.Point;

   public class BackgroundImageController extends TickedComponent
   {
      public var TrackObject:IDrawable2D = null;
      public var BGImagePositionReference:PropertyReference = null;
      public var MovementScale:Number = 1;
      
      public function BackgroundImageController()
      {
         super();
      }
      
      public override function onTick(tickRate:Number):void
      {
         super.onTick(tickRate);
         
         var playerPosition:Point = TrackObject.renderPosition;
         
         var bgPosition:Point = new Point(
            (playerPosition.x * MovementScale),
            (playerPosition.y * MovementScale));
            
         owner.setProperty(BGImagePositionReference, bgPosition);         
      }
      
   }
}
User avatar
brock555
 
Posts: 20
Joined: Mon Mar 01, 2010 10:47 pm

Re: Parallax Scrolling in 1.0

Postby zylick on Fri Mar 12, 2010 6:51 am

HanClinto's got a kit he's selling. Should be close to being in the component store. It shows you how to do this and much much more! I'd recommend it. He gives videos and walkthroughs and answers posts on his forums pretty quickly.
User avatar
zylick
 
Posts: 31
Joined: Fri Feb 19, 2010 12:20 am

Re: Parallax Scrolling in 1.0

Postby shaz on Fri Mar 12, 2010 9:23 am

I just got the kit. Looking forward to playing with it - it looks very easy to use (as far as creating a level goes, at least).

Do you have a link to the forum? I couldn't find anything on the blog & wouldn't mind taking a look at any Q&A already posted.
User avatar
shaz
 
Posts: 254
Joined: Sat Oct 03, 2009 1:21 am
Location: Australia

Re: Parallax Scrolling in 1.0

Postby brock555 on Fri Mar 12, 2010 3:20 pm

Sweet. Where do you I buy this kit? I assume it uses 1.0 right?
User avatar
brock555
 
Posts: 20
Joined: Mon Mar 01, 2010 10:47 pm

Re: Parallax Scrolling in 1.0

Postby HanClinto on Fri Mar 12, 2010 6:51 pm

You can see a bit more of the kit here:
http://hanclinto.com

It does use PBE 1.0 -- I'm still working on getting the official purchase channels all set up, but I'll send you a PM with info on how we can work out a pre-release sale if you're interested.

Thanks! :)

--clint

P.S. Just noticed the question re: the Platformer Kit forums -- there isn't a separate forum yet, but there will (hopefully) be one on the boards here soon. Because this is pre-release, I'm trying to work pretty closely with all of my customers who may have questions, so feel free to e-mail me, or catch up with me in the IRC channel.
User avatar
HanClinto
Rock Star
 
Posts: 289
Joined: Mon Jan 19, 2009 5:54 pm

Re: Parallax Scrolling in 1.0

Postby brock555 on Fri Mar 12, 2010 6:55 pm

I'm interested in purchasing. Please PM
User avatar
brock555
 
Posts: 20
Joined: Mon Mar 01, 2010 10:47 pm

Re: Parallax Scrolling in 1.0

Postby HanClinto on Fri Mar 12, 2010 7:49 pm

brock555 wrote:I'm interested in purchasing. Please PM

Sent.
User avatar
HanClinto
Rock Star
 
Posts: 289
Joined: Mon Jan 19, 2009 5:54 pm

Re: Parallax Scrolling in 1.0

Postby bengarney on Fri Apr 02, 2010 11:11 pm

For anyone reading this thread now: The kit is now available for sale at http://hanclinto.com/! Check it out!
Ben Garney PushButton Labs
User avatar
bengarney
Employee
 
Posts: 1530
Joined: Wed Jan 14, 2009 7:21 pm
Location: Eugene, OR

Re: Parallax Scrolling in 1.0

Postby Jonak on Sat May 29, 2010 4:16 pm

For anyone reading this thread now and still interested in the original question, here's the originally posted class, adapted to work with 1.0 (at least it does for me)

Code: Select all
package
{

   import com.pblabs.engine.components.TickedComponent;
   import com.pblabs.engine.entity.PropertyReference;
   import com.pblabs.rendering2D.DisplayObjectRenderer;
   
   import flash.geom.Point;

   public class BackgroundImageController extends TickedComponent
   {
      /* properties will be set in the level description or commons xml */
      public var trackObject:DisplayObjectRenderer = null;
      public var BGImagePositionReference:PropertyReference = null;
      public var bgOffset : Point;
      public var MovementScale:Number = 1;
      
      public function BackgroundImageController()
      {
         super();
      }
      
      public override function onTick(tickRate:Number):void
      {
         super.onTick(tickRate);
         
         var playerPosition:Point = trackObject.position;
         
         var bgPosition:Point = new Point(
            (bgOffset.x + playerPosition.x * MovementScale),
            (bgOffset.y + playerPosition.y * MovementScale));
            
         owner.setProperty(BGImagePositionReference, bgPosition);         
      }
      
   }
}


HanClinto's kit probably does this in an easier and safer way, but to say it with Feynman: "What I cannot create, I cannot understand".
User avatar
Jonak
 
Posts: 5
Joined: Thu May 13, 2010 6:11 pm

Re: Parallax Scrolling in 1.0

Postby mrsanders on Mon Jun 21, 2010 2:53 pm

The code that i used is...
Code: Select all
public class BackgroundImageController extends TickedComponent {
      public var positionReference:PropertyReference;
      public var BGImagePositionReference:PropertyReference;
      public var MovementScale:Number = 1;
      
      public override function onTick(tickRate:Number):void
      {
         super.onTick(tickRate);
                        //var playerPosition:Point = TrackObject.renderPosition; replaced by below
         var playerPosition:Point = PBE.lookupEntity("player").getProperty(new PropertyReference("@Spatial.position"));
                        //in playerPosition x and y value put the minus sign
         var bgPosition:Point = new Point(
            (-playerPosition.x * MovementScale),
            (-playerPosition.y * MovementScale));
            
         owner.setProperty(BGImagePositionReference, bgPosition);         
      }
   }

You just need to remove also the TrackObject in the player creation. Because in my example i used a direct access to the property of player movement. I my case it is working but i don't know if is the properly way (or best practice).

...i realize later if you want the effect of the center player (tracking object), i put this code in the player creation. and no need anything else in the code that i post above.

Code: Select all
var display:DisplayObjectScene = PBE.scene as DisplayObjectScene;
display.trackObject = render; // render in my case it is SpriteSheetRenderer type
User avatar
mrsanders
 
Posts: 4
Joined: Fri Jun 18, 2010 2:34 pm


Return to General

Who is online

Users browsing this forum: TheBlackSheep and 0 guests