Creating large objects effeciently.

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
splendidland
Red Slime
Posts: 42
Joined: Tue Feb 19, 2013 11:06 am
Contact:

Creating large objects effeciently.

Post by splendidland »

Hello!
I'm currently working on a train system in my game, which ideally would show a shot of the train leaving the station as you travel from one place to another.

Image

This is a bunch of NPCs bundled together to create a large object, 20 of them in total, and while this will probably work for what I want to do, it also feels extremely inefficient.

Would there be a better way to draw this train on the map? I know there are scripts to replace an NPC sprite with various other sprites, but what would be the best way to go about this? Should I just stick to the way I have it currently?

Image

Thanks in advance!

-Samanthuel
User avatar
BMR
Metal King Slime
Posts: 3310
Joined: Mon Feb 27, 2012 2:46 pm
Location: The Philippines
Contact:

Post by BMR »

By, "...show a shot of the train leaving the station..." do you mean that the entire thing is going to move off screen? If so, might not be a bad idea to forgo NPCs and instead stick a slice there, perhaps a large enemy sprite or maybe even a screen. You'd also have more control over the speed and whatnot for when it animates away.
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

If the carriages move or animate independently (say, the train turns a corner) then it would be easiest to have each a separate large enemy sprite slice, otherwise I would use a backdrop slice for everything (which also lets you use more than 16 colours, but this looks like a limited palette), with multiple backdrops for animation. Attaching the slice(s) to NPCs means you can use regular NPC commands you're familiar with rather than using slice commands, but it looks like this is just moving in a straight line and it would be useful to be able to use the "move slice by" or "set slice velocity" commands with varying speeds to make the train accelerate.

To use NPCs, use a modified version of the walktall "embiggen walkabout slice" script, something like this:

Code: Select all

# Called with two arguments: NPC id or reference, and large enemy sprite number
script, embiggen npc to large enemy, npc, spriteset id, begin
  variable(sl, pic sl)
  sl := get NPC slice(npc)
  if(sl) then(
    pic sl := lookup slice(sl:walkabout sprite component, sl)
    replace large enemy sprite(pic sl, spriteset id)
  )
end
To use non-NPC slices you would load and parent them to the appropriate map layer, like:

Code: Select all

global variable (1, train slice)

# in the map autorun script
train slice := load backdrop sprite(id)
set parent(train slice, lookup slice(sl:map layer3))
put slice(train slice, -40, 80)   # set top left position of the slice on the map, in pixels
Last edited by TMC on Mon Jun 27, 2016 12:00 pm, edited 1 time in total.
splendidland
Red Slime
Posts: 42
Joined: Tue Feb 19, 2013 11:06 am
Contact:

Post by splendidland »

Hiya, sorry to bump this thread, but I tried the script to replace an NPC sprite with a large enemy sprite, it works just fine for the most part, however as soon as I try and move the NPC with the large sprite applied to it, I get an error.
Image
What I'm currently using this for won't require any animation, I just need it to move to the left. How would I be able to bypass this error?
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

@Brotoad:

I believe it has to do with your large enemy sprite consisting of a single frame while your walkabout sprite consists of a set of 8 frames (2 frames for walking animation in each direction). Your walkabout NPC is moving, thus it is trying to change frames, however there is no large enemy sprite assigned to replace the other walkabout frames.

I'm sure there's an easy way to solve this but I don't know what to suggest off hand. Perhaps you can assign the single large sprite frame to all 8 walkabout frames so as to avoid this error... or perhaps knowing the error will help you come up with a solution.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Oops, I should have known that would happen. (Well, actually, that error message is incorrectly reporting an engine bug rather than a script error, which are hidden by default). Here is a fixed copy of the embiggen script.

Code: Select all

# Called with two arguments: NPC id or reference, and large enemy sprite number
script, embiggen npc to large enemy, npc, spriteset id, begin
  variable(npc slice, slice)
  npc slice := get NPC slice(npc)
  if(npc slice) then(
    slice := load large enemy sprite(spriteset id)
    set parent(slice, npc slice)
    # Align the sprite to the bottom of the NPC, centred
    realign slice(slice, edge:middle, edge:bottom, edge:middle, edge:bottom)
    # Hide the original walkabout sprite
    set slice visible(lookup slice(sl:walkabout sprite component, npc slice), false)
  )
end 
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

Epic looking game bro...


..toad


I'm really glad to see you active in the community
Post Reply