background follow view and view follow player without parent

Game Editor comments and discussion.

background follow view and view follow player without parent

Postby J Maker » Wed Jul 01, 2009 2:56 am

ok, sorry, another topic where i can't find wat im looking for, but i remember someone posting a code that lets the view follow the player but smoother than parenting and another code someone posted that has the background actor follow the view. any codes that work are welcome or at least the link. thx :D
Some people believe Chuck Norris evolved from a dinosaur, the Chucknorisaurus.
----------------------------------------------------------------------------------
Chuck Norris doesn't sleep, he waits.
----------------------------------------------------------------------------------
Chuck Norris doesn't hunt, he kills.
----------------------------------------------------------------------------------
Chuck Norris once shot down a german fighter plane with his finger by yelling BANG!!!
----------------------------------------------------------------------------------
User avatar
J Maker
 
Posts: 177
Joined: Fri Jun 22, 2007 4:17 pm
Location: in the stick version of Hyrule
Score: 10 Give a positive score

Re: background follow view and view follow player without parent

Postby DST » Wed Jul 01, 2009 3:30 am

The trick is to do it from the player's script, not view's. This will keep it instantaneous and smooth.

player>draw actor>
Code: Select all
view.x=x-320;
view.y=y-240;
background.x=player.x;
background.y=player.y;
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: background follow view and view follow player without parent

Postby J Maker » Wed Jul 01, 2009 6:01 pm

thx man! never really thought of it that way.
Some people believe Chuck Norris evolved from a dinosaur, the Chucknorisaurus.
----------------------------------------------------------------------------------
Chuck Norris doesn't sleep, he waits.
----------------------------------------------------------------------------------
Chuck Norris doesn't hunt, he kills.
----------------------------------------------------------------------------------
Chuck Norris once shot down a german fighter plane with his finger by yelling BANG!!!
----------------------------------------------------------------------------------
User avatar
J Maker
 
Posts: 177
Joined: Fri Jun 22, 2007 4:17 pm
Location: in the stick version of Hyrule
Score: 10 Give a positive score

Re: background follow view and view follow player without parent

Postby J Maker » Wed Jul 01, 2009 6:18 pm

the code does great except for one little thing. the background is off. my background is the same size as the view and is aligned perfect in the GE editor, but when i hit game mode, the code makes it move to the bittim right, like this:
Attachments
background off.JPG
Some people believe Chuck Norris evolved from a dinosaur, the Chucknorisaurus.
----------------------------------------------------------------------------------
Chuck Norris doesn't sleep, he waits.
----------------------------------------------------------------------------------
Chuck Norris doesn't hunt, he kills.
----------------------------------------------------------------------------------
Chuck Norris once shot down a german fighter plane with his finger by yelling BANG!!!
----------------------------------------------------------------------------------
User avatar
J Maker
 
Posts: 177
Joined: Fri Jun 22, 2007 4:17 pm
Location: in the stick version of Hyrule
Score: 10 Give a positive score

Re: background follow view and view follow player without parent

Postby skydereign » Wed Jul 01, 2009 8:56 pm

This is probably happening due to the discrepancy of xy coordinates of view and other actors. I can't give you direct code, as I don't know your dimensions. If your dimensions are not 640x480, that may be why. If not, can you explain more?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: background follow view and view follow player without parent

Postby Game A Gogo » Wed Jul 01, 2009 10:16 pm

Code: Select all
view.x=x-view.width/2;
view.y=y-view.height/2;
background.x=player.x;
background.y=player.y;
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: background follow view and view follow player without parent

Postby J Maker » Thu Jul 02, 2009 1:34 am

skydereign wrote:This is probably happening due to the discrepancy of xy coordinates of view and other actors. I can't give you direct code, as I don't know your dimensions. If your dimensions are not 640x480, that may be why. If not, can you explain more?
my demensions are wierd. they r custom thats prolly why. they are: 485x365 in order to fit the picture. game a gogo, i will try ur code and report back
Some people believe Chuck Norris evolved from a dinosaur, the Chucknorisaurus.
----------------------------------------------------------------------------------
Chuck Norris doesn't sleep, he waits.
----------------------------------------------------------------------------------
Chuck Norris doesn't hunt, he kills.
----------------------------------------------------------------------------------
Chuck Norris once shot down a german fighter plane with his finger by yelling BANG!!!
----------------------------------------------------------------------------------
User avatar
J Maker
 
Posts: 177
Joined: Fri Jun 22, 2007 4:17 pm
Location: in the stick version of Hyrule
Score: 10 Give a positive score

Re: background follow view and view follow player without parent

Postby J Maker » Thu Jul 02, 2009 1:38 am

Game A Gogo, u rock man! the code works like a charm!
Some people believe Chuck Norris evolved from a dinosaur, the Chucknorisaurus.
----------------------------------------------------------------------------------
Chuck Norris doesn't sleep, he waits.
----------------------------------------------------------------------------------
Chuck Norris doesn't hunt, he kills.
----------------------------------------------------------------------------------
Chuck Norris once shot down a german fighter plane with his finger by yelling BANG!!!
----------------------------------------------------------------------------------
User avatar
J Maker
 
Posts: 177
Joined: Fri Jun 22, 2007 4:17 pm
Location: in the stick version of Hyrule
Score: 10 Give a positive score

Re: background follow view and view follow player without parent

Postby Game A Gogo » Thu Jul 02, 2009 12:10 pm

Universal codes that fits for everyone makes J Maker happy c:
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: background follow view and view follow player without parent

Postby DST » Thu Jul 02, 2009 3:42 pm

x=x-(width/2);

This is standard notation for centering objects in a script, used in many languages.

x=x-320;

This is magic number notation for a 640 x480 game.

Why use the magic number? Because width/2 doesn't change. You already know the answer to that equation.

So if your game plays for 10 minutes, at 30 fps, you will compute width/2 no less than 18,000 times. Its not a big deal, but its good to get in the habit of not wasting cpu, even if its only a little bit.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: background follow view and view follow player without parent

Postby Game A Gogo » Thu Jul 02, 2009 10:21 pm

true that, although since this variable changes from game to game, it's good to ask which value their's would be :P
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: background follow view and view follow player without parent

Postby J Maker » Mon Jul 06, 2009 2:35 am

Game A Gogo wrote:Universal codes that fits for everyone makes J Maker happy c:
totaly! :D thx man
Some people believe Chuck Norris evolved from a dinosaur, the Chucknorisaurus.
----------------------------------------------------------------------------------
Chuck Norris doesn't sleep, he waits.
----------------------------------------------------------------------------------
Chuck Norris doesn't hunt, he kills.
----------------------------------------------------------------------------------
Chuck Norris once shot down a german fighter plane with his finger by yelling BANG!!!
----------------------------------------------------------------------------------
User avatar
J Maker
 
Posts: 177
Joined: Fri Jun 22, 2007 4:17 pm
Location: in the stick version of Hyrule
Score: 10 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron