It looks like you're new here. If you want to get involved, click one of these buttons!
Hi, I have a problem when I run my code. I want to have many enemy spiders that move but only the first one moves. If someone could help me that would be appreciated.
Here is some of my Config code:
[Scene]
TrackList = enemyMakerTrack
[enemyMakerTrack]
1 = Object.Create spiderObject
Loop = True
[spiderObject]
Graphic = spiderGraphic
Scale = 0.2
Position = (800, 275, 0)
AnimationSet = spiderAnimationSet
Body = spiderBody
[spiderGraphic]
Texture = spider_full.png
TextureOrigin = (0, 0, 0)
TextureSize = (0, 0, 0)
Pivot = center
[spiderAnimationSet]
Texture = spider_full.png
FrameSize = (1024, 1024, 0)
Pivot = center
spiderWalkRight = 5
spiderWalkLeft = 5
StartAnim = spiderWalkLeft
spiderWalkLeft-> = spiderWalkLeft # .spiderWalkRight
spiderWalkRight-> = spiderWalkRight # .spiderWalkLeft
[spiderWalkLeft]
KeyDuration = 0.1
TextureOrigin = (0, 1024, 0)
[spiderWalkRight]
KeyDuration = 0.1
TextureOrigin = (0, 0, 0)
[spiderBody]
Dynamic = true
PartList = spiderBodyPart
LinearDamping = 5
[spiderBodyPart]
Type = box
Solid = true
SelfFlags = enemy
CheckMask = platforms # bullet
BottomRight = (225, 100, 0)
TopLeft = (-200, -175, 0)
and here is some of my c++ code:
#include "orx.h"
orxOBJECT* spider;
void spiderMovement()
{
orxVECTOR spiderLeftSpeed = { -3, 0, 0 };
orxVECTOR spiderRightSpeed = { 3, 0, 0 };
if (dead == 0)
{
orxObject_ApplyImpulse(spider, &spiderLeftSpeed, orxNULL);
orxObject_SetTargetAnim(spider, "spiderWalkLeft");
}
}
orxSTATUS orxFASTCALL Init()
{
orxObject_CreateFromConfig("Scene");
spider = orxObject_CreateFromConfig("spiderObject");
}
orxSTATUS orxFASTCALL Run()
{
spiderMovement();
}
This is not the whole code it is just things that are regarding to the problem.
I can post the whole code if you like.
Comments
Hi @Super_Michael_05, let's see what you have!
Here you have a
Scene
object that you use to create a new spider every second. Is that what you want?If so, you can check spawners to that effect.
Here I'd recommend having generic animations/set instead, this way you can re-use it for other enemies and use the same animation code to control them. Something like:
Of course if the size/number of frames per animation is different for every enemy, you can override them in each specific animation set by using the
Prefix
feature.Also, are you sure your
FrameSize
is correct? It seems much too large.Here you create yet another spider, this one you control it by code in
spiderMovement
. The other spiders that are created through the track onScene
are not controlled by this code, so they won't be moving.Do you want to control all the spiders as one or all of them independently?
If you want to control them as one, you could have them child of a single parent object and control them through that object instead. If you want to control them independently, you'll need to loop over them.
One of the easiest way to do that is either to use
Scroll
or to add a config property such asIsEnemy = true
and test it in a loop, something like:I also recommend using
orxObject_SetSpeed
instead of applying an impulse, it'll be much easier to control.Please note that as I wrote the code directly in the forum, there might be typos.
Thank you! I will get back to you when I have updated my code.
It works but I can't get the
orxObject_SetSpeed
to work.Here is where I added it:
Thanks!
I believe your problem here is two-folds:
Lastly, you can use the config system in order to retrieve the speeds, this way you can tweak them without having to recompile (you can even tweak them on-the-fly during runtime if you're using the resource's
WatchList
feature).Ex:
Thank you!
My pleasure!
For some reason it still doesn't work it plays the animation as it should but it doesn't move.
Did you set a bigger value on it? If you want you can send me your whole project and I can have a look at it.
Can I send you a link to my repository in Github then you could it download on to your computer?
Here it is:
https://github.com/Super-Michael-05/Space-Shooter-Current-Project
I do not see any code to move the spiders in your project at the moment. Did you remove it?
Ah sorry my bad I fixed it and pushed it but it still doesn't work.
I'm doing some refactoring, hope you don't mind, mostly the animation sets and the size of the textures that were ~1000 times bigger than they should have been, and it made the debug version very slow on my computer.
As I started working on the previous version, I didn't check your enemy code, however I added a functional version on my side.
I did some changes to your project, feel free to revert what you don't like:
Don't hesitate if you have any questions about some of the changes I made. Hope it'll help!
The PR can be found at https://github.com/Super-Michael-05/Space-Shooter-Current-Project/pull/1
Ah, you'll need the latest version of orx from its github repo, btw, as I fixed a small animation set inheritance bug, thanks to your project.
I am glad my project helped with the development of ORX and thank you a lot!
I implemented a Health system but it doesn't work and when I check the console and add
Config.GetValue Enemy Health
it doesn't give a value. If you can help me I have my code here: https://github.com/Super-Michael-05/Space-Shooter-Current-ProjectFirst of all, I'd recommend removing all runtime files (the logs, the build files, the debug files, etc...) from your repository, it makes a lot of noise when looking at diffs and will make the size of your repo grow very fast.
If we look at your
Enemy
section, there's noHealth
property in it:That's why
Config.GetValue Enemy Health
returns an empty value. Whereas you have:So,
Config.GetValue spiderObject Health
would return50
.Speaking of which, when doing a variation of an enemy type, I'd recommend inheriting from the base type of that enemy instead of
Enemy
directly and duplicating all the properties that are the same.Right now you have:
I'd suggest something like:
This way the changes done to the base spider will also affect its fast version.
Now regarding your code, I found:
The part
doesn't make much sense to me. That means every time a collision occurs, you're going to create two new objects,
Enemy
andGun
, but those don't have any purpose and will linger on forever.You do not need to have objects to retrieve config values. However if you want to retrieve values for an existing object, then you can use the object's name as the config section to push.
You do not have access to the gun in this event handler, only the character that got hit and the bullet. As such, I'd recommend setting the
Damage
value on the bullet instead of the gun (which works for you as you have different bullets for your different guns). You can even store it on the gun and inherit it at the bullet's level as well.At the moment, you do not store the
Health
on every character. You need to either attach your own structure to the characters that have health when they're created, so as to be able to track them over time, or simply use Scroll (https://github.com/orx/scroll) instead, which will make this much easier as you'll then have your own C++ classes for the objects that need runtime values, like health.Here's a part of what you need, assuming the above (there are ways to be more generic/automated, but let's focus on a simpler, more manual, approach, for now):
Thanks!