Page 1 of 1

keep player in view

PostPosted: Fri Jul 27, 2007 1:15 pm
by foleyjo
I have a top down scroller. I have everything laid out and the view moves upwards.
What I need is the player to move with the view.

I tried giving it view as parent but then I started to get all sorts of problems.

My enemies which shoot at the player end up shooting down no matter where the player is
Im using create actor -> script editor

Code: Select all
angle = direction(x, y, poop.x, poop.y);
directional_velocity = 10;


Also I have a move to command where the player needs to move to the center of the screen. This was working fine but now the views moving it just goes off screen.

Any help please

PostPosted: Fri Jul 27, 2007 1:40 pm
by foleyjo
ok first problem sorted.
On actor draw command i have

Code: Select all
yvelocity = view.yvelocity;


and its done the trick

PostPosted: Fri Jul 27, 2007 2:13 pm
by pixelpoop
Code: Select all
angle = direction(x, y, poop.x, poop.y);
directional_velocity = 10;

Is this code on the create actor event of the bullet or the enemy? If it is on the bullet and your target is poop, then your code will work.

PostPosted: Fri Jul 27, 2007 2:20 pm
by pixelpoop
The move_to function uses a velocity and is probably screwing with your yvelocity code. Instead of using yvelocity = view.yvelocity; on your player, use: y=view.y;

PostPosted: Fri Jul 27, 2007 2:29 pm
by foleyjo
pixelpoop wrote:
Code: Select all
angle = direction(x, y, poop.x, poop.y);
directional_velocity = 10;

Is this code on the create actor event of the bullet or the enemy? If it is on the bullet and your target is poop, then your code will work.


create code is on the bullet

PostPosted: Fri Jul 27, 2007 3:41 pm
by pixelpoop
here is a demo that may help

PostPosted: Fri Jul 27, 2007 5:32 pm
by foleyjo
Thank you very much. :D

just one thing i got to mention not covered in that demo.
My player actor also move up and down which is where my main problem is comming from.

PostPosted: Fri Jul 27, 2007 11:36 pm
by DilloDude
You could have a variable that is your y=position on the screen, and use that (yscreen = variable). The reason the parenting doesn't work is because an actor's coordinates are relative to its parent. To fix this you can use xscreen, yscreen, instead of x, y.

PostPosted: Sat Jul 28, 2007 7:47 am
by pixelpoop
Here is another demo. Some of the coding has changed.
The target moves with the arrow keys. Space bar to fire. "a" button to set the target to the middle.

PostPosted: Sat Jul 28, 2007 8:36 am
by foleyjo
Thank you once again, It has no become apparant to me that when i first tried to this in theory I was doing the right thing.
In practice I was using

actor =- 1;

when i change this to

actor -= 1;
like I noticed you do in your 2 demos, suddenly it all works.

again thank you

PostPosted: Sat Jul 28, 2007 5:57 pm
by Sgt. Sparky
here is a code I use for my latest project, a side scroller version of Sky Master:
Code: Select all
if(ActorCount("plane") > 0 && pause == 0)x = (plane.x - width) + plane.X;

to use a code similar to this that would work with your game,
make 1 filled region actor called block,
make the view its parent and make it the size of the edges of the view.
next make a integer that is an actor variable called Y.
and put on the draw actor event of your view actor:
Code: Select all
if(ActorCount("playername") > 0)x = (playername.y - height) + playername.Y;

(replace playername with your players name. :D
now put on the create actor event of your player:
Code: Select all
Y = view.height - (height + 50);

and on the key down event of up for your player:
Y -= 5;
on the key down event of down:
Y += 5;

:D
if you have any problems let me know, but try using all the other codes first. :D
EDIT: nevermind, it seems you got it to work. :D

PostPosted: Sat Jul 28, 2007 10:22 pm
by foleyjo
Even though I seem to be ok now Ill still try what you said.
Im new to this and my programming skills are lacking so trying everything and seeing how it works helps. So thank you very much

I notice you used the
a-=b
as well
I must get to grips with this
Can someone explain what the difference is between that and
a=-b

PostPosted: Sun Jul 29, 2007 2:12 am
by DilloDude
a -= b is shorthand for a = a - b. IE it subtracts b from a (in some ways it is different in that it soesn't invlove temporary values). the same applies for +=, *= and /=. Also you can use a++ or a-- for a+=1 and a-=1 (just a bit simpler). Putting a = -b sets a to the opposite value of b.