keep player in view

Game Editor comments and discussion.

keep player in view

Postby foleyjo » Fri Jul 27, 2007 1:15 pm

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
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Postby foleyjo » Fri Jul 27, 2007 1:40 pm

ok first problem sorted.
On actor draw command i have

Code: Select all
yvelocity = view.yvelocity;


and its done the trick
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Postby pixelpoop » Fri Jul 27, 2007 2:13 pm

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.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby pixelpoop » Fri Jul 27, 2007 2:20 pm

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;
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby foleyjo » Fri Jul 27, 2007 2:29 pm

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
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Postby pixelpoop » Fri Jul 27, 2007 3:41 pm

here is a demo that may help
Attachments
fire_direction.zip
demo of:
setting angle for bullets
moving view up
moving player within moving view
(198.74 KiB) Downloaded 102 times
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby foleyjo » Fri Jul 27, 2007 5:32 pm

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.
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Postby DilloDude » Fri Jul 27, 2007 11:36 pm

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby pixelpoop » Sat Jul 28, 2007 7:47 am

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.
Attachments
fire_direction2.zip
(199.22 KiB) Downloaded 97 times
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby foleyjo » Sat Jul 28, 2007 8:36 am

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
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Postby Sgt. Sparky » Sat Jul 28, 2007 5:57 pm

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
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby foleyjo » Sat Jul 28, 2007 10:22 pm

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
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Postby DilloDude » Sun Jul 29, 2007 2:12 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron