Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / using sprites with Velocity#

Author
Message
UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 4th Mar 2004 22:44
I was tryin to use a sprite for the engine im making but every time i try to get it to move with the Velocity# command it dosnt do anything it just sits there anyone have any idea's?

The search continues.

Current project - A space game
Cros Jovil
21
Years of Service
User Offline
Joined: 27th Jan 2004
Location:
Posted: 4th Mar 2004 23:53
quite possibly because the x and y cords are integers thats a real number not quite sure but I dont think that they work well together and why not just use integer velocities anyways
UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 5th Mar 2004 07:14
because i believe real numbers work better for speed then integers. As integers are 20 and a real number is something like 20.0 so you have better control over the speed.

i do believe that doing this is better
EXAMPLE this probably won't work so don't try it.

Velocity# = 0.0

if upkey()=1 then inc velocity#,0.2

as to where if you used integers you'd have something like

Velocity# = 0

if upkey()=1 then inc velocity#,1

So for integers you'd be going way to fast but with real numbers you can make things go at a decent speed it also works better for acceleration as you can have 0.1,0.2,0.3 ect ect as if each real number where a diffrent speed (10 mph 20 mph 30 mph ect ect..)

so thats why and even though you where tryin to help me you didnt really. i was looking for more of a example coding of what i could possibly do...

The search continues.

Current project - A space game
Cros Jovil
21
Years of Service
User Offline
Joined: 27th Jan 2004
Location:
Posted: 5th Mar 2004 15:05
is velocity a command or just a variable cuz if it's a variable just velocity=1 your not going to want to move half a pixel so your code could look like
do
xvelocity=0
yvelocity=0
if upkey()=1 then inc yvelocity
x=x+xvelocity
y=y+yvelocity
sprite 1,x,y,1
loop
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 5th Mar 2004 15:46
You do sometimes want to move half a pixel, Im afraid. It doesnt show up on screen, but its related to speed. For example, if I want to move a sprite at a cretain speed along a vector when I calculate the vector, my speed might dictate that I have to move 1.5 pixels every loop so that Ive moved 9 pixels in 6 cycles. You see what I mean?

GIve me more power!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Mar 2004 16:08
Yeah you use # for velocity for better timing. It makes gravity look more realistic. Your code looks ok. It's probably just the sprite part that is wrong. Try velocity# = velocity# + 0.2 just incase of a bug.

UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 5th Mar 2004 16:32 Edited at: 5th Mar 2004 17:17
Cros - any variable with a '#' after it IE Velocity# is a variable that uses real numbers if i tried to use Velocity# with a integer number it wouldnt work. So just making sure you know why i was using real numbers i hope you learned something from this =) and thanks for your help anyways but you might want to look at that code you did.

Thanks Pinco i'll try that...

[edit]

Well i figgured out what i was doing wrong after i took another glance at the spaceship/shooting controls in the codebase hehe then i just edited the code in the codebase (by david89 it was) to work on what i have right now and it works perfectly...well almost still a couple things to work out but it turns out that i forgot to put

Move sprite 1,velocity# and thats why the sprite wasnt moving hehe

So im glad people do use the codebase or i would have never thought of that so yay! im making progress!!! silly me...


the code im using if anyone is inttrested in looking


The search continues.

Current project - A space game
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Mar 2004 17:20 Edited at: 5th Mar 2004 17:21
Quote: "Cros - any variable with a '#' after it IE Velocity# is a variable that uses real numbers if i tried to use Velocity# with a integer number it wouldnt work."


It would work, it just wouldn't look quite as realistic. The code would be faster though, and if you were desperate for more speed you could get away with it.

UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 5th Mar 2004 17:25 Edited at: 5th Mar 2004 18:07
Never that desperate =) but anyhow its a good thing that the code was there in the codebase or i might of ended up using some weird peice of code the code im using now i seem to understand better then any other code i'v tried (3rd time changing player movement code)

[edit]

ok so now that i'v done that...how would i put a max limit on how fast the ship can go because the longer i hold the up button down for the faster it goes

The search continues.

Current project - A space game
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Mar 2004 18:42
Max speed = whatever

If speed < max speed

speed = speed + whatever

endif

UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 6th Mar 2004 00:48
ahh i c thanks pincho i'll add tis in right befor i go to work see how it holds up.


Well it gave me something but not what i wanted =P what i did was



so if you see the

if speed < maxvelocity# then velocity# = maxvelocity# + 0.4 which actually made the ship move without using the arrow key (up) to move it hhehe funny i think i should have put '+ 0.0' as the regular velocity is velocity# = 0.0 heh

The search continues.

Current project - A space game
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Mar 2004 02:23 Edited at: 6th Mar 2004 02:25
Ok you need to understand how code works... this is wrong...

rem player movement got off the code base thanks to david89
if upkey()=1 then inc Velocity#,0.1
if downkey()=1 then dec Velocity#,0.1
if leftkey()=1 then dec Ang,3
if rightkey()=1 then inc Ang,3

Move sprite 1,Velocity#

if upkey()=0 and downkey()=0 and velocity# <> 0
if velocity# > 0 then dec velocity#
if velocity# < 0 then inc velocity#
velocity# = 0
endif

if speed < maxvelocity# then velocity# = maxvelocity# + 0.4
***************************************************************
THIS IS THE EDITED VERSION
Upkey is where you need to put my line.......
rem player movement got off the code base thanks to david89
if upkey()=1
if speed < maxvelocity# then inc Velocity#,0.1
Endif


if downkey()=1 and velocity# > 0.0 then dec Velocity#,0.1

if leftkey()=1 then dec Ang,3
if rightkey()=1 then inc Ang,3

Move sprite 1,Velocity#

if upkey()=0 and downkey()=0 and velocity# <> 0
if velocity# > 0 then dec velocity#
if velocity# < 0 then inc velocity#
velocity# = 0
endif

***************************************************************

UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 6th Mar 2004 06:12 Edited at: 6th Mar 2004 07:37
hmmm i c i c well im still a noob pincho i won't know everything you do. I also thought that making it move on its own was kinda nice but usless none the less im sure someone could find a use for it though.

that seems to work ok but the downkey dosnt work heh =)

The search continues.

Current project - A space game
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Mar 2004 16:29
I didn't do the downkey part, it's up to you to figure it out.

UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 6th Mar 2004 17:08
i figgured that is why you made it not work....=)

The search continues.

Current project - A space game
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Mar 2004 17:17
The opposite to inc is dec

UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 7th Mar 2004 16:59
i know it wasnt that hard to figgure out but it was a nice thought to think about my learning

The search continues.

Current project - A space game
UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 21st Mar 2004 20:51
Oh haha i havent worked on this for awhile but i figgured it out lol got it to move at the same speed all the time now hehe

The search continues.

Current project - A space game
UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 21st Mar 2004 21:01
here is the code you gave me

rem player movement got off the code base thanks to david89
if upkey()=1
if speed < maxvelocity# then inc Velocity#,0.1
Endif


if downkey()=1 and velocity# > 0.0 then dec Velocity#,0.1

if leftkey()=1 then dec Ang,3
if rightkey()=1 then inc Ang,3

Move sprite 1,Velocity#

if upkey()=0 and downkey()=0 and velocity# <> 0
if velocity# > 0 then dec velocity#
if velocity# < 0 then inc velocity#
velocity# = 0
endif

and this is what i did

deleted the

if upkey()=0 and downkey()=0 and velocity# <> 0
if velocity# > 0 then dec velocity#
if velocity# < 0 then inc velocity#
velocity# = 0
endif

took this

if upkey()=1
if speed < maxvelocity# then inc Velocity#,0.1
Endif

replaced it with
if upkey()=1
if velocity# < maxvelocity# then inc Velocity#,2.5

now this is what i have

if upkey()=1
if velocity# < maxvelocity# then inc Velocity#,2.5
Endif


if downkey()=1 and velocity# > 0.0 then dec Velocity#,0.1

if leftkey()=1 then dec Ang,3
if rightkey()=1 then inc Ang,3

Move sprite 1,Velocity#




Rotate sprite 1,curveangle(Ang,sprite angle(1),0.1)

this allows the player to control what speed he/she wants to go at without holding down the up key to go fast you just press up and then press down to slow down to any speed you want...although going backwards is really slow but i can change that =)

is that what you where hoping i'd get pinco? this is the first time i'v messed with the code in weeks lol.

The search continues.

Current project - A space game
UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 21st Mar 2004 22:35 Edited at: 21st Mar 2004 22:37
heres something to play with

if velocity# <> maxvelocity# then inc velocity#

i was wondering what would happen if i put that in there and bam this is what i got...kinda looked like a ship jumping into warp speed like on star trek lol.

put it in the code i gave above heh.

[edit]

if velocity# <> maxvelocity# then inc maxvelocity#,0.1

putting this in will let the ship go super fast heh. dunno why i'd want that just some fooling around.

The search continues.

Current project - A space game

Login to post a reply

Server time is: 2025-08-09 02:12:19
Your offset time is: 2025-08-09 02:12:19