Hi,
I am in the early stages of starting out with UE4. I am using 4.23. I have decided to write a 2D game in C++ as much as possible. I have been coding for many years now and am comfortable with C++. I am following the Epic Games C++ Tanks vs Zombies 2D video series.
At the moment I am just getting a feel for rendering sprites etc. I am getting a bit ahead of myself because I haven’t learnt how to spawn a sprite from the video series. I just searched online.
This is my scenario:
Sprite 1 is a C++ pawn class, which contains a orthographic camera. The sprite is a UPaperSpriteComponent attached to the RootComponent. I have loaded the sprite asset (UPaperSprite) and set it on the component and located it on the screen somewhere.
Sprite 2 is another C++ pawn class, that loads another sprite asset.
Sprite 1 is spawned when the game starts from a blueprint gamemode class.
Sprite 1 then spawns Sprite 2 as follows:
// Called when the game starts or when spawned
void ABackground::BeginPlay()
{
Super::BeginPlay();
// Spawn sprite2
FVector location {0.0f, 0.0f, 1.0f};
UWorld* const World = GetWorld();
if (World)
World->SpawnActor(ASprite2::StaticClass(), &location);
}
Sprite2 does not appear!
It only appears if it is located away from Sprite1!
It’s almost as if it can’t collide with Sprite1? As soon as I locate it anywhere else on the screen, it appears fine.
Am I spawning it correctly?
Is there any parameter I need to set or turn off?
Another thing I noticed is that the screen position for Sprite2 is located a little bit off centre when the game is packaged up as a Windows program? E.g. based on my 1280x720 screen, then a sprite rendered at 640, 360 should sit half showing at the bottom right of the screen, but in packaged mode, the sprite shows on screen NEAR the bottom right corner? It is ok when playing a standalone from the editor.
Do I need to something when spawning, like set the relative position to the same position as the main world position or something? I don’t know, I’m guessing here …
Thanks,
M.