Post new topic    
Slime Knight
Send private message
Moving Slices 
 PostMon Aug 01, 2011 2:08 am
Send private message Reply with quote
Would it be best to use the PUT SLICE command in a while loop in order to make the wagon below move across the screen, or is there a better way to do this?

The wagon is a large enemy sprite, and I want to be able to make it move to the right while also moving the camera and showing text boxes. If it's possible, I also plan on animating the wagon wheels.

Metal King Slime
Send private message
 
 PostMon Aug 01, 2011 7:37 am
Send private message Reply with quote
Put slice would work perfectly well, but there is a slightly easier way: nightly versions have several commands for moving slices, including:
Code:
move slice by (slice, x offset, y offset, ticks)
move slice to (slice, x, y, ticks)
set slice velocity (slice, x velocity, y velocity, ticks)

(see e.g. move slice by)

In order to animate the wagon, use replace large enemy sprite in a loop. (If you had been using walkabouts or something else with multiple frames, then you could also use set sprite frame to animate). For example:
Code:
variable (sl)
#... load and position the wagon slice, store the handle in sl ...
variable (i)
move slice by (sl, 80, 0, 40)  #move at 2 pixels per tick
# change the frame every 2 ticks, for 40 ticks
for (i, 0, 9) do (
  replace large enemy sprite (sl, SPRITE 1, PAL 1)
  wait (2)
  replace large enemy sprite (sl, SPRITE 2, PAL 2)
  wait (2)
)


There's no command to make the camera follow a slice. Use pancamera or focuscamera instead.

EDIT: Oh, you want to show textboxes at the same time. If you want to manually show and advance the textboxes, that makes things much trickier. You change the wheel animation loop into a timer-triggered script instead.
Slime Knight
Send private message
 
 PostTue Aug 02, 2011 3:16 am
Send private message Reply with quote
TMC wrote:
Put slice would work perfectly well, but there is a slightly easier way: nightly versions have several commands for moving slices


Those would make things much easier, but does editing in a nightly build prevent an .rpg file from being loaded in a stable version of GAME? If so then I would be hesitant to edit in a nightly build.

However, I tried your suggestions, but modified them just a bit. Instead of replace large enemy sprite, I loaded two slice collections, parented them to a container, and used the slice to back command to animate them.

This seemed easier than replace large enemy sprite because the wagon now consists of two large enemy sprites put together, instead of just the one from before. I needed something to pull the wagon Smile :



The animation works, but the slices aren't moving to the right. Do you happen to see what's causing the problem?

Code:
plotscript,wagon_train_rescue,begin

variable (wagon,wagonx,wagony,frame1,frame2,animate)

wagon := create container (160,160)
wagonx := slice x (wagon)
wagony := slice y (wagon)
frame1 := load slice collection (1)
frame2 := load slice collection (2)

put slice (wagon,0,9)
set parent (frame1,wagon)
set parent (frame2,wagon)
slice to back (frame2)

set tag (20,on)

while (check tag (20) == on)
   do (
   
      put slice (wagon,wagonx+1,wagony)
      slice to back (frame1)
      wait (5)
      slice to back (frame2)
      wait (5)
      
      )
      
set tag (20,off)

end


Thank you for your help, by the way Grin
Metal King Slime
Send private message
 
 PostTue Aug 02, 2011 7:44 am
Send private message Reply with quote
Yes, you shouldn't try to switch back to a previous version.

You need to actually increment the wagonx variable:
Code:
wagonx += 1
put slice (wagon,wagonx,wagony)


However, that script would move the wagon extremely slowly, just 1 pixel per 10 ticks (less than 2 pixels per second). You want the wagon to continue to move during the "wait (5)" commands. You could do that using timers, or by using a custom wait script, for example:

Code:
script, wagon wait, wagon, ticks, begin
  variable (i)
  for (i, 1, ticks) do (
    wait (1)
    set slice x (wagon, slice x (wagon) + 1)
  )
end


Code:
while (check tag (20) == on)
   do (
      slice to back (frame1)
      wagon wait (wagon, 5)
      slice to back (frame2)
      wagon wait (wagon, 5)
      )


Also, the "set tag (20,off)" at the end of your script does nothing, since the tag has to be off for the while loop to exit.
Slime Knight
Send private message
 
 PostThu Aug 04, 2011 3:14 am
Send private message Reply with quote
Ha ha, I thought I was incrementing the wagonx variable. Looks like I was doing it wrong.

I tried your custom wait script and it works great.

Thanks for the help! I feel slice-savvy now Smile
Display posts from previous: