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.

AppGameKit Classic Chat / creating a side scroller with SetSpritePhysicsVelocity

Author
Message
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Oct 2021 00:26
rather than trying to match the speed just use the players x position, we can use Mod() but there isnt much need and I think mod has overhead we dont want in a loop, just use what you already have, the players position, if the background is going to scroll with the player then just use the players global x position to offset your UV, so now mid jump and he suddenly stops the background stops with him

its best not to use SetSpritePosition while using physics but Get... we can use that as much as we want to no effect

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 20th Oct 2021 03:05
PartTimeCoder

I did a test to see the memory with 70 background sprites to just using one and I have more memory with just one as I scroll the texture.
Like 30 mg more memory.

So I've decided not to scroll, its a bad idea.

Thanks for your help anyhow.

I do appreciate it.
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Oct 2021 18:10
Are you saying scrolling an image requires 30mb of memory ...

I really doubt that, I have an Asteroid type setup using physics in infinite space environment that uses the below function to scroll the background with a lerp and the entire game run at 20mb, if you are adding 30 by scrolling an image the you are doing something very very wrong!

a single 1024x1024 background covers the entire universe but never moves, I just offset the image to give the illusion of movement



although it is a little jumpy in the browser : https://parttimecoder.itch.io/space-game-thing?secret=LgiU3MpR1yiHtfxxt7bO94SyZS4
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 20th Oct 2021 19:07
Quote: "I really doubt that"




I've done many tests and I was also very surprised myself.

And to be honest with you, I don't want any jumps in my scrolling and there are many to count.

every time when I get stopped mid air in a jump.

Plus I don't plan on adding any more to any level, all my levels are going to match each other in sprite counts, I hope.

PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Oct 2021 20:32
Quote: "I've done many tests and I was also very surprised myself."


Because you don't understand it, does not mean its broken.

I have a rather old low end laptop if a function has overhead believe me I would encounter it.

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 20th Oct 2021 23:21
Quote: "not mean its broken"


I never said anything about being broken my friend.

But I do understand memory and sprites loaded and just about everything there is to know about computers.

What is it I don't understand?

Please explain so I can know myself.
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 21st Oct 2021 00:00
Seriously, now that's a bold statement for someone that did not know what Box2D was?, maybe not everything then, huh?

ok, the render pipeline, understanding memory and computers you will understand that the image is sent to the GPU, the default sprite shader generated by AppGameKit sends texture coord's to tell the GPU where to draw your sprite within its frame, using SetSpriteUVOffset simply changes the value sent to the shader telling the GPU what to draw, no overhead is add, no extra arguments sent, no extra memory used, I fail to see how it affected your memory usage and have explained in detail how I have come to that conclusion but you assert that it did, one of us is misunderstanding something here!

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 21st Oct 2021 02:20 Edited at: 21st Oct 2021 14:58
Edit out.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 05:32 Edited at: 24th Oct 2021 05:33
Well Here is a update on level 2, still have a lot more to do.

I added many new aspects to this level and for future levels.

Note: The game will be much faster pace then this, I just slow it down to show the progress.

PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 24th Oct 2021 16:57
A bit of a weird sliding action while on the platform and your animations are still a bit out of sync size wise but dam, your levels look fantastic, the rope jump works well just a shame that sprite does not have a "grab" animation

Your jump physics look 100% better, still a tad high maybe but a nice arc your settings are almost spot on and she seems to land with a bit of a thump, which is good.

Again your levels look great, its just a crying shame that AppGameKit does not have out of the box 2D lighting as your level would really benefit from a little atmosphere.

Overall I'd say its coming along nicely, 10/10 for effort, well done
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 19:03
Quote: "A bit of a weird sliding action while on the platform"


I know, I tried every physics function to boot and still slides, I tried setting sprite mass real high and this made the swing , swing all around non stop lol, it was a funny this to watch.

Quote: " just a shame that sprite does not have a "grab" animation"


I wish I was a artist, but I will soon be looking for a artist who can use what I bought and hopefully make a couple more animations for me.

Quote: "Your jump physics look 100% better, still a tad high "


Well It is odd, how things work differently in my phone and on the pc, I have to adjust it for each and as i am testing I just keep it like it is. same for my walk and run, on my phone real fast, to fast, on my pc just the right amount. so I have this set for my pc to test it.

Quote: "Again your levels look great"


Thank you, a lot of hard work.
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 24th Oct 2021 19:46
Quote: "I tried every physics function to boot and still slides"


Is your player now set dynamic or kinematic?

I would need to test to confirm but once the player lands on the platform the physics engine should take care of the position, if its dynamic, kinematic you would need to lock its position <<< brain fart << not really sure

one way to go about it is use GetWorld*FromSprite to get the correct position on the platform and (in this case) override the physics to set the player position.

Its an interesting mechanic that I have never done before so from the get go you already done better than me, lol

Quote: "I wish I was a artist"


Yeah, "Game Art 2D" free stuff does not come with the SCML file, if you buy a premium pack you get the body parts and SCML file then you can make any animation you want in Spriter, the IK is already setup on the rigs adding new animations is pretty easy, its worth the investment.

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 20:29
Quote: "if you buy a premium pack"


I have a monthly download premium membership and I have all the sprinter parts with license for each player the guy and Girl. I just don't know anything about sprinter lol.

Quote: "one way to go about it is use GetWorld*FromSprite"


I might just try to use set sprite position or set sprite movment to o, let me look at it and work it out, something to do today.

PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 24th Oct 2021 20:53
Ah ok well if your subscribed and get the full package it would really benefit you to learn Spriter, there is a wealth of information out there on how to use it, its not an overly complicated program but does have a small learning curve, I have a few of their packs (Mechs and Soldiers) but never used them.

I have this weird thing that I want to learn a program or system, I learn it and get good and then find something else I want to learn, its good because I know many API's, IDE's and systems but bad because I never get anything done!!

Quote: "set sprite position or set sprite movment to o"


In that situation its probably the best solution, only the player will still need to move on the platform but thats easy enough to code in, as you say just use SetSpritePosition only while on a oscillating platform overriding the physics engine and reinstate the physics when the player jumps off the platform.

This should be doable in just physics code but right now I am not sure how to go about it.... depends on the settings and will most likely break something else... the joys of coding, huh! lol
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 21:46
Quote: "its good because I know many API's, IDE's and systems but bad because I never get anything done!!"


And this is why I don't want to do anything else.

I am a programmer, that is all I want to be.

I know some big time Programmer's who work along with artist's who make many big programs because they work together. Now all i need is a good artist to work along with me and we can create many good applications and make a business out of it.

Small time artists work by them self and sell there art for small amounts and do ok, but artists that want to grow find good programmer's to work with and I'm hoping soon I can find the same.

It is funny because I just watched a video of the team who created crash bandicoot years ago and they only had two in the team, the programmer and the artist.
They did everything just for the game and became a team together for years after that.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 22:17
On another note

I can not for the life of me figure out what ray cast from just the top of the player to the bottom of the rock would be

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 24th Oct 2021 22:33
seems you're doing something different than Grounded (ie, checking a single rock?)
but, maybe:
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 22:39 Edited at: 24th Oct 2021 22:42
Quote: "seems you're doing something different than Grounded"


Nope just in my PhysicsRayCast, thanks I will try it but I can not get a hit other then under the rock. this is what I'm trying to achieve.

This is the whole thing

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 23:01
Virtual Nomad

That fixed it so simple in the end lol

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 24th Oct 2021 23:19 Edited at: 24th Oct 2021 23:36
i havent implemented it yet myself but a few examples ago i realized that Contacts vs Rays might be best (where there is now redundancy). ie, get all contacts then get positions/directions relative to px#/py# to determine "ground", "head", "left/right", etc for full 360 deg coverage.

it might have to do with experience with contacts in 3d/bullet which are tricky but i was hesitant to use box2d contacts because of said experience. but, it's worth exploring, so...

in the end, whatever works then, ideally, whatever works BEST.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 24th Oct 2021 23:52
Quote: "Contacts vs Rays might be best "


Well this is a ray with a contact together and it works great.

Quote: " ideally, whatever works BEST."


Amen to that
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 25th Oct 2021 02:45
I have been looking for that Artist for over a decade!

A small tip for code optimization

This:


You call Rocks.Find(ThisHit) in the if statement and then again after by setting the Rock variable, call it once before the IF and use the variable in the IF, this might seem a bit OCD to some saying "but modern computers bla bla bla" but in a massive project if you did this kind of thing on every if, loop and function you will cripple the FPS and have your users flaming you on Steam ...

Rule of thumb, if an array lookup is going to be used more than once in a section of code put it in a variable, var access is far far less expensive than array lookups, also self auditing is very very important, I don't believe in "if it works its good" that is a bad attitude and one that will lead to failure, write the function, get the code working and then study the living daylights out of it to find ways to improve and speed it up.

Good programmers write code that works, great programmers write code that works fast

You seem like a smart determined person and a fast learner, I am sure you will get there, if you find that artist, give him my number! lol

Quote: " i was hesitant to use box2d contacts because of said experience"


Your intuition is correct there is a very well documented fault in Box2D "the ghost vertices issue" that occurs when a box shape slides over another box shape, think a square player sprite sliding over a tilemap with individual collision shapes for the tiles, sometimes the edges can catch on "ghost vertices" and register a collision


Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 25th Oct 2021 04:29 Edited at: 25th Oct 2021 04:30
Quote: "I have been looking for that Artist for over a decade!"


Yes there hard to find unless you pay them upfront then even after that your not guarantied good quality.

Quote: "You call Rocks.Find(ThisHit) in the if statement and then again after by setting the Rock variable,"


Well I am using the same code Virtual Nomad wrote up as a example.

Quote: "You seem like a smart determined person and a fast learner, I am sure you will get there, if you find that artist, give him my number! lol"


Thank you
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 26th Oct 2021 01:21 Edited at: 26th Oct 2021 01:25
I have a small problem

I create my rocks and coins with this array

I then hit each rock and then the coins delete.

I then walk and my ground is also deleted

Somehow my invisible ground for collision is in the same array but it is not.



This is me creating my ground




How is my ground being mixed in with a set array?

Edit:::

This is how I'm deleting the coins in its own array.



Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 26th Oct 2021 02:47 Edited at: 26th Oct 2021 02:59
Quote: "How is my ground being mixed in with a set array?"

i don't see where it is. where else are you deleting sprites?

unrelated:

at some point, m => 700 then it's immediately 900, then 950 (all at once).
later, it's 1700 and immediately 2000, then 2050 (again, all at once)
i dunno what m might be but i'm pretty sure you don't want all that going on.
maybe m should use select/case vs if statements so it's only processed once at a time?

add: obviously that code is familiar but i used step -1 because when i wrote it, i also .removed the index from the array (along with deleting the sprite it referenced).
you're not doing that (.remove) so at some point that index is refilled with another sprite ID? or, recreated later with the SAME sprite ID?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Oct 2021 02:50
Maybe try
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 26th Oct 2021 03:43 Edited at: 26th Oct 2021 04:02
Quote: "unrelated:"


So I want to position each rock in some x pos and not so I change the x pos for those places, it works good.

Quote: ".remove"


I'm not sure and if so I need to look at it better, that would be my bad. That is a probability.

blink0k

That's a good idea, I will try it just to play around with it.

But to be honest I was more confused on why my ground is in my array and I think Virtual Nomad Answered this.

Ok edit:

I added this to my code

MyCollectedCoins .remove()

And it works
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 26th Oct 2021 04:24
Nomad wrote: "unrelated:"


GameCode wrote: "it works good."


What Nomad is trying to tell you is

this line (if m=>700 then inc m,200.0), sets m to 900 and the next line (if m=>900 then inc m,50.0) sets m to 950 so m=900 never makes it into your code

and the same for the next 2 lines

if this is the behaviour you want then (if m>=700 then m=950) gives the same result and saves CPU cycles, again, same for the next 2 lines

and please don't say "well it works so its fine", we are trying to help you here, we know code, we know how it works and we can do basic math and that block of code makes no sense!, did you read anything I posted about self auditing?

use elseif





Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 26th Oct 2021 05:09 Edited at: 26th Oct 2021 05:15
Quote: "we know how it works and we can do basic math and that block of code makes no sense!, did you read anything I posted about self auditing?"


It does work, it places every rock where I want and not in the places I don't want.

m=900 never makes it into your code, is because I am not finished with the code, I stopped there till I am ready to put in new rocks.

But I will try your elseif any how because it looks like a better way to do it.

Thanks for your input.

I am real close to finishing level 2

I have some pretty cool things I am going to add soon.


Edit:

But I looked and found im not using that any longer my bad lol.

I am now doing this

SetSpritePosition(Rocks[0].ID, 130, 20)
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 26th Oct 2021 05:47 Edited at: 26th Oct 2021 05:51
Quote: "It does work"


I didn't doubt for a second that it does exactly what you want it to do, just pointing out the obvious flaw in the block trying to help make you a better coder.

Quote: "But I will try your elseif any how because it looks like a better way to do it."


Well better is subjective, depends on the use case

if you are checking the same variable multiple times (within a range) then use a elseif, for static values use a select statement, for a single argument/function check (if something then) is fine, it really depends on what values you are evaluating

one of the fundamental principles of coding is instinctively knowing what to use where ... this will come with experience, and good advice form forum members

Edit:

Quote: "But I looked and found im not using that any longer my bad lol."


Meh!, I have many projects that have unused blocks of code left over from testing, it happens, don't sweat it.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 26th Oct 2021 06:14
Quote: "one of the fundamental principles of coding is instinctively knowing what to use where ... this will come with experience, and good advice form forum members "


Boy am I finding out that to be so true.

I think I have restructured this code at least 4 times after learning new things.

But I think I understand arrays a lot better then i did and this will help me with future code and also what to put where and why.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 27th Oct 2021 01:42 Edited at: 27th Oct 2021 03:05
Hello my good coding friends.

I have a small crazy situation.

I have snakes in my level, each snake is set in a array.

That works great.

But when they attack they attack with there sprite flip is the wrong way and right way.

How do I check what side of each snake is on from my player? then flip there sprites accordingly?

I was thinking maybe

if getspritex(player)>getspritex(snake) setspriteflip(snake,0,0)
if getspritex(player)<getspritex(snake) setspriteflip(snake,1,0)

untested

what is the best way?

EDIT:

I tried this and it works but at a point some of them flip back and forth like crazy.

PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 27th Oct 2021 13:31
Try adding a little padding, a few pixels either side of the player (PX#-3>SX#) (PX#+3<SX#)
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 27th Oct 2021 20:00
Quote: "Try adding a little padding"


I did, and it still does it and I figured out why.

It is in a continuous loop

if SnakeDis=<30 and SnakeDis=>15

I need to set it to flip on like this I believe.

if SnakeDis=30 without the <>

Thank you for the help either way.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 28th Oct 2021 02:06 Edited at: 28th Oct 2021 07:29
I have a set up where the player is moving between swinging spikes

I need the spikes to keep swinging at the same pace back and forth.

this does not work at all



Edit:

I figured it out

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 31st Oct 2021 04:42
So I have a array set up for the life time of each arrow shot.

it counts the arrow timer for each then zeros out after the arrow has been deleted.

What I'm worried about is my program storing all the timed 0 variable's in memory for no reason, if it doesn't exist what is the point?
will it slow down my program after awhile? Is there a way to rem memory after each delete sprite?

PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 31st Oct 2021 11:40
DOT REMOVE X

.remove(x)



Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 31st Oct 2021 18:35 Edited at: 31st Oct 2021 19:23
ArrayOfArrows.remove(x)

this worked, thank you PartTimeCoder

But I had a array error so I had to ask if the array was over 0

if ArrayOfArrows.Length>0 then ArrayOfArrows.remove(x)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 31st Oct 2021 20:21
Remember that if you are looping throught the array and deleting elements as you go then you should loop from the end of the array through to zero or you will skip entries or get the error you mentioned
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 31st Oct 2021 20:32 Edited at: 31st Oct 2021 20:38
blink0k

Yes, and sometimes when you are shooting bullets' or arrows I noticed if you have more then one it will also give me a error so I am only shooting one bullet at a time.

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 31st Oct 2021 22:08
Ok here is a little update on level 3

took me awhile to figure out some array stuff but added a lot.

Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Nov 2021 17:05
There's nothing there that would indicate to me that the barrels could be broken by jumping on them. Do you have something planned to show that? Or is that intended to be a hidden thing?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 2nd Nov 2021 19:35 Edited at: 2nd Nov 2021 19:37
Quote: "Do you have something planned to show that? Or is that intended to be a hidden thing?"


Yes, you can break boxes barrel's and chests, this will be a known event in the game. < almost have the timing perfect but sometimes you can easily break two at a time, I'm trying to fix this.

The bird is dropping mad amount of rocks on you as you try to dodge arrows so breaking the boxes are a good way to avoid things for a time period.

The next level is a water level where you have to jump from platform to platform and not get pulled into the water by something.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 3rd Nov 2021 00:45 Edited at: 3rd Nov 2021 02:00
Help

This is driving me crazy, I had tried everything

I am creating water for my levels, with a water shader that looks cool and works good.

But when I add clones to my level then I line them right next to each other, there is a border line, if to close, but if one point away there is a line between them.

I know it is mostly because of the transparency but still, they can not be that close in to each other.

I've tried

SetSpriteUVBorder(clone_1,0)
setimagemagfilter(clone_1,1)
setimageminfilter(clone_1,1)

Edit:

Never mind, I figured out that setting the sprite offset before hand was making it do this.


Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 6th Nov 2021 01:09 Edited at: 6th Nov 2021 04:09
What am I doing wrong, its not returning any find for my array



Edit:

Never mind lol

I just used PlayerFeet = PhysicsRayCastGroup( -100,PX#,PY#,PX#,PY#+15 )

PhysicsRayCastGroup

Login to post a reply

Server time is: 2024-03-04 14:17:53
Your offset time is: 2024-03-04 14:17:53